Skip to content

Commit

Permalink
fix: remove unprovable property and replace it with two provable ones
Browse files Browse the repository at this point in the history
  • Loading branch information
0xteddybear committed Aug 2, 2024
1 parent eb3e148 commit a5458ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
3 changes: 2 additions & 1 deletion test/invariants/PROPERTIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ badd result should always be gte its terms
badd should never sum terms which have a sum gt uint max
badd should have bsub as reverse operation

bsub should not be commutative
bsub should not be associative
bsub should have 0 as identity
bsub result should always be lte its terms
bsub should alway revert if b > a (duplicate with previous tho)

bsubSign should not be commutative sign-wise
bsubSign should be commutative value-wise
bsubSign result should always be negative if b > a
bsubSign result should always be positive if a > b
bsubSign result should always be 0 if a == b
Expand Down
39 changes: 26 additions & 13 deletions test/invariants/symbolic/BNum.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,6 @@ contract SymbolicBNum is BNum, HalmosTest {
// Bnum::bsub //
/////////////////////////////////////////////////////////////////////

// bsub should not be commutative
function check_bsub_notCommut(uint256 _a, uint256 _b) public pure {
// precondition
vm.assume(_a != _b);

// action
uint256 _result1 = bsub(_a, _b);
uint256 _result2 = bsub(_b, _a);

// post condition
assert(_result1 != _result2);
}

// bsub should not be associative
function check_bsub_notAssoc(uint256 _a, uint256 _b, uint256 _c) public pure {
// precondition
Expand Down Expand Up @@ -152,6 +139,32 @@ contract SymbolicBNum is BNum, HalmosTest {
// Bnum::bsubSign //
/////////////////////////////////////////////////////////////////////

// bsubSign should be commutative value-wise
function check_bsubSign_CommutValue(uint256 _a, uint256 _b) public pure {
// precondition
vm.assume(_a != _b);

// action
(uint256 _result1,) = bsubSign(_a, _b);
(uint256 _result2,) = bsubSign(_b, _a);

// post condition
assert(_result1 == _result2);
}

// bsubSign should not be commutative sign-wise
function check_bsubSign_notCommutSign(uint256 _a, uint256 _b) public pure {
// precondition
vm.assume(_a != _b);

// action
(, bool _sign1) = bsubSign(_a, _b);
(, bool _sign2) = bsubSign(_b, _a);

// post condition
assert(_sign1 != _sign2);
}

// bsubSign result should always be negative if b > a
function check_bsubSign_negative(uint256 _a, uint256 _b) public pure {
// precondition
Expand Down

0 comments on commit a5458ac

Please sign in to comment.