Skip to content

PrecompileHandle trait#122

Merged
sorpaas merged 17 commits intorust-ethereum:masterfrom
moonbeam-foundation:jeremy-precompile-handle-for-subcalls
May 19, 2022
Merged

PrecompileHandle trait#122
sorpaas merged 17 commits intorust-ethereum:masterfrom
moonbeam-foundation:jeremy-precompile-handle-for-subcalls

Conversation

@nanocryk
Copy link
Copy Markdown
Contributor

Adds a PrecompileHandle trait allowing to perform subcalls and register gas and logs from a precompile.
Registering gas and logs with the handle provides better integration with gas and logs that could be emitted by the subcalls.
For that reason the cost and logs fields of PrecompileOutput are removed.

Copy link
Copy Markdown
Contributor

@tgmichel tgmichel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--

@nanocryk
Copy link
Copy Markdown
Contributor Author

Currently panics when doing subcalls because we don't record the dynamic cost of the subcall, and an underflow occurs while recording the stipend. Fixing that.

@nanocryk
Copy link
Copy Markdown
Contributor Author

Fixed the above and an issue with tracing.

Copy link
Copy Markdown
Member

@sorpaas sorpaas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still need to review something related to Runtime ref, but at this moment just some grumble.

Comment thread src/executor/stack/executor.rs Outdated
}

fn log(&mut self, address: H160, topics: Vec<H256>, data: Vec<u8>) {
let _ = Handler::log(self.0, address, topics, data);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error should be propagated, not ignored.

Comment thread src/executor/stack/executor.rs Outdated
context.clone(),
) {
Capture::Exit((s, v)) => (s, v),
Capture::Trap(_) => unreachable!(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment here why it's unreachable. (StackExecutor is sync.)

Comment thread src/executor/stack/executor.rs Outdated
&self,
handle: &mut impl PrecompileHandle,
address: H160,
input: &[u8],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move all parameters other than address to the handle trait. The lifetime should work, as everything will be within the scope of the overall handle lifetime.

Copy link
Copy Markdown
Contributor Author

@nanocryk nanocryk May 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. While updating our precompiles I already noticed target_gas was not very useful anymore since we can obtain the remaining gas. Making the handle the only parameter will also avoid breaking changes if new data should be accessible to the precompiles.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm also moved the address, but that shouldn't make a difference.

Comment thread src/executor/stack/executor.rs Outdated
context: &Context,
) -> (ExitReason, Vec<u8>) {
// For normal calls the cost is recorded at opcode level.
// Since we don't go throught opcodes we need manually record the call
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Since we don't go throught opcodes we need manually record the call
// Since we don't go through opcodes we need manually record the call

Comment thread src/executor/stack/executor.rs Outdated
// We're not reading from EVM memory, so we record the minimum MemoryCost.
let memory_cost = Some(crate::gasometer::MemoryCost {
offset: U256::zero(),
len: U256::zero(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may be safer to set this to input.len() for now. Call itself indeed copies it.

@sorpaas
Copy link
Copy Markdown
Member

sorpaas commented May 17, 2022

I still have some concerns over the trait design (mostly the call function), but let's cut a beta release so that we can move on in Frontier first.

@sorpaas sorpaas merged commit 01bcbd2 into rust-ethereum:master May 19, 2022
@koushiro
Copy link
Copy Markdown
Contributor

koushiro commented Jun 7, 2022

@sorpaas Do you have a plan to release a new version 0.36.0 or 0.36.0-beta that includes this PR ?

zjb0807 added a commit to AcalaNetwork/Acala that referenced this pull request Jan 22, 2024
zjb0807 added a commit to AcalaNetwork/Acala that referenced this pull request Jan 29, 2024
* update PrecompileHandle ref: rust-ethereum/evm#122

* update fee calculation ref: rust-ethereum/evm#132

* add code_size/code_hash fn in StackState trait ref: rust-ethereum/evm#140

* update evm call stack ref: rust-ethereum/evm#136

* update evm call stack ref: rust-ethereum/evm#155

* add shanghai eips 3651, 3855, 3860 ref: rust-ethereum/evm#152

* update is_precompile ref: rust-ethereum/evm#157

* fix eip-3860 ref: rust-ethereum/evm#160

* update runtime config ref: rust-ethereum/evm#161

* add eip-4399 ref: rust-ethereum/evm#162

* fix eip-2618 ref: rust-ethereum/evm#163

* fix nonce back to U256 ref: rust-ethereum/evm#166

* remove exit_substate in create functions ref: rust-ethereum/evm#168

* record external cost ref: rust-ethereum/evm#170

* add record_external_operation ref: rust-ethereum/evm#171

* add storage_growth ref: rust-ethereum/evm#173

* update evm

* switch to shanghai hardfork

* update ecrecover ref: polkadot-evm/frontier#964 (#2696)
mattsse added a commit to mattsse/evm that referenced this pull request Jan 17, 2026
* chore: bump revm

* chore: bump revm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants