-
Notifications
You must be signed in to change notification settings - Fork 62
Fixing checking assert failure #753
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,8 @@ import Data.Word (Word64) | |
import GHC.Natural | ||
import System.IO (hFlush, stdout) | ||
import Witch (unsafeInto, into) | ||
import Data.Vector qualified as V | ||
import Data.Char (ord) | ||
|
||
data UnitTestOptions s = UnitTestOptions | ||
{ rpcInfo :: Fetch.RpcInfo | ||
|
@@ -210,9 +212,12 @@ symRun opts@UnitTestOptions{..} vm (Sig testName types) = do | |
Success _ _ _ store -> if opts.checkFailBit then PNeg (failed store) else PBool True | ||
Failure _ _ (Revert msg) -> case msg of | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the sake of completeness, we should also handle the invalid opcode ( |
||
ConcreteBuf b -> | ||
if (BS.isPrefixOf (selector "Error(string)") b) || b == panicMsg 0x01 then PBool False | ||
-- We need to drop the selector (4B), the offset value (aligned to 32B), and the length of the string (aligned to 32B) | ||
-- NOTE: assertTrue/assertFalse does not have the double colon after "assertion failed" | ||
let assertFail = selector "Error(string)" `BS.isPrefixOf` b && "assertion failed" `BS.isPrefixOf` (BS.drop (4+32+32) b) | ||
in if assertFail || b == panicMsg 0x01 then PBool False | ||
else PBool True | ||
b -> b ./= ConcreteBuf (panicMsg 0x01) | ||
_ -> symbolicFail msg | ||
Failure _ _ _ -> PBool True | ||
Partial _ _ _ -> PBool True | ||
_ -> internalError "Invalid leaf node" | ||
|
@@ -257,7 +262,14 @@ symRun opts@UnitTestOptions{..} vm (Sig testName types) = do | |
liftIO $ putStr txtResult | ||
liftIO $ printWarnings ends results t | ||
pure (not (any isCex results), not (warnings || unexpectedAllRevert)) | ||
|
||
where | ||
symbolicFail :: Expr Buf -> Prop | ||
symbolicFail e = | ||
let text = V.fromList $ map (fromIntegral . ord) "assertion failed" | ||
panic = e == ConcreteBuf (panicMsg 0x01) | ||
assertFail = V.take (length text) (Expr.concretePrefix e) == text | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is sound? What if we have a symbolic prefix that could still be "assertion failed"? |
||
in PBool ((not panic) && (not assertFail)) | ||
-- | ||
printWarnings :: GetUnknownStr b => [Expr 'End] -> [ProofResult a b] -> String -> IO () | ||
printWarnings e results testName = do | ||
when (any isUnknown results || any isError results || any Expr.isPartial e) $ do | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {Test} from "forge-std/Test.sol"; | ||
|
||
contract SolidityTest is Test { | ||
function prove_assert_equal(uint stuff) public { | ||
assertEq(stuff, 0); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {Test} from "forge-std/Test.sol"; | ||
|
||
interface Vm { | ||
function bad_cheatcode(uint) external returns (bytes32); | ||
} | ||
|
||
contract SolidityTest is Test { | ||
function prove_bad_cheatcode(uint stuff) public { | ||
Vm vm = Vm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D); | ||
assert(stuff != 4); | ||
vm.bad_cheatcode(stuff); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {Test} from "forge-std/Test.sol"; | ||
|
||
contract SolidityTest is Test { | ||
function prove_require_emtpy(uint stuff, uint a) public returns (uint) { | ||
if (stuff == 0) { | ||
require(a == 0); | ||
return a; | ||
} | ||
return a; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {Test} from "forge-std/Test.sol"; | ||
|
||
contract SolidityTest is Test { | ||
function prove_require_string(uint stuff, uint a) public returns (uint) { | ||
if (stuff == 0) { | ||
require(a == 0, "must be 0"); | ||
return a; | ||
} | ||
return a; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {Test} from "forge-std/Test.sol"; | ||
|
||
contract SolidityTest is Test { | ||
function prove_revert_empty(uint stuff) public { | ||
if (stuff == 0) revert(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {Test} from "forge-std/Test.sol"; | ||
|
||
contract SolidityTest is Test { | ||
function prove_revert_string(uint stuff) public { | ||
if (stuff == 0) revert("stuff"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used anywhere? can we either fix it or delete it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or is there a reason to only check for direct calls to
assert
in solidity?