Skip to content

Soundness Bug in Function Substitution #653

@joscoh

Description

@joscoh

This assertion succeeds:

def functionAssertPgm : Program :=
#strata
program Core;

inline function foo(x : int, $__y0 : int) : int { x + $__y0 }

procedure TestFoo() returns ()
{
  var y : int;
  assert [fooEq]: (foo(y, 2) == 4);
};

#end

#eval verify functionAssertPgm

The reason is that in the evaluation of Factory functions, arguments are substituted for the free variables sequentially, so one can be captured by a future substitution. Here we first substitute x -> $__y0 and then substitute $__y0 -> 2. This particular example relies on giving an "illegal" variable name, but since functions and expressions can be constructed via an API, name clashes are possible.

The most straightforward fix is to do simultaneous substitution rather than sequential substitution when evaluating Factory functions.

Metadata

Metadata

Assignees

Labels

CorebugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions