Skip to content

Commit

Permalink
feat: use TestAuthorization and skip decoding of eip7702 tx (#1785)
Browse files Browse the repository at this point in the history
  • Loading branch information
royvardhan authored Sep 18, 2024
1 parent 3e5a307 commit be1d324
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 154 deletions.
122 changes: 0 additions & 122 deletions bins/revme/src/cmd/statetest/models/eip7702.rs

This file was deleted.

59 changes: 32 additions & 27 deletions bins/revme/src/cmd/statetest/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
mod deserializer;
mod eip7702;
mod spec;

use deserializer::*;
pub use eip7702::TxEip7702;

pub use spec::SpecName;

use revm::{
primitives::{Address, Bytes, HashMap, B256, U256},
specification::{eip2930::AccessList, eip7702::AuthorizationList},
specification::{
eip2930::AccessList,
eip7702::{Authorization, Parity, RecoveredAuthorization, Signature},
},
};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
Expand Down Expand Up @@ -52,26 +54,6 @@ pub struct Test {
pub txbytes: Option<Bytes>,
}

impl Test {
pub fn eip7702_authorization_list(
&self,
) -> Result<Option<AuthorizationList>, alloy_rlp::Error> {
let Some(txbytes) = self.txbytes.as_ref() else {
return Ok(None);
};

if txbytes.first() == Some(&0x04) {
let mut txbytes = &txbytes[1..];
let tx = TxEip7702::decode(&mut txbytes)?;
return Ok(Some(
AuthorizationList::Signed(tx.authorization_list).into_recovered(),
));
}

Ok(None)
}
}

#[derive(Debug, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct TxPartIndices {
Expand Down Expand Up @@ -130,16 +112,15 @@ pub struct TransactionParts {

#[serde(default)]
pub access_lists: Vec<Option<AccessList>>,
#[serde(default)]
pub authorization_list: Vec<Authorization>,
pub authorization_list: Option<Vec<TestAuthorization>>,
#[serde(default)]
pub blob_versioned_hashes: Vec<B256>,
pub max_fee_per_blob_gas: Option<U256>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Copy)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Authorization {
pub struct TestAuthorization {
chain_id: U256,
address: Address,
nonce: U256,
Expand All @@ -149,6 +130,30 @@ pub struct Authorization {
signer: Option<Address>,
}

impl TestAuthorization {
pub fn signature(&self) -> Signature {
let v = u64::try_from(self.v).unwrap_or(u64::MAX);
let parity = Parity::try_from(v).unwrap_or(Parity::Eip155(36));
Signature::from_rs_and_parity(self.r, self.s, parity).unwrap()
}

pub fn into_recovered(self) -> RecoveredAuthorization {
let authorization = Authorization {
chain_id: self.chain_id,
address: self.address,
nonce: u64::try_from(self.nonce).unwrap(),
};
let authority = self
.signature()
.recover_address_from_prehash(&authorization.signature_hash())
.ok();
RecoveredAuthorization::new_unchecked(
authorization.into_signed(self.signature()),
authority,
)
}
}

#[cfg(test)]
mod tests {

Expand Down
16 changes: 11 additions & 5 deletions bins/revme/src/cmd/statetest/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use revm::{
inspectors::TracerEip3155,
interpreter::analysis::to_analysed,
primitives::{keccak256, Bytes, TxKind, B256},
specification::hardfork::SpecId,
specification::{eip7702::AuthorizationList, hardfork::SpecId},
wiring::{
block::calc_excess_blob_gas,
default::EnvWiring,
Expand Down Expand Up @@ -378,10 +378,16 @@ pub fn execute_test_suite(
.and_then(Option::as_deref)
.cloned()
.unwrap_or_default();
let Ok(auth_list) = test.eip7702_authorization_list() else {
continue;
};
env.tx.authorization_list = auth_list;

env.tx.authorization_list =
unit.transaction
.authorization_list
.as_ref()
.map(|auth_list| {
AuthorizationList::Recovered(
auth_list.iter().map(|auth| auth.into_recovered()).collect(),
)
});

let to = match unit.transaction.to {
Some(add) => TxKind::Call(add),
Expand Down

0 comments on commit be1d324

Please sign in to comment.