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

Fixing partial warning for missing cheatcode #640

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Not all testcases ran due to incorrect filtering, fixed
- Removed dead code related to IOAct in the now deprecated and removed debugger
- Dumping of END states (.prop) files is now default for `--debug`
- When cheatcode is missing, we produce a partial execution warning

## [0.54.2] - 2024-12-12

Expand Down
4 changes: 3 additions & 1 deletion src/EVM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,9 @@ cheat gas (inOffset, inSize) (outOffset, outSize) xs = do
runCheat abi input = do
let abi' = unsafeInto abi
case Map.lookup abi' cheatActions of
Nothing -> vmError (BadCheatCode "Cannot understand cheatcode." abi')
Nothing -> do
vm <- get
partial $ CheatCodeMissing vm.state.pc abi'
Just action -> action input

type CheatAction t s = Expr Buf -> EVM t s ()
Expand Down
7 changes: 6 additions & 1 deletion src/EVM/Format.hs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ formatError = \case

formatPartial :: PartialExec -> Text
formatPartial = \case
(UnexpectedSymbolicArg pc opcode msg args) -> T.unlines
UnexpectedSymbolicArg pc opcode msg args -> T.unlines
[ "Unexpected Symbolic Arguments to Opcode"
, indent 2 $ T.unlines
[ "msg: " <> T.pack (show msg)
Expand All @@ -477,6 +477,11 @@ formatPartial = \case
]
MaxIterationsReached pc addr -> "Max Iterations Reached in contract: " <> formatAddr addr <> " pc: " <> pack (show pc) <> " To increase the maximum, set a fixed large (or negative) value for `--max-iterations` on the command line"
JumpIntoSymbolicCode pc idx -> "Encountered a jump into a potentially symbolic code region while executing initcode. pc: " <> pack (show pc) <> " jump dst: " <> pack (show idx)
CheatCodeMissing pc selector ->T.unlines
[ "Cheat code not recognized"
, "program counter: " <> T.pack (show pc)
, "function selector: " <> T.pack (show selector)
]

formatSomeExpr :: SomeExpr -> Text
formatSomeExpr (SomeExpr e) = formatExpr $ Expr.simplify e
Expand Down
1 change: 1 addition & 0 deletions src/EVM/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ data PartialExec
= UnexpectedSymbolicArg { pc :: Int, opcode :: String, msg :: String, args :: [SomeExpr] }
| MaxIterationsReached { pc :: Int, addr :: Expr EAddr }
| JumpIntoSymbolicCode { pc :: Int, jumpDst :: Int }
| CheatCodeMissing { pc :: Int, selector :: FunctionSelector }
deriving (Show, Eq, Ord)

-- | Effect types used by the vm implementation for side effects & control flow
Expand Down
21 changes: 19 additions & 2 deletions test/test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1310,8 +1310,25 @@ tests = testGroup "hevm"
|]
r <- allBranchesFail c Nothing
assertBoolM "all branches must fail" (isRight r)
,
test "cheatcode-with-selector" $ do
, test "cheatcode-nonexistent" $ do
Just c <- solcRuntime "C"
[i|
interface Vm {
function nonexistent_cheatcode(uint) external;
}
contract C {
function fun(uint a) public {
// Cheatcode address
Vm vm = Vm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
vm.nonexistent_cheatcode(a);
assert(1 == 1);
}
}
|]
let sig = Just (Sig "fun(uint256)" [AbiUIntType 256])
(e, [Qed _]) <- withDefaultSolver $ \s -> checkAssert s defaultPanicCodes c sig [] defaultVeriOpts
assertBoolM "The expression must contain Partial." $ Expr.containsNode isPartial e
, test "cheatcode-with-selector" $ do
Just c <- solcRuntime "C"
[i|
contract C {
Expand Down
Loading