-
Notifications
You must be signed in to change notification settings - Fork 0
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
Ensure state is correct in both EVM and Scilla environments #2414
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -584,9 +584,13 @@ fn scilla_call_precompile<I: ScillaInspector>( | |
|
||
let empty_state = PendingState::new(evmctx.db.pre_state.clone()); | ||
// Temporarily move the `PendingState` out of `evmctx`, replacing it with an empty state. | ||
let state = std::mem::replace(&mut evmctx.db, empty_state); | ||
let mut state = std::mem::replace(&mut evmctx.db, empty_state); | ||
let depth = evmctx.journaled_state.depth; | ||
if external_context.fork.scilla_call_respects_evm_state_changes { | ||
state.evm_state = Some(evmctx.journaled_state.clone()); | ||
} | ||
let scilla = evmctx.db.pre_state.scilla(); | ||
let Ok((result, state)) = scilla_call( | ||
let Ok((result, mut state)) = scilla_call( | ||
state, | ||
scilla, | ||
evmctx.env.tx.caller, | ||
|
@@ -596,7 +600,7 @@ fn scilla_call_precompile<I: ScillaInspector>( | |
.call_mode_1_sets_caller_to_parent_caller | ||
{ | ||
// Use the caller of the parent call-stack. | ||
external_context.callers[evmctx.journaled_state.depth - 1] | ||
external_context.callers[depth - 1] | ||
} else { | ||
// Use the original transaction signer. | ||
evmctx.env.tx.caller | ||
|
@@ -622,6 +626,7 @@ fn scilla_call_precompile<I: ScillaInspector>( | |
}; | ||
trace!(?result, "scilla_call complete"); | ||
if !&result.success { | ||
evmctx.db = state; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This allows failed scilla transitions to modify the state - do we want to allow this? |
||
if result.errors.values().any(|errs| { | ||
errs.iter() | ||
.any(|err| matches!(err, ScillaError::GasNotSufficient)) | ||
|
@@ -631,7 +636,25 @@ fn scilla_call_precompile<I: ScillaInspector>( | |
return err("scilla call failed"); | ||
} | ||
} | ||
// Move the new state back into `evmctx`. | ||
state.new_state.retain(|address, account| { | ||
if !account.touched { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to rely on side effects in retain() ? (it's safe, but .. ) |
||
return true; | ||
} | ||
if !account.from_evm { | ||
return true; | ||
} | ||
|
||
// Apply changes made to EVM accounts back to the EVM `JournaledState`. | ||
let before = evmctx.journaled_state.state.get_mut(address).unwrap(); | ||
|
||
// The only thing that Scilla is able to update is the balance. | ||
if before.info.balance.to::<u128>() != account.account.balance { | ||
before.info.balance = account.account.balance.try_into().unwrap(); | ||
before.mark_touch(); | ||
} | ||
|
||
false | ||
}); | ||
evmctx.db = state; | ||
|
||
for log in result.logs { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can't query the code either, so why set that?