Skip to content

Commit a82801b

Browse files
authored
feat: integrate alloy-eips (#2078)
1 parent 8858a31 commit a82801b

File tree

11 files changed

+83
-66
lines changed

11 files changed

+83
-66
lines changed

Cargo.lock

+24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ statetest-types = { path = "crates/statetest-types", package = "revm-statetest-t
5353
context = { path = "crates/context", package = "revm-context", version = "1.0.0", default-features = false }
5454
context-interface = { path = "crates/context/interface", package = "revm-context-interface", version = "1.0.0", default-features = false }
5555
handler = { path = "crates/handler", package = "revm-handler", version = "1.0.0", default-features = false }
56+
57+
# alloy
58+
alloy-eip2930 = { version = "0.1.0", default-features = false }
59+
alloy-eip7702 = { version = "0.5.0", default-features = false }
60+
5661
# misc
5762
cfg-if = { version = "1.0", default-features = false }
5863
auto_impl = { version = "1.2.0" }

bins/revme/src/cmd/statetest/runner.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,8 @@ pub fn execute_test_suite(
383383
.transaction
384384
.access_lists
385385
.get(test.indexes.data)
386-
.and_then(Option::as_deref)
387-
.map(|access_list| {
388-
access_list
389-
.iter()
390-
.map(|item| (item.address, item.storage_keys.clone()))
391-
.collect()
392-
})
386+
.cloned()
387+
.flatten()
393388
.unwrap_or_default();
394389

395390
tx.authorization_list = unit

crates/context/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ specification.workspace = true
3232
bytecode.workspace = true
3333
auto_impl.workspace = true
3434

35+
# alloy
36+
alloy-eip2930.workspace = true
37+
alloy-eip7702 = { workspace = true, features = ["k256"] }
38+
3539
# misc
3640
derive-where.workspace = true
3741
cfg-if.workspace = true

crates/context/src/tx.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use alloy_eip2930::AccessList;
2+
use alloy_eip7702::SignedAuthorization;
13
use context_interface::transaction::AuthorizationItem;
24
use context_interface::Transaction;
35
use core::fmt::Debug;
@@ -39,7 +41,7 @@ pub struct TxEnv {
3941
/// Added in [EIP-2930].
4042
///
4143
/// [EIP-2930]: https://eips.ethereum.org/EIPS/eip-2930
42-
pub access_list: Vec<(Address, Vec<B256>)>,
44+
pub access_list: AccessList,
4345

4446
/// The priority fee per gas
4547
///
@@ -72,7 +74,7 @@ pub struct TxEnv {
7274
/// Set EOA account code for one transaction via [EIP-7702].
7375
///
7476
/// [EIP-7702]: https://eips.ethereum.org/EIPS/eip-7702
75-
pub authorization_list: Vec<AuthorizationItem>,
77+
pub authorization_list: Vec<SignedAuthorization>,
7678
}
7779

7880
impl Default for TxEnv {
@@ -87,7 +89,7 @@ impl Default for TxEnv {
8789
data: Bytes::default(),
8890
nonce: 0,
8991
chain_id: Some(1), // Mainnet chain ID is 1
90-
access_list: Vec::new(),
92+
access_list: Default::default(),
9193
gas_priority_fee: Some(0),
9294
blob_hashes: Vec::new(),
9395
max_fee_per_blob_gas: 0,
@@ -132,8 +134,9 @@ impl Transaction for TxEnv {
132134
fn access_list(&self) -> Option<impl Iterator<Item = (&Address, &[B256])>> {
133135
Some(
134136
self.access_list
137+
.0
135138
.iter()
136-
.map(|(address, storage_keys)| (address, storage_keys.as_slice())),
139+
.map(|item| (&item.address, item.storage_keys.as_slice())),
137140
)
138141
}
139142

@@ -150,7 +153,14 @@ impl Transaction for TxEnv {
150153
}
151154

152155
fn authorization_list(&self) -> impl Iterator<Item = AuthorizationItem> {
153-
self.authorization_list.iter().cloned()
156+
self.authorization_list.iter().map(|item| {
157+
(
158+
item.recover_authority().ok(),
159+
item.chain_id,
160+
item.nonce,
161+
item.address,
162+
)
163+
})
154164
}
155165

156166
fn input(&self) -> &Bytes {

crates/revm/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ indicatif = "0.17"
4545
reqwest = { version = "0.12" }
4646
rstest = "0.22.0"
4747

48+
alloy-eip7702.workspace = true
4849
alloy-provider = "0.9.2"
50+
alloy-signer = "0.9.2"
51+
alloy-signer-local = "0.9.2"
4952

5053
[features]
5154
default = ["std", "c-kzg", "secp256k1", "portable", "blst"]

crates/revm/src/mainnet_exec_inspect.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,29 @@ where
109109
mod test {
110110
use super::*;
111111
use crate::{MainBuilder, MainContext};
112+
use alloy_eip7702::Authorization;
113+
use alloy_signer::SignerSync;
114+
use alloy_signer_local::PrivateKeySigner;
112115
use bytecode::{
113116
opcode::{PUSH1, SSTORE},
114117
Bytecode,
115118
};
116119
use context::Context;
117120
use context_interface::TransactionType;
118121
use database::{BenchmarkDB, EEADDRESS, FFADDRESS};
119-
use primitives::{address, TxKind, U256};
122+
use primitives::{TxKind, U256};
120123
use specification::hardfork::SpecId;
121124

122125
#[test]
123126
fn sanity_eip7702_tx() {
124-
let auth = address!("0000000000000000000000000000000000000100");
127+
let signer = PrivateKeySigner::random();
128+
let auth = Authorization {
129+
chain_id: U256::ZERO,
130+
nonce: 0,
131+
address: FFADDRESS,
132+
};
133+
let signature = signer.sign_hash_sync(&auth.signature_hash()).unwrap();
134+
let auth = auth.into_signed(signature);
125135

126136
let bytecode = Bytecode::new_legacy([PUSH1, 0x01, PUSH1, 0x01, SSTORE].into());
127137

@@ -131,16 +141,16 @@ mod test {
131141
.modify_tx_chained(|tx| {
132142
tx.tx_type = TransactionType::Eip7702.into();
133143
tx.gas_limit = 100_000;
134-
tx.authorization_list = vec![(Some(auth), U256::from(0), 0, FFADDRESS)];
144+
tx.authorization_list = vec![auth];
135145
tx.caller = EEADDRESS;
136-
tx.kind = TxKind::Call(auth);
146+
tx.kind = TxKind::Call(signer.address());
137147
});
138148

139149
let mut evm = ctx.build_mainnet();
140150

141151
let ok = evm.transact_previous().unwrap();
142152

143-
let auth_acc = ok.state.get(&auth).unwrap();
153+
let auth_acc = ok.state.get(&signer.address()).unwrap();
144154
assert_eq!(auth_acc.info.code, Some(Bytecode::new_eip7702(FFADDRESS)));
145155
assert_eq!(auth_acc.info.nonce, 1);
146156
assert_eq!(

crates/statetest-types/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ all = "warn"
2626
revm = { workspace = true, features = ["std", "serde"] }
2727
serde = { version = "1.0", features = ["derive", "rc"] }
2828
serde_json = { version = "1.0", features = ["preserve_order"] }
29+
30+
# alloy
31+
alloy-eip2930 = { workspace = true, features = ["serde"] }
32+
alloy-eip7702 = { workspace = true, features = ["serde"] }

crates/statetest-types/src/test_authorization.rs

+7-34
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,17 @@
1-
use revm::{
2-
context_interface::transaction::AuthorizationItem,
3-
primitives::{Address, U256},
4-
specification::eip2::SECP256K1N_HALF,
5-
};
1+
use alloy_eip7702::SignedAuthorization;
62
use serde::{Deserialize, Serialize};
73

84
/// Struct for test authorization
95
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
10-
#[serde(rename_all = "camelCase", deny_unknown_fields)]
6+
#[serde(rename_all = "camelCase")]
117
pub struct TestAuthorization {
12-
/// The chain ID of the authorization.
13-
pub chain_id: U256,
14-
/// The address of the authorization.
15-
pub address: Address,
16-
/// The nonce for the authorization.
17-
pub nonce: U256,
18-
v: U256,
19-
r: U256,
20-
s: U256,
21-
signer: Option<Address>,
8+
#[serde(flatten)]
9+
inner: SignedAuthorization,
2210
}
2311

24-
impl From<TestAuthorization> for AuthorizationItem {
25-
fn from(auth: TestAuthorization) -> AuthorizationItem {
26-
let mut signer = auth.signer;
27-
28-
if auth.s > SECP256K1N_HALF {
29-
signer = None
30-
}
31-
32-
if auth.v > U256::from(1) {
33-
signer = None
34-
}
35-
36-
(
37-
signer,
38-
auth.chain_id,
39-
auth.nonce.try_into().unwrap_or(u64::MAX),
40-
auth.address,
41-
)
12+
impl From<TestAuthorization> for SignedAuthorization {
13+
fn from(auth: TestAuthorization) -> Self {
14+
auth.inner
4215
}
4316
}
4417

crates/statetest-types/src/transaction.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
use crate::{deserializer::deserialize_maybe_empty, TestAuthorization};
2+
use alloy_eip2930::AccessList;
13
use revm::{
24
context_interface::transaction::TransactionType,
35
primitives::{Address, Bytes, B256, U256},
46
};
57
use serde::{Deserialize, Serialize};
68

7-
use crate::{deserializer::deserialize_maybe_empty, TestAuthorization};
8-
99
/// Transaction parts.
1010
#[derive(Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1111
#[serde(rename_all = "camelCase")]
@@ -25,7 +25,7 @@ pub struct TransactionParts {
2525
pub max_priority_fee_per_gas: Option<U256>,
2626

2727
#[serde(default)]
28-
pub access_lists: Vec<Option<Vec<AccessListItem>>>,
28+
pub access_lists: Vec<Option<AccessList>>,
2929
pub authorization_list: Option<Vec<TestAuthorization>>,
3030
#[serde(default)]
3131
pub blob_versioned_hashes: Vec<B256>,
@@ -82,13 +82,6 @@ pub struct TxPartIndices {
8282
pub value: usize,
8383
}
8484

85-
#[derive(Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
86-
#[serde(rename_all = "camelCase", deny_unknown_fields)]
87-
pub struct AccessListItem {
88-
pub address: Address,
89-
pub storage_keys: Vec<B256>,
90-
}
91-
9285
#[cfg(test)]
9386
mod test {
9487

examples/block_traces/src/main.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,7 @@ async fn main() -> anyhow::Result<()> {
126126
etx.chain_id = Some(chain_id);
127127
etx.nonce = tx.nonce();
128128
if let Some(access_list) = tx.access_list() {
129-
etx.access_list = access_list
130-
.0
131-
.iter()
132-
.map(|item| (item.address, item.storage_keys.clone()))
133-
.collect();
129+
etx.access_list = access_list.clone()
134130
} else {
135131
etx.access_list = Default::default();
136132
}

0 commit comments

Comments
 (0)