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

feat: Eip 6110 #8204

Merged
merged 7 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/ethereum/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ revm-precompile = { version = "7.0.0", features = ["std"], default-features = fa

# Alloy
alloy-consensus.workspace = true
alloy-eips.workspace = true
alloy-rlp.workspace = true

# misc
tracing.workspace = true
Expand Down
30 changes: 26 additions & 4 deletions crates/ethereum/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ where
}
}
}
// EIP-6110
use alloy_eips::eip6110::{DepositRequest, MAINNET_DEPOSIT_CONTRACT_ADDRESS};
use alloy_rlp::Decodable;

fn parse_deposits_from_receipts(
receipts: &[Receipt],
) -> Result<Vec<Request>, BlockValidationError> {
let res = receipts
.iter()
.flat_map(|receipt| receipt.logs.iter())
.filter(|log| log.address == MAINNET_DEPOSIT_CONTRACT_ADDRESS)
.map(|log| DepositRequest::decode(&mut log.data.data.as_ref()))
.map(|res| res.map(Request::DepositRequest))
.collect::<Result<Vec<_>, _>>()
// ugly
.map_err(|err| BlockValidationError::DepositRequestDecode(err.to_string()))?;
Ok(res)
}

/// Helper type for the output of executing a block.
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -168,7 +186,7 @@ where
transaction_gas_limit: transaction.gas_limit(),
block_available_gas,
}
.into())
.into());
}

EvmConfig::fill_tx_env(evm.tx_mut(), transaction, *sender);
Expand Down Expand Up @@ -209,13 +227,17 @@ where
gas: GotExpected { got: cumulative_gas_used, expected: block.gas_used },
gas_spent_by_tx: receipts.gas_spent_by_tx()?,
}
.into())
.into());
}

// Collect all EIP-6110 deposits
let deposits = parse_deposits_from_receipts(&receipts)?;

// Collect all EIP-7685 requests
let withdrawal_requests =
post_block_withdrawal_requests(&self.chain_spec, block.timestamp, &mut evm)?;
Copy link
Member

@DaniPopes DaniPopes May 13, 2024

Choose a reason for hiding this comment

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

Should accumulate, extending a vector, rather than two vecs and concatenating after. Can be done with &mut Vec as argument and transforming the iterator into a for loop

Copy link
Member Author

Choose a reason for hiding this comment

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

The withdrawal function returns a Vec<Request> via Vec<Request>::decode and I cannot break out of the iterator without collecting so not sure how to do that here, also prob not big perf given smol list

Copy link
Member

Choose a reason for hiding this comment

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

i see, what about moving the parse_deposits to after post_block and extending that list?

let requests = withdrawal_requests;
// TODO: Does order matter?
let requests = [deposits, withdrawal_requests].concat();
Copy link
Member

Choose a reason for hiding this comment

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

yes and this is the correct order

gakonst marked this conversation as resolved.
Show resolved Hide resolved

Ok(EthExecuteOutput { receipts, requests, gas_used: cumulative_gas_used })
}
Expand Down Expand Up @@ -311,7 +333,7 @@ where
receipts.iter(),
) {
debug!(target: "evm", %error, ?receipts, "receipts verification failed");
return Err(error)
return Err(error);
Copy link
Collaborator

Choose a reason for hiding this comment

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

hehe

Suggested change
return Err(error);
return Err(error)

};
}

Expand Down
11 changes: 10 additions & 1 deletion crates/interfaces/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,21 @@ pub enum BlockValidationError {
/// The error message.
message: String,
},
/// EVM error during withdrawal requests contract call
/// EVM error during withdrawal requests contract call [EIP-7002]
///
/// [EIP-7002]: https://eips.ethereum.org/EIPS/eip-7002
#[error("failed to apply withdrawal requests contract call: {message}")]
WithdrawalRequestsContractCall {
/// The error message.
message: String,
},
/// Error when decoding deposit requests from receipts [EIP-6110]
///
/// [EIP-6110]: https://eips.ethereum.org/EIPS/eip-6110
// TODO(gakonst): This is an RLP decoding error but we don't import alloy_rlp here,
Copy link
Member

Choose a reason for hiding this comment

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

why not? It should be in reth_primitives already

// do we want to?
#[error("could not decode deposit request: {0}")]
DepositRequestDecode(String),
}

/// BlockExecutor Errors
Expand Down