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

feat: gas snapshots over arbitrary sections #8952

Merged
merged 56 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
4ef2ac6
update internal naming
zerosnacks Sep 24, 2024
d90a09e
further internals
zerosnacks Sep 24, 2024
3d326d2
deprecate cheats
zerosnacks Sep 24, 2024
72b4e15
update Solidity tests and add dedicated test for testing deprecated c…
zerosnacks Sep 24, 2024
7fed284
clarify gas snapshots
zerosnacks Sep 24, 2024
d544326
fix build
zerosnacks Sep 24, 2024
8492c71
final fixes
zerosnacks Sep 24, 2024
a8f2ec5
fix build
zerosnacks Sep 24, 2024
2cca2c7
fix repro 6355 rename
zerosnacks Sep 24, 2024
9602aec
add gas snapshot setup from #8755
zerosnacks Sep 24, 2024
1ced509
fix build + clippy warnings
zerosnacks Sep 24, 2024
9348062
fix cheatcodes
zerosnacks Sep 24, 2024
094a4bb
account for fixed CREATE / CALL gas cost
zerosnacks Sep 24, 2024
e9bd560
remove import
zerosnacks Sep 24, 2024
836a400
add stipend
zerosnacks Sep 24, 2024
45ae718
Merge branch 'master' into zerosnacks/add-gas-section-snapshot-cheatc…
zerosnacks Sep 25, 2024
1ebd5c3
recalculate after a - b setup
zerosnacks Sep 25, 2024
9f8ea19
clear call_stipend, update tests
zerosnacks Sep 25, 2024
fd97339
Merge branch 'master' into zerosnacks/rename-state-snapshot
zerosnacks Sep 25, 2024
4114b07
Merge branch 'zerosnacks/rename-state-snapshot' into zerosnacks/add-g…
zerosnacks Sep 25, 2024
55d43f4
avoid double counting external calls
zerosnacks Sep 25, 2024
eb3f0ae
Merge branch 'zerosnacks/add-gas-section-snapshot-cheatcodes' of gith…
zerosnacks Sep 25, 2024
fe9822f
update cheatcodes, remove debug prints
zerosnacks Sep 25, 2024
1b2439c
enable assertions
zerosnacks Sep 25, 2024
aaee5d4
clean up tests
zerosnacks Sep 25, 2024
1bb65a7
clean up test names
zerosnacks Sep 25, 2024
040a2bf
Merge branch 'master' into zerosnacks/add-gas-section-snapshot-cheatc…
zerosnacks Sep 25, 2024
162ab95
remove snapshot directory on `forge clean`
zerosnacks Sep 25, 2024
50b8e54
Merge branch 'master' into zerosnacks/rename-state-snapshot
zerosnacks Sep 25, 2024
b78bd56
do not remove all snapshots by default due to multiple test suites be…
zerosnacks Sep 25, 2024
dd7c457
Merge branch 'zerosnacks/rename-state-snapshot' into zerosnacks/add-g…
zerosnacks Sep 25, 2024
7ae5dee
handle edge case where we ask to compare but file does not exist, rem…
zerosnacks Sep 25, 2024
54ea324
Merge branch 'zerosnacks/add-gas-section-snapshot-cheatcodes' of gith…
zerosnacks Sep 25, 2024
41800da
fix path issue when attempting removal
zerosnacks Sep 25, 2024
6408bb1
Update crates/cheatcodes/src/evm.rs
zerosnacks Sep 26, 2024
6c05e09
Update crates/cheatcodes/src/inspector.rs
zerosnacks Sep 26, 2024
fcd43e4
refactor, apply recommended changes for last_snapshot_group, last_sna…
zerosnacks Sep 26, 2024
c6b19b3
remove gas snapshots from fuzz tests for now: this is largely due to …
zerosnacks Sep 26, 2024
bca712f
fix clippy
zerosnacks Sep 26, 2024
d040ea7
Merge branch 'master' into zerosnacks/rename-state-snapshot-bu
zerosnacks Sep 26, 2024
6e0d85f
Merge branch 'zerosnacks/rename-state-snapshot-bu' into zerosnacks/ad…
zerosnacks Sep 26, 2024
23fdf66
avoid setting to 0 unnecessarily
zerosnacks Sep 26, 2024
86060d3
use if let Some
zerosnacks Sep 26, 2024
92384b2
improve comments, clarify use of last_gas_used != 0
zerosnacks Sep 26, 2024
b1e2567
merge in master
zerosnacks Sep 27, 2024
23d4410
Merge branch 'master' into zerosnacks/add-gas-section-snapshot-cheatc…
zerosnacks Sep 30, 2024
f789e3d
fix merge conflict issue
zerosnacks Sep 30, 2024
8f62030
fix arg ordering to address group naming regression
zerosnacks Sep 30, 2024
731cbe3
fix merge conflicts
zerosnacks Sep 30, 2024
d3d1229
fix import
zerosnacks Sep 30, 2024
ab2cded
move snapshot name derivation to helper
zerosnacks Oct 1, 2024
d3310f2
only skip initial call w/ overhead, no special handling for call frames
zerosnacks Oct 1, 2024
73b4f81
add flare test
zerosnacks Oct 1, 2024
b74ae33
style nits + use helper method
zerosnacks Oct 2, 2024
0511d24
Merge branch 'master' into zerosnacks/add-gas-section-snapshot-cheatc…
zerosnacks Oct 2, 2024
e7c9bf9
Merge branch 'master' into zerosnacks/add-gas-section-snapshot-cheatc…
zerosnacks Oct 2, 2024
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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_STORE
/target
out/
snapshots/
out.json
.idea
.vscode
182 changes: 181 additions & 1 deletion crates/cheatcodes/assets/cheatcodes.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 44 additions & 1 deletion crates/cheatcodes/spec/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,49 @@ interface Vm {
#[cheatcode(group = Evm, safety = Unsafe)]
function readCallers() external returns (CallerMode callerMode, address msgSender, address txOrigin);

// ----- Arbitrary Snapshots -----

/// Snapshot capture an arbitrary numerical value by name.
/// The group name is derived from the contract name.
#[cheatcode(group = Evm, safety = Unsafe)]
function snapshotValue(string calldata name, uint256 value) external;

/// Snapshot capture an arbitrary numerical value by name in a group.
#[cheatcode(group = Evm, safety = Unsafe)]
function snapshotValue(string calldata group, string calldata name, uint256 value) external;

// -------- Gas Snapshots --------

/// Snapshot capture the gas usage of the last call by name from the callee perspective.
#[cheatcode(group = Evm, safety = Unsafe)]
function snapshotGasLastCall(string calldata name) external returns (uint256 gasUsed);

/// Snapshot capture the gas usage of the last call by name in a group from the callee perspective.
#[cheatcode(group = Evm, safety = Unsafe)]
function snapshotGasLastCall(string calldata group, string calldata name) external returns (uint256 gasUsed);

/// Start a snapshot capture of the current gas usage by name.
/// The group name is derived from the contract name.
#[cheatcode(group = Evm, safety = Unsafe)]
function startSnapshotGas(string calldata name) external;

/// Start a snapshot capture of the current gas usage by name in a group.
#[cheatcode(group = Evm, safety = Unsafe)]
function startSnapshotGas(string calldata group, string calldata name) external;

/// Stop the snapshot capture of the current gas by latest snapshot name, capturing the gas used since the start.
#[cheatcode(group = Evm, safety = Unsafe)]
function stopSnapshotGas() external returns (uint256 gasUsed);

/// Stop the snapshot capture of the current gas usage by name, capturing the gas used since the start.
/// The group name is derived from the contract name.
#[cheatcode(group = Evm, safety = Unsafe)]
function stopSnapshotGas(string calldata name) external returns (uint256 gasUsed);

/// Stop the snapshot capture of the current gas usage by name in a group, capturing the gas used since the start.
#[cheatcode(group = Evm, safety = Unsafe)]
function stopSnapshotGas(string calldata group, string calldata name) external returns (uint256 gasUsed);

// -------- State Snapshots --------

/// `snapshot` is being deprecated in favor of `snapshotState`. It will be removed in future versions.
Expand Down Expand Up @@ -698,7 +741,7 @@ interface Vm {

// -------- Gas Measurement --------

/// Gets the gas used in the last call.
/// Gets the gas used in the last call from the callee perspective.
#[cheatcode(group = Evm, safety = Safe)]
function lastCallGas() external view returns (Gas memory gas);

Expand Down
6 changes: 6 additions & 0 deletions crates/cheatcodes/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub struct CheatsConfig {
/// If Some, `vm.getDeployedCode` invocations are validated to be in scope of this list.
/// If None, no validation is performed.
pub available_artifacts: Option<ContractsByArtifact>,
/// Name of the script/test contract which is currently running.
pub running_contract: Option<String>,
/// Version of the script/test contract which is currently running.
pub running_version: Option<Version>,
/// Whether to enable legacy (non-reverting) assertions.
Expand All @@ -64,6 +66,7 @@ impl CheatsConfig {
evm_opts: EvmOpts,
available_artifacts: Option<ContractsByArtifact>,
script_wallets: Option<ScriptWallets>,
running_contract: Option<String>,
running_version: Option<Version>,
) -> Self {
let mut allowed_paths = vec![config.root.0.clone()];
Expand Down Expand Up @@ -92,6 +95,7 @@ impl CheatsConfig {
labels: config.labels.clone(),
script_wallets,
available_artifacts,
running_contract,
running_version,
assertions_revert: config.assertions_revert,
seed: config.fuzz.seed,
Expand Down Expand Up @@ -221,6 +225,7 @@ impl Default for CheatsConfig {
labels: Default::default(),
script_wallets: None,
available_artifacts: Default::default(),
running_contract: Default::default(),
running_version: Default::default(),
assertions_revert: true,
seed: None,
Expand All @@ -240,6 +245,7 @@ mod tests {
None,
None,
None,
None,
)
}

Expand Down
Loading
Loading