Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FV type inference of function result not properly working #1109

Closed
rsoeldner opened this issue Dec 23, 2022 · 0 comments · Fixed by #1112
Closed

FV type inference of function result not properly working #1109

rsoeldner opened this issue Dec 23, 2022 · 0 comments · Fixed by #1112
Labels
bug FV Formal verification

Comments

@rsoeldner
Copy link
Member

Within the formal verification module, the type inference of the function result body, and hence the result property, is not properly working.

The following type error:

"Verification of test failed"
:OutputFailure: pact-issue-1107.repl:5:23: could not parse (> result 0.0): in (> result 0.0), type error: * vs decimal (CallStack (from HasCallStack):   typeError, called at src-tool/Pact/Analyze/Parse/Prop.hs:452:16

Can be generated by running:

(module test GOVERNANCE
  (defcap GOVERNANCE() true)

  (defun get-refund (balance:decimal stakers:integer)
    @model [ (property (> result 0.0)) ]

    (enforce (> balance 0.0) "balance must be non-negative")
    (enforce (> stakers 0) "stakers must be non-negative")
    
    (/ balance stakers)))

(verify 'test)

The issue can be fixed by explicitly annotating the function return type (decimal).

I tried tracking town the issue, and it seems to me that in getFunChecks, we

  1. collect function types (funTypes)
  2. collect the set of checks for each function (moduleFunCheck)

Already here, the function type map lists the return type as TyVar:

FunType {_ftArgs = [Arg {_aName = "balance", _aType = TyPrim TyDecimal, _aInfo = balance},Arg {_aName = "stakers", _aType = TyPrim TyInteger,                                                                                                                                                                 
_aInfo = stakers}], _ftReturn = TyVar {_tyVar = TypeVar {_tvName = "b", _tvConstraint = []}}}

In moduleFunCheck here, we use makeFunctionEnv which binds the result type to SAny (here).

@rsoeldner rsoeldner added bug FV Formal verification labels Dec 23, 2022
@rsoeldner rsoeldner changed the title VF type inference of function result not properly working FV type inference of function result not properly working Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug FV Formal verification
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant