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(--isolate): correctly handle staticcalls #9940

Merged
merged 2 commits into from
Feb 23, 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
50 changes: 35 additions & 15 deletions crates/evm/evm/src/inspectors/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use revm::{
Account, AccountStatus, BlockEnv, CreateScheme, Env, EnvWithHandlerCfg, ExecutionResult,
HashMap, Output, TransactTo,
},
EvmContext, Inspector,
EvmContext, Inspector, JournaledState,
};
use std::{
ops::{Deref, DerefMut},
Expand Down Expand Up @@ -846,20 +846,40 @@ impl Inspector<&mut dyn DatabaseExt> for InspectorStackRefMut<'_> {
}
}

if self.enable_isolation &&
call.scheme == CallScheme::Call &&
!self.in_inner_context &&
ecx.journaled_state.depth == 1
{
let (result, _) = self.transact_inner(
ecx,
TxKind::Call(call.target_address),
call.caller,
call.input.clone(),
call.gas_limit,
call.value.get(),
);
return Some(CallOutcome { result, memory_offset: call.return_memory_offset.clone() });
if self.enable_isolation && !self.in_inner_context && ecx.journaled_state.depth == 1 {
match call.scheme {
// Isolate CALLs
CallScheme::Call | CallScheme::ExtCall => {
let (result, _) = self.transact_inner(
ecx,
TxKind::Call(call.target_address),
call.caller,
call.input.clone(),
call.gas_limit,
call.value.get(),
);
return Some(CallOutcome {
result,
memory_offset: call.return_memory_offset.clone(),
});
}
// Mark accounts and storage cold before STATICCALLs
CallScheme::StaticCall | CallScheme::ExtStaticCall => {
let JournaledState { state, warm_preloaded_addresses, .. } =
&mut ecx.journaled_state;
for (addr, acc_mut) in state {
if !warm_preloaded_addresses.contains(addr) {
acc_mut.mark_cold();
}

for slot_mut in acc_mut.storage.values_mut() {
slot_mut.is_cold = true;
}
}
}
// Process other variants as usual
CallScheme::CallCode | CallScheme::DelegateCall | CallScheme::ExtDelegateCall => {}
}
}

None
Expand Down
54 changes: 27 additions & 27 deletions crates/forge/tests/cli/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2874,19 +2874,19 @@ contract NestedDeploy is Test {
| w | 21185 | 21185 | 21185 | 21185 | 1 |
╰-------------------------------------------------+-----------------+-------+--------+-------+---------╯

╭------------------------------------------+-----------------+-----+--------+-----+---------╮
| test/NestedDeployTest.sol:Child Contract | | | | | |
+===========================================================================================+
| Deployment Cost | Deployment Size | | | | |
|------------------------------------------+-----------------+-----+--------+-----+---------|
| 0 | 731 | | | | |
|------------------------------------------+-----------------+-----+--------+-----+---------|
| | | | | | |
|------------------------------------------+-----------------+-----+--------+-----+---------|
| Function Name | Min | Avg | Median | Max | # Calls |
|------------------------------------------+-----------------+-----+--------+-----+---------|
| child | 681 | 681 | 681 | 681 | 1 |
╰------------------------------------------+-----------------+-----+--------+-----+---------╯
╭------------------------------------------+-----------------+------+--------+------+---------╮
| test/NestedDeployTest.sol:Child Contract | | | | | |
+=============================================================================================+
| Deployment Cost | Deployment Size | | | | |
|------------------------------------------+-----------------+------+--------+------+---------|
| 0 | 731 | | | | |
|------------------------------------------+-----------------+------+--------+------+---------|
| | | | | | |
|------------------------------------------+-----------------+------+--------+------+---------|
| Function Name | Min | Avg | Median | Max | # Calls |
|------------------------------------------+-----------------+------+--------+------+---------|
| child | 2681 | 2681 | 2681 | 2681 | 1 |
╰------------------------------------------+-----------------+------+--------+------+---------╯

╭-------------------------------------------+-----------------+-----+--------+-----+---------╮
| test/NestedDeployTest.sol:Parent Contract | | | | | |
Expand Down Expand Up @@ -2938,10 +2938,10 @@ Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
"functions": {
"child()": {
"calls": 1,
"min": 681,
"mean": 681,
"median": 681,
"max": 681
"min": 2681,
"mean": 2681,
"median": 2681,
"max": 2681
}
}
},
Expand Down Expand Up @@ -3593,7 +3593,7 @@ forgetest_init!(gas_report_include_tests, |prj, cmd| {
|----------------------------------+-----------------+-------+--------+-------+---------|
| increment | 43482 | 43482 | 43482 | 43482 | 1 |
|----------------------------------+-----------------+-------+--------+-------+---------|
| number | 424 | 424 | 424 | 424 | 1 |
| number | 2424 | 2424 | 2424 | 2424 | 1 |
|----------------------------------+-----------------+-------+--------+-------+---------|
| setNumber | 23784 | 23784 | 23784 | 23784 | 1 |
╰----------------------------------+-----------------+-------+--------+-------+---------╯
Expand All @@ -3611,7 +3611,7 @@ forgetest_init!(gas_report_include_tests, |prj, cmd| {
|-----------------------------------------+-----------------+--------+--------+--------+---------|
| setUp | 218902 | 218902 | 218902 | 218902 | 1 |
|-----------------------------------------+-----------------+--------+--------+--------+---------|
| test_Increment | 52915 | 52915 | 52915 | 52915 | 1 |
| test_Increment | 54915 | 54915 | 54915 | 54915 | 1 |
╰-----------------------------------------+-----------------+--------+--------+--------+---------╯


Expand Down Expand Up @@ -3641,10 +3641,10 @@ Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
},
"number()": {
"calls": 1,
"min": 424,
"mean": 424,
"median": 424,
"max": 424
"min": 2424,
"mean": 2424,
"median": 2424,
"max": 2424
},
"setNumber(uint256)": {
"calls": 1,
Expand All @@ -3671,10 +3671,10 @@ Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
},
"test_Increment()": {
"calls": 1,
"min": 52915,
"mean": 52915,
"median": 52915,
"max": 52915
"min": 54915,
"mean": 54915,
"median": 54915,
"max": 54915
}
}
}
Expand Down
Loading