viperproject / silver

Definition of the Viper intermediate verification language.
Mozilla Public License 2.0
78 stars 40 forks source link

Precondition reason #798

Closed pieter-bos closed 2 months ago

pieter-bos commented 3 months ago

We rely on the fact that we can recover the section of the precondition of a method that fails by storing metadata in the info of precondition nodes and then inspecting the error reason. I noticed that the error reason will report the expression in a form where all parameters are substituted with their actual value, which in the extreme case can make all information about the precondition disappear if an assertion is directly a parameter:

method req(x: Bool, y: Bool)
requires x && y
{

}

method use()
{
  req(false, false)
}

reports:

The precondition of method req might not hold. Assertion false might not hold. (output-0.vpr@9.3--9.20)

Didactically this makes sense to me, but I don't see a way for us to now know whether x or y is false. Is there a nice trick to resolve this? We can resort to some hack like encoding (x || false) instead but I would prefer not to :)

Aurel300 commented 3 months ago

Are you relying on error messages/is the interaction with Viper based on generating Viper files? When constructing the AST you can provide IDs for nodes, then recover those from the verification error.

pieter-bos commented 3 months ago

No, we make ASTs directly. By adding id's do you just mean store information in the info? We do that, the point is there is no node left to represent the declared precondition.

marcoeilers commented 2 months ago

You could attach information (through an Info or a custom Position object) to the argument expressions themselves (i.e., here the two false literals) I guess?

pieter-bos commented 2 months ago

Even then it would require scanning to obtain the position in the declared contract where the parameter occurs as a direct cause of failing the contract, to attach the equivalent metadata to the argument expression. Anyway it's more an aesthetic concern so I think we'll just encode true ==> x or so when an argument occurs in a position like this, thanks for the pointers :)