Skip to content

Commit

Permalink
fix: Add check in ZK create to check if it's the test contract (#585)
Browse files Browse the repository at this point in the history
* Add check in zk create to check whether we are deploying the test contract or not

* Update crates/cheatcodes/src/inspector.rs

Co-authored-by: Nisheeth Barthwal <nbaztec@gmail.com>

---------

Co-authored-by: Nisheeth Barthwal <nbaztec@gmail.com>
  • Loading branch information
Jrigada and nbaztec committed Sep 24, 2024
1 parent 8422d71 commit 082b6a3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions crates/cheatcodes/src/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,23 @@ impl Cheatcodes {
return None
}

if let Some(CreateScheme::Create) = input.scheme() {
let caller = input.caller();
let nonce = ecx
.inner
.journaled_state
.load_account(input.caller(), &mut ecx.inner.db)
.unwrap()
.0
.info
.nonce;
let address = caller.create(nonce);
if ecx.db.get_test_contract_address().map(|addr| address == addr).unwrap_or_default() {
info!("running create in EVM, instead of zkEVM (Test Contract) {:#?}", address);
return None
}
}

if input.init_code().0 == DEFAULT_CREATE2_DEPLOYER_CODE {
info!("running create in EVM, instead of zkEVM (DEFAULT_CREATE2_DEPLOYER_CODE)");
return None
Expand Down
1 change: 1 addition & 0 deletions crates/script/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ impl ScriptRunner {
let address = CALLER.create(self.executor.get_nonce(CALLER)?);
self.executor.backend_mut().set_test_contract(address);

self.executor.backend_mut().set_test_contract(address);
// Set the contracts initial balance before deployment, so it is available during the
// construction
self.executor.set_balance(address, self.evm_opts.initial_balance)?;
Expand Down

0 comments on commit 082b6a3

Please sign in to comment.