Skip to content

Commit c4b0fc2

Browse files
authored
chore(evm): update deps (#1243)
* update deps * fix compile errors * fix * store raw bytecode * replace `AccountInfo` with `StoredAccountInfo`
1 parent 9850576 commit c4b0fc2

9 files changed

Lines changed: 595 additions & 364 deletions

File tree

packages/evm/Cargo.lock

Lines changed: 493 additions & 321 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/evm/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ members = ["core", "bindings"]
44

55
[workspace.package]
66
version = "0.1.0"
7-
rust-version = "1.91"
7+
rust-version = "1.93"
88
edition = "2024"
99
license = "GPL-3.0-only"
1010
authors = [""]
@@ -15,19 +15,19 @@ bincode = { version = "1.3.3" }
1515
ethers-contract = { version = "2.0.14" }
1616
ethers-core = { version = "2.0.14" }
1717
ethers-providers = { version = "2.0.14" }
18-
revm = { version = "34.0.0", features = ["alloydb", "serde", "serde-json"] }
19-
alloy-sol-types = { version = "1.5.2", default-features = false, features = [
18+
revm = { version = "36.0.0", features = ["alloydb", "serde", "serde-json"] }
19+
alloy-sol-types = { version = "1.5.7", default-features = false, features = [
2020
"std",
2121
] }
22-
alloy-primitives = { version = "1.5.2", default-features = false, features = [
22+
alloy-primitives = { version = "1.5.7", default-features = false, features = [
2323
"rlp",
2424
"map",
2525
] }
26-
alloy-provider = { version = "1.4.3", default-features = false }
26+
alloy-provider = { version = "1.7.3", default-features = false }
2727
serde = { version = "1.0", features = ["derive"] }
2828
serde_json = "1.0"
2929
thiserror = { version = "1.0" }
30-
tokio = { version = "1.47" }
30+
tokio = { version = "1.50" }
3131

3232
[profile.release]
3333
lto = true

packages/evm/bindings/src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use revm::{
3737
database::{State, TransitionAccount, WrapDatabaseRef, bal::EvmDatabaseError},
3838
handler::EvmTr,
3939
primitives::{Address, B256, Bytes, TxKind, U256, hex::ToHexExt, map::HashMap},
40-
state::{AccountInfo, Bytecode},
40+
state::AccountInfo,
4141
};
4242

4343
mod ctx;
@@ -173,10 +173,7 @@ impl EvmInner {
173173
EVMError::Database(format!("code lookup failed: {}", err).into())
174174
})?;
175175

176-
Ok(match code {
177-
Bytecode::LegacyAnalyzed(code) => code.original_bytes(),
178-
Bytecode::Eip7702(code) => code.raw.clone(),
179-
})
176+
Ok(code.original_bytes())
180177
}
181178
None => Ok(Default::default()),
182179
}

packages/evm/core/src/account.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use alloy_primitives::{B256, U256};
12
use revm::{primitives::Address, state::AccountInfo};
23
use serde::{Deserialize, Serialize};
34

@@ -23,3 +24,32 @@ impl AccountInfoExtended {
2324
)
2425
}
2526
}
27+
28+
#[derive(Default, Debug, Serialize, Deserialize)]
29+
pub(crate) struct StoredAccountInfo {
30+
pub balance: U256,
31+
pub nonce: u64,
32+
pub code_hash: B256,
33+
}
34+
35+
impl StoredAccountInfo {
36+
pub fn new(balance: U256, nonce: u64, code_hash: B256) -> Self {
37+
Self {
38+
balance,
39+
nonce,
40+
code_hash,
41+
}
42+
}
43+
}
44+
45+
impl From<StoredAccountInfo> for AccountInfo {
46+
fn from(stored: StoredAccountInfo) -> Self {
47+
AccountInfo {
48+
balance: stored.balance,
49+
nonce: stored.nonce,
50+
code_hash: stored.code_hash,
51+
account_id: None,
52+
code: None,
53+
}
54+
}
55+
}

packages/evm/core/src/bytecode.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use alloy_primitives::Bytes;
2+
use revm::{bytecode::BytecodeDecodeError, state::Bytecode};
3+
use serde::{Deserialize, Serialize};
4+
5+
#[derive(Default, Debug, Serialize, Deserialize)]
6+
pub struct StoredBytecode {
7+
pub raw: Bytes,
8+
}
9+
10+
impl From<Bytecode> for StoredBytecode {
11+
fn from(code: Bytecode) -> Self {
12+
Self {
13+
raw: code.original_bytes(),
14+
}
15+
}
16+
}
17+
18+
impl TryFrom<StoredBytecode> for Bytecode {
19+
type Error = BytecodeDecodeError;
20+
21+
fn try_from(stored: StoredBytecode) -> Result<Self, Self::Error> {
22+
Bytecode::new_raw_checked(stored.raw)
23+
}
24+
}

packages/evm/core/src/db.rs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ use revm::{
2121
use serde::{Deserialize, Serialize};
2222

2323
use crate::{
24-
account::AccountInfoExtended,
24+
account::{AccountInfoExtended, StoredAccountInfo},
25+
bytecode::StoredBytecode,
2526
compression::CompressedBincode,
2627
historical::{AccountHistory, HistoricalAccountData},
2728
legacy::{LegacyAccountAttributes, LegacyAddress, LegacyColdWallet},
@@ -155,15 +156,15 @@ pub(crate) struct CommitReceipts {
155156
}
156157

157158
pub(crate) struct InnerStorage {
158-
pub accounts: heed::Database<AddressWrapper, CompressedBincode<AccountInfo>>,
159+
pub accounts: heed::Database<AddressWrapper, CompressedBincode<StoredAccountInfo>>,
159160
pub accounts_history: Option<
160161
heed::Database<
161162
HeedBlockNumber,
162163
CompressedBincode<BTreeMap<Address, HistoricalAccountData>>,
163164
>,
164165
>,
165166
pub commits: heed::Database<HeedBlockNumber, CompressedBincode<CommitReceipts>>,
166-
pub contracts: heed::Database<HashWrapper, CompressedBincode<Bytecode>>,
167+
pub contracts: heed::Database<HashWrapper, CompressedBincode<StoredBytecode>>,
167168
pub legacy_attributes:
168169
heed::Database<AddressWrapper, CompressedBincode<LegacyAccountAttributes>>,
169170
pub legacy_cold_wallets:
@@ -316,6 +317,8 @@ impl PersistentDBOptions {
316317
pub enum Error {
317318
#[error("IO error: {0}")]
318319
IO(#[from] std::io::Error),
320+
#[error("BytecodeDecode error: {0}")]
321+
BytecodeDecode(#[from] revm::bytecode::BytecodeDecodeError),
319322
#[error("heed error: {0}")]
320323
Heed(#[from] heed::Error),
321324
#[error("state error: {0}")]
@@ -376,10 +379,11 @@ impl PersistentDB {
376379
let tx_env = env.clone();
377380
let mut wtxn = tx_env.write_txn()?;
378381

379-
let accounts = env.create_database::<AddressWrapper, CompressedBincode<AccountInfo>>(
380-
&mut wtxn,
381-
Some("accounts"),
382-
)?;
382+
let accounts = env
383+
.create_database::<AddressWrapper, CompressedBincode<StoredAccountInfo>>(
384+
&mut wtxn,
385+
Some("accounts"),
386+
)?;
383387

384388
let (accounts_history_db, accounts_history) = match opts.history_size {
385389
Some(history_size) if history_size > 0 => {
@@ -394,7 +398,7 @@ impl PersistentDB {
394398
&mut wtxn,
395399
Some("commits"),
396400
)?;
397-
let contracts = env.create_database::<HashWrapper, CompressedBincode<Bytecode>>(
401+
let contracts = env.create_database::<HashWrapper, CompressedBincode<StoredBytecode>>(
398402
&mut wtxn,
399403
Some("contracts"),
400404
)?;
@@ -757,7 +761,7 @@ impl DatabaseRef for PersistentDB {
757761
let inner = self.inner.borrow();
758762

759763
let basic = match inner.accounts.get(&txn, &AddressWrapper(address))? {
760-
Some(account) => account.0,
764+
Some(account) => account.0.into(),
761765
None => match &self.genesis_info {
762766
Some(genesis) if genesis.account == address => revm::state::AccountInfo {
763767
balance: genesis.initial_supply,
@@ -779,7 +783,7 @@ impl DatabaseRef for PersistentDB {
779783
None => Default::default(),
780784
};
781785

782-
Ok(contract)
786+
Ok(contract.try_into()?)
783787
}
784788

785789
fn storage_ref(&self, address: Address, index: U256) -> Result<U256, Self::Error> {
@@ -858,9 +862,15 @@ impl PersistentDB {
858862
let address = AddressWrapper(*address);
859863

860864
if let Some(account) = account {
861-
inner
862-
.accounts
863-
.put(rwtxn, &address, &CompressedBincode(account))?;
865+
inner.accounts.put(
866+
rwtxn,
867+
&address,
868+
&CompressedBincode(&StoredAccountInfo::new(
869+
account.balance,
870+
account.nonce,
871+
account.code_hash,
872+
)),
873+
)?;
864874
} else {
865875
inner.accounts.delete(rwtxn, &address)?;
866876
}
@@ -904,9 +914,11 @@ impl PersistentDB {
904914

905915
// Update contracts
906916
for (hash, bytecode) in contracts.into_iter() {
907-
inner
908-
.contracts
909-
.put(rwtxn, &HashWrapper(*hash), &CompressedBincode(&bytecode))?;
917+
inner.contracts.put(
918+
rwtxn,
919+
&HashWrapper(*hash),
920+
&CompressedBincode(&bytecode.clone().into()),
921+
)?;
910922
}
911923

912924
// Update storage
@@ -1656,7 +1668,7 @@ fn test_read_accounts() {
16561668
.put(
16571669
&mut wtxn,
16581670
&AddressWrapper(*address),
1659-
&CompressedBincode(&AccountInfo {
1671+
&CompressedBincode(&StoredAccountInfo {
16601672
balance: U256::from(index),
16611673
nonce: index as u64,
16621674
..Default::default()

packages/evm/core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod account;
2+
mod bytecode;
23
mod compression;
34
pub mod db;
45
mod events;

packages/evm/core/src/logs_bloom.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ fn test_calculate_logs_bloom() {
4040
)
4141
})
4242
.collect::<Vec<revm::primitives::Log>>(),
43-
gas_refunded: 0,
44-
gas_used: 0,
43+
gas: revm::context::result::ResultGas::default(),
4544
output: revm::context::result::Output::Call(Default::default()),
4645
reason: revm::context::result::SuccessReason::Stop,
4746
};

packages/evm/core/src/receipt.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,38 @@ pub struct TxReceipt {
1818
pub fn map_execution_result(result: ExecutionResult, cumulative_gas_used: u64) -> TxReceipt {
1919
match result {
2020
ExecutionResult::Success {
21-
gas_used,
22-
gas_refunded,
23-
output,
24-
logs,
25-
..
21+
gas, output, logs, ..
2622
} => match output {
2723
Output::Call(output) => TxReceipt {
28-
gas_used,
29-
gas_refunded,
24+
gas_used: gas.used(),
25+
gas_refunded: gas.inner_refunded(),
3026
cumulative_gas_used,
3127
success: 1,
3228
contract_address: None,
3329
logs: Some(logs),
3430
output: Some(output),
3531
},
3632
Output::Create(output, address) => TxReceipt {
37-
gas_used,
38-
gas_refunded,
33+
gas_used: gas.used(),
34+
gas_refunded: gas.inner_refunded(),
3935
cumulative_gas_used,
4036
success: 1,
4137
contract_address: address.map(|address| address.to_string()),
4238
logs: Some(logs),
4339
output: Some(output),
4440
},
4541
},
46-
ExecutionResult::Revert { gas_used, output } => TxReceipt {
47-
gas_used,
42+
ExecutionResult::Revert { gas, output, .. } => TxReceipt {
43+
gas_used: gas.used(),
4844
success: 0,
4945
cumulative_gas_used,
5046
gas_refunded: 0,
5147
contract_address: None,
5248
logs: None,
5349
output: Some(output),
5450
},
55-
ExecutionResult::Halt { gas_used, .. } => TxReceipt {
56-
gas_used,
51+
ExecutionResult::Halt { gas, .. } => TxReceipt {
52+
gas_used: gas.used(),
5753
success: 0,
5854
cumulative_gas_used,
5955
gas_refunded: 0,

0 commit comments

Comments
 (0)