Skip to content

CT: Improve generators sanity checks by not only checking variable clash but assignment clash as well.  #52

Description

@LuisPH3

CT generators suffer from an anti-pattern, when two conflicting constraints check if the used variables are the same, but do not check if the already assigned values to the variable are the same.

So far the specification may not have produced assignments with this problem, but this is technically incorrect.

  • Check all generators:
  • Write unit tests for assignment variables clashes for each constraint in each generator.

Technically it is insufficient to just check for the same variable names. What you actually would have to check is whether the values assigned to those variables in the assignment are the same.

For instance, assume there are the following constraints:

Delegates($a), !Delegates($b)

In the current code, these could never cause a conflict, since $a and $b are distinct variables. However, for whatever reasons, the initial assignment could be

a -> Address(1), b -> Address(1)

which would get you

Delegates(Address(1)), !Delegates(Address(1))

which is unsatisfied. This, however, is not detected by this code.

You can see this in this unit test:

func TestDelegateConstraints_MissesConflictsIntroducedByAssignment(t *testing.T) {
	vA := Variable("a")
	vB := Variable("b")

	generator := NewAccountGenerator()
	generator.BindDelegationDesignator(vA, tosca.ColdAccess)
	generator.BindNoDelegationDesignator(vB)

	rnd := rand.New(0)
	assignment := Assignment{}
	_, err := generator.Generate(assignment, rnd, tosca.Address{})
	if err != nil {
		t.Fatalf("Unexpected error during account generation")
	}

	assignment[vA] = NewU256(1)
	assignment[vB] = NewU256(1)
	_, err = generator.Generate(assignment, rnd, tosca.Address{})
	if err == nil {
		t.Fatalf("expected %v to be unsatisfiable", generator)
	}
}

However, I do suspect that issues like this are hidden in many generators and situations like this are currently not showing up in our constraints. So I guess we can ignore this. However, technically this makes this constraint solver incorrect.

Originally posted by @HerbertJordan in #37 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions