This repository was archived by the owner on Jul 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 838
feat: bus mapping for sload and sstore #418
Closed
Closed
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e47613b
pick
lispc 1079392
change geth to nightly in integration-tests
lispc a891164
Merge remote-tracking branch 'origin/main' into feat/sstore_busmapping
lispc 3419920
Merge remote-tracking branch 'origin/main' into feat/sstore_busmapping
lispc 2077c0e
fix conflict
lispc 2ba341d
minor
lispc c03ac9c
Merge branch 'main' into feat/sstore_busmapping
lispc 11534d4
fix conflict
lispc 6778b3a
Merge branch 'main' into feat/sstore_busmapping
lispc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -178,6 +178,8 @@ pub struct ExecStep { | |
| /// overflow", this value will **not** be the actual Gas cost of the | ||
| /// step. | ||
| pub gas_cost: GasCost, | ||
| /// accumulated gas refund | ||
| pub gas_refund: Gas, | ||
| /// Call index within the [`Transaction`] | ||
| pub call_index: usize, | ||
| /// The global counter when this step was executed. | ||
|
|
@@ -208,6 +210,7 @@ impl ExecStep { | |
| memory_size: step.memory.0.len(), | ||
| gas_left: step.gas, | ||
| gas_cost: step.gas_cost, | ||
| gas_refund: Gas(0), | ||
| call_index, | ||
| rwc, | ||
| swc, | ||
|
|
@@ -227,6 +230,7 @@ impl Default for ExecStep { | |
| memory_size: 0, | ||
| gas_left: Gas(0), | ||
| gas_cost: GasCost(0), | ||
| gas_refund: Gas(0), | ||
| call_index: 0, | ||
| rwc: RWCounter(0), | ||
| swc: 0, | ||
|
|
@@ -796,11 +800,7 @@ impl<'a> CircuitInputStateRef<'a> { | |
| rw: RW, | ||
| op: T, | ||
| ) -> Result<(), Error> { | ||
| let op_ref = self.block.container.insert(Operation::new_reversible( | ||
| self.block_ctx.rwc.inc_pre(), | ||
| rw, | ||
| op, | ||
| )); | ||
| let op_ref = self.apply_op(false, rw, op.into_enum()); | ||
| step.bus_mapping_instance.push(op_ref); | ||
|
|
||
| // Increase state_write_counter | ||
|
|
@@ -1068,37 +1068,28 @@ impl<'a> CircuitInputStateRef<'a> { | |
| } | ||
|
|
||
| /// Apply reverted op to state and push to container. | ||
| fn apply_reverted_op(&mut self, op: OpEnum) -> OperationRef { | ||
| match op { | ||
| fn apply_op(&mut self, is_revert: bool, rw: RW, op: OpEnum) -> OperationRef { | ||
| match &op { | ||
| OpEnum::Storage(op) => { | ||
| let (_, account) = self.sdb.get_storage_mut(&op.address, &op.key); | ||
| *account = op.value; | ||
| self.block.container.insert(Operation::new( | ||
| self.block_ctx.rwc.inc_pre(), | ||
| RW::WRITE, | ||
| op, | ||
| )) | ||
| self.sdb.set_storage(&op.address, &op.key, &op.value); | ||
| } | ||
| OpEnum::TxAccessListAccount(op) => { | ||
| if !op.value { | ||
| if !op.value_prev && op.value { | ||
| self.sdb.add_account_to_access_list(op.address); | ||
| } | ||
| if op.value_prev && !op.value { | ||
| self.sdb.remove_account_from_access_list(&op.address); | ||
| } | ||
| self.block.container.insert(Operation::new( | ||
| self.block_ctx.rwc.inc_pre(), | ||
| RW::WRITE, | ||
| op, | ||
| )) | ||
| } | ||
| OpEnum::TxAccessListAccountStorage(op) => { | ||
| if !op.value { | ||
| if !op.value_prev && op.value { | ||
| self.sdb | ||
| .add_account_storage_to_access_list((op.address, op.key)); | ||
| } | ||
| if op.value_prev && !op.value { | ||
| self.sdb | ||
| .remove_account_storage_from_access_list(&(op.address, op.key)); | ||
| } | ||
| self.block.container.insert(Operation::new( | ||
| self.block_ctx.rwc.inc_pre(), | ||
| RW::WRITE, | ||
| op, | ||
| )) | ||
| } | ||
| OpEnum::Account(op) => { | ||
| let (_, account) = self.sdb.get_account_mut(&op.address); | ||
|
|
@@ -1109,16 +1100,19 @@ impl<'a> CircuitInputStateRef<'a> { | |
| account.code_hash = op.value.to_be_bytes().into(); | ||
| } | ||
| } | ||
| self.block.container.insert(Operation::new( | ||
| self.block_ctx.rwc.inc_pre(), | ||
| RW::WRITE, | ||
| op, | ||
| )) | ||
| } | ||
| OpEnum::TxRefund(_) => unimplemented!(), | ||
| OpEnum::TxRefund(op) => { | ||
| self.sdb.set_refund(op.value); | ||
| } | ||
| OpEnum::AccountDestructed(_) => unimplemented!(), | ||
| _ => unreachable!(), | ||
| }; | ||
| if is_revert { | ||
| debug_assert!(rw == RW::WRITE, "revert read operation"); | ||
| } | ||
| self.block | ||
| .container | ||
| .insert_op_enum(self.block_ctx.rwc.inc_pre(), rw, !is_revert, op) | ||
| } | ||
|
|
||
| /// Handle a reversion group | ||
|
|
@@ -1132,7 +1126,7 @@ impl<'a> CircuitInputStateRef<'a> { | |
| // Apply reversions | ||
| for (step_index, op_ref) in reversion_group.op_refs.into_iter().rev() { | ||
| if let Some(op) = self.get_rev_op_by_ref(&op_ref) { | ||
| let rev_op_ref = self.apply_reverted_op(op); | ||
| let rev_op_ref = self.apply_op(true, RW::WRITE, op); | ||
| self.tx.steps[step_index] | ||
| .bus_mapping_instance | ||
| .push(rev_op_ref); | ||
|
|
@@ -1463,6 +1457,7 @@ impl<'a> CircuitInputBuilder { | |
|
|
||
| for (index, geth_step) in geth_trace.struct_logs.iter().enumerate() { | ||
| let mut state_ref = self.state_ref(&mut tx, &mut tx_ctx); | ||
| log::trace!("handle {}th opcode {:?} ", index, geth_step.op); | ||
|
Contributor
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. I prefer tokio/tracing for these things. But maybe it's not the best option. Maybe @ed255 has some suggestions
Contributor
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. I'm happy with using the log crate here, it's very lightweight and if logs aren't activated they don't add any performance penalty as far as I know. I don't know about tokio/tracing so I can't comment on that. |
||
| let exec_steps = gen_associated_ops( | ||
| &geth_step.op, | ||
| &mut state_ref, | ||
|
|
@@ -1478,8 +1473,8 @@ impl<'a> CircuitInputBuilder { | |
| let end_tx_step = gen_end_tx_ops(&mut self.state_ref(&mut tx, &mut tx_ctx))?; | ||
| tx.steps.push(end_tx_step); | ||
|
|
||
| self.sdb.commit_tx(); | ||
| self.block.txs.push(tx); | ||
| self.sdb.clear_access_list_and_refund(); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
@@ -1994,6 +1989,7 @@ mod tracer_tests { | |
| &GethExecTrace { | ||
| gas: Gas(0), | ||
| failed: false, | ||
| return_value: "".to_owned(), | ||
| struct_logs: vec![geth_step.clone()], | ||
| }, | ||
| false, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.