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

PrecompileHandle trait #122

Conversation

nanocryk
Copy link
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
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
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
Contributor Author

Fixed the above and an issue with tracing.

Copy link
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.

}

fn log(&mut self, address: H160, topics: Vec<H256>, data: Vec<u8>) {
let _ = Handler::log(self.0, address, topics, data);
Copy link
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.

context.clone(),
) {
Capture::Exit((s, v)) => (s, v),
Capture::Trap(_) => unreachable!(),
Copy link
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.)

@@ -248,6 +271,7 @@ pub trait PrecompileSet {
/// If the provided address is not a precompile, returns None.
fn execute(
&self,
handle: &mut impl PrecompileHandle,
address: H160,
input: &[u8],
Copy link
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
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
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.

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
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

// 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
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
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
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)
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