Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

klab-prove: toggle deterministic functions #354

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

asymmetric
Copy link
Contributor

@asymmetric asymmetric commented Feb 17, 2020

This fixes the non-determinism we were seeing in some proofs.
The reason was that there was more than one function defined for
sizeWordStack, one of which is problematic, and they were being
chosen non-deterministically.


I've created this PR from magit!!! 🚀

@asymmetric asymmetric requested review from MrChico and a team and removed request for MrChico February 17, 2020 15:41
@asymmetric
Copy link
Contributor Author

Quite interesting that there are CI failures for this one.

@asymmetric asymmetric force-pushed the deterministic-functions branch 3 times, most recently from 3d53480 to ef7c564 Compare February 19, 2020 18:28
@d-xo
Copy link
Contributor

d-xo commented Feb 29, 2020

rebased on master

@asymmetric
Copy link
Contributor Author

asymmetric commented Mar 3, 2020

[Error] Critical: [non-deterministic function definition]: more than one rule can apply to the term:
#if_#then_#else_#fi_K-EQUAL(_andBool_(_andBool_(notBool_(_==K_(Temperature_1790:Int,, _+Int_(ABI_x_1787:Int,, Temperature_1790:Int))),, _==K_(Junk_0_1783:Int,, Temperature_1790:Int)),, _==K_(_+Int_(ABI_x_1787:Int,, Temperature_1790:Int),, Int(#"0"))),, Int(#"15000"),, _+Int_(#if_#then_#else_#fi_K-EQUAL(_andBool_(_andBool_(notBool_(_==K_(Temperature_1790:Int,, _+Int_(ABI_x_1787:Int,, Temperature_1790:Int))),, notBool_(_==K_(Junk_0_1783:Int,, Temperature_1790:Int))),, notBool_(_==K_(Junk_0_1783:Int,, Int(#"0")))),, #if_#then_#else_#fi_K-EQUAL(_==K_(Temperature_1790:Int,, Int(#"0")),, Int(#"-15000"),, #if_#then_#else_#fi_K-EQUAL(_==K_(_+Int_(ABI_x_1787:Int,, Temperature_1790:Int),, Int(#"0")),, Int(#"15000"),, Int(#"0"))),, Int(#"0")),, #if_#then_#else_#fi_K-EQUAL(_andBool_(notBool_(_==K_(Temperature_1790:Int,, _+Int_(ABI_x_1787:Int,, Temperature_1790:Int))),, _==K_(Junk_0_1783:Int,, _+Int_(ABI_x_1787:Int,, Temperature_1790:Int))),, _+Int_(#if_#then_#else_#fi_K-EQUAL(_==K_(Junk_0_1783:Int,, Int(#"0")),, Int(#"15000"),, Int(#"0")),, Int(#"4200")),, Int(#"0"))))

Candidate rules:
    rule #if C1 #then A #else (B +Int #if C2 #then B2 #else B3 #fi) #fi =>
         #if C1 #then A #else B #fi +Int #if (C2 andBool notBool C1) #then B2 #else 0 #fi +Int #if ((notBool C2) andBool (notBool C1)) #then B3 #else 0 #fi
        Source: /home/asymmetric/klab/examples/multipleCalls/out/rules.k Location(319,10,320,156)
  rule #if C:Bool #then _ #else B2::K #fi => B2 requires notBool C
        Source: /home/asymmetric/klab/evm-semantics/deps/k/k-distribution/target/release/k/include/builtin/domains.k Location(870,8,870,67)

This is saying that this clashes with this on Callee_tempDelta_pass_rough.

@MrChico is the rule there for performance reasons? If so, does it make sense to remove it? Or can we instead mark it concrete?

I'm also wondering about these rules. They will also clash, as the rule in domains.k is extremely generic.

@asymmetric
Copy link
Contributor Author

40d3201 fixes the issue in Callee_tempDelta_pass_rough.

This fixes the non-determinism we were seeing in some proofs.
The reason was that there was more than one function defined for
`sizeWordStack`, one of which is problematic, and they were being
chosen non-deterministically.
It clashes with this rule in domains.k:

```k
rule #if C:Bool #then _ #else B2::K #fi => B2 requires notBool C
```
@d-xo
Copy link
Contributor

d-xo commented Apr 8, 2020

rebased on master

@d-xo
Copy link
Contributor

d-xo commented Apr 8, 2020

Vat_subui_fail_rough, ConstantTemp_sub_fail_rough, and Callee_add_fail_rough both fail because the following rules clash:

Candidate rules:
    rule (A +Int B) -Int C  => A +Int (B -Int C)
        Source: /home/me/code/dapphub/klab/deterministic-functions/examples/multipleCalls/out/rules.k Location(356,10,356,49)
    rule A -Int A => 0
        Source: /home/me/code/dapphub/klab/deterministic-functions/examples/multipleCalls/out/rules.k Location(455,10,455,23)

@d-xo
Copy link
Contributor

d-xo commented Apr 8, 2020

Vat_heal_fail_rough fails because of the following collision:

rule A -Word #unsigned(B) => A -Int B
  requires #rangeUInt(256, A)
  andBool #rangeSInt(256, B)
  andBool #rangeUInt(256, A -Int B)
        Source: /home/me/code/dapphub/klab/deterministic-functions/examples/heal/out/rules.k Location(587,6,590,36)
rule W0 -Word W1 => W0 -Int W1 requires W0 >=Int W1
        Source: /home/me/code/dapphub/klab/deterministic-functions/evm-semantics/.build/defn/java/evm-types.k Location(218,10,218,56)

@d-xo
Copy link
Contributor

d-xo commented Apr 8, 2020

@MrChico @mhhf @livnev I don't really have the nescessary context to determine which of the above rules can be removed without causing issues, would really appreciate some input here 🙏 ✨.

Once we have a clean run of the klab test suite, I'll merge this and start working to make k-uniswap deterministic.

@MrChico
Copy link
Member

MrChico commented Apr 9, 2020

I vote to keep A - A => 0 and rule A -Word #unsigned(B) => A -Int B

@d-xo
Copy link
Contributor

d-xo commented Apr 9, 2020

@MrChico rule A -Word #unsigned(B) => A -Int B conflicts with a rule inside evm-types.md and so would require a patch against evm semantics, are you OK with this?

Why is rule A -Word #unsigned(B) => A -Int B required?

@MrChico
Copy link
Member

MrChico commented Apr 9, 2020

#rangeUInt256(A -Int B) => A >= #unsigned(B)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants