Skip to content

Commit

Permalink
Merge pull request #509 from ethereum/fix-initial-storage
Browse files Browse the repository at this point in the history
cli: fix --initial-storage option for hevm symbolic
  • Loading branch information
msooseth authored Jul 23, 2024
2 parents cdc1ed5 + 588f342 commit 3f5b21e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Printing panic uint256 as hex, not as int
- Decomposition does not take place when entire states are compared, as that would necessitate
a different approach.
- `initial-storage` option of `hevm symbolic` is respected

## [0.53.0] - 2024-02-23

Expand Down
13 changes: 8 additions & 5 deletions cli/cli.hs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ symvmFromCommand cmd calldata = do
caller = SymAddr "caller"
ts = maybe Timestamp Lit cmd.timestamp
callvalue = maybe TxValue Lit cmd.value
storageBase = maybe AbstractBase parseInitialStorage (cmd.initialStorage)

contract <- case (cmd.rpc, cmd.address, cmd.code) of
(Just url, Just addr', _) ->
Expand All @@ -535,12 +536,14 @@ symvmFromCommand cmd calldata = do
& set #nonce (contract'.nonce)
& set #external (contract'.external)

(_, _, Just c) ->
pure ((`abstractContract` address) . mkCode $ decipher c)
(_, _, Just c) -> case storageBase of
EmptyBase -> pure (initialContract . mkCode $ decipher c)
AbstractBase -> pure ((`abstractContract` address) . mkCode $ decipher c)

(_, _, Nothing) ->
error "Error: must provide at least (rpc + address) or code"

vm <- stToIO $ vm0 baseFee miner ts blockNum prevRan calldata callvalue caller contract
vm <- stToIO $ vm0 baseFee miner ts blockNum prevRan calldata callvalue caller contract storageBase
pure $ EVM.Transaction.initTx vm

where
Expand All @@ -551,7 +554,7 @@ symvmFromCommand cmd calldata = do
then InitCode bs mempty
else RuntimeCode (ConcreteRuntimeCode bs)
address = eaddr (.address) (SymAddr "entrypoint")
vm0 baseFee miner ts blockNum prevRan cd callvalue caller c = makeVm $ VMOpts
vm0 baseFee miner ts blockNum prevRan cd callvalue caller c baseState = makeVm $ VMOpts
{ contract = c
, otherContracts = []
, calldata = cd
Expand All @@ -573,7 +576,7 @@ symvmFromCommand cmd calldata = do
, schedule = feeSchedule
, chainId = word (.chainid) 1
, create = (.create) cmd
, baseState = maybe AbstractBase parseInitialStorage (cmd.initialStorage)
, baseState = baseState
, txAccessList = mempty
, allowFFI = False
}
Expand Down

0 comments on commit 3f5b21e

Please sign in to comment.