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

fix(forge): replace loaded and untouched accounts on fork init #3222

Merged
merged 3 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions evm/src/executor/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,7 @@ impl Backend {
.fork_init_journaled_state
.state
.iter()
.filter(|(addr, acc)| {
!self.is_existing_precompile(addr) && acc.is_touched && !self.is_persistent(addr)
})
.filter(|(addr, _)| !self.is_existing_precompile(addr) && !self.is_persistent(addr))
.map(|(addr, _)| addr)
.copied()
.collect::<Vec<_>>();
Expand Down
6 changes: 6 additions & 0 deletions forge/tests/it/repros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,9 @@ fn test_issue_3119() {
fn test_issue_3190() {
test_repro!("Issue3190");
}

// <https://github.com/foundry-rs/foundry/issues/3221>
#[test]
fn test_issue_3221() {
test_repro!("Issue3221");
}
42 changes: 42 additions & 0 deletions testdata/repros/Issue3221.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.0;

import "ds-test/test.sol";
import "../cheats/Cheats.sol";

// https://github.com/foundry-rs/foundry/issues/3221
contract Issue3221Test is DSTest {
Cheats constant vm = Cheats(HEVM_ADDRESS);
uint256 fork1;
uint256 fork2;

function setUp() public {
fork1 = vm.createFork(
"https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161",
7475589
);
fork2 = vm.createFork(
"https://api.avax-test.network/ext/bc/C/rpc",
12880747
);
}

function testForkNonce() public {
address user = address(0xF0959944122fb1ed4CfaBA645eA06EED30427BAA);

// Loads but doesn't touch
assertEq(vm.getNonce(user), 0);

vm.selectFork(fork2);
assertEq(vm.getNonce(user), 3);
vm.prank(user);
new Counter();

vm.selectFork(fork1);
assertEq(vm.getNonce(user), 3);
vm.prank(user);
new Counter();
}
}

contract Counter {}