Skip to content

Commit 80f47b1

Browse files
committed
EVM: remove a few more deps
- Remove OnceCell and replace it with an Option. - Move lazy_static to the dev dependencies. - Manually implement deref instead of importing a crate just for that. - Remove a bunch of unused dependencies.
1 parent 1280bb2 commit 80f47b1

File tree

4 files changed

+48
-66
lines changed

4 files changed

+48
-66
lines changed

Cargo.lock

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

actors/evm/Cargo.toml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,22 @@ anyhow = "1.0.65"
2727
log = "0.4.14"
2828
fvm_ipld_blockstore = "0.1.1"
2929
fvm_ipld_encoding = "0.3.3"
30-
rlp = { version = "0.5.1", default-features = false }
31-
strum = "0.24"
32-
strum_macros = "0.24"
3330
multihash = { version = "0.16.1", default-features = false }
34-
derive_more = "0.99"
35-
fixed-hash = { version = "0.7.0", default-features = false }
36-
impl-serde = { version = "0.3.2", default-features = false }
37-
arrayvec = { version = "0.7.2", features = ["serde"] }
3831
hex = { version = "0.4.3", features = ["serde"] }
3932
hex-literal = "0.3.4"
4033
substrate-bn = { version = "0.6.0", default-features = false }
4134
near-blake2 = { version = "0.9.1", git = "https://github.com/filecoin-project/near-blake2.git" }
42-
lazy_static = "1.4.0"
43-
once_cell = { version = "1.16.0", default-features = false}
4435
frc42_dispatch = "3.0.1-alpha.2"
4536
fil_actors_evm_shared = { version = "10.0.0-alpha.1", path = "shared" }
4637

4738
[dev-dependencies]
39+
lazy_static = "1.4.0"
4840
fil_actors_runtime = { path = "../../runtime", features = ["test_utils", "sector-default"] }
4941
etk-asm = "^0.2.1"
5042
ethers = { version = "1.0.2", features = ["abigen"] }
5143
serde_json = "1.0"
5244
rand = "0.8.5"
45+
once_cell = "1.17.0"
5346

5447
[features]
5548
fil-actor = ["fil_actors_runtime/fil-actor"]

actors/evm/src/interpreter/memory.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
use derive_more::{Deref, DerefMut};
2-
31
use crate::EVM_WORD_SIZE;
2+
use std::ops::{Deref, DerefMut};
43

54
const PAGE_SIZE: usize = 4 * 1024;
65

7-
#[derive(Clone, Debug, Deref, DerefMut)]
6+
#[derive(Clone, Debug)]
87
pub struct Memory(Vec<u8>);
98

9+
impl Deref for Memory {
10+
type Target = [u8];
11+
12+
fn deref(&self) -> &Self::Target {
13+
&*self.0
14+
}
15+
}
16+
17+
impl DerefMut for Memory {
18+
fn deref_mut(&mut self) -> &mut Self::Target {
19+
&mut *self.0
20+
}
21+
}
22+
1023
impl Default for Memory {
1124
fn default() -> Self {
1225
Self(Vec::with_capacity(PAGE_SIZE))
@@ -59,6 +72,6 @@ mod tests {
5972
let mut mem = Memory::default();
6073
mem.grow(PAGE_SIZE * 2 + 1);
6174
assert_eq!(mem.len(), PAGE_SIZE * 2 + EVM_WORD_SIZE);
62-
assert_eq!(mem.capacity(), PAGE_SIZE * 3);
75+
assert_eq!(mem.0.capacity(), PAGE_SIZE * 3);
6376
}
6477
}

actors/evm/src/interpreter/system.rs

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use fvm_shared::{
1717
MethodNum, Response, IPLD_RAW, METHOD_SEND,
1818
};
1919
use multihash::Code;
20-
use once_cell::unsync::OnceCell;
2120

2221
use crate::state::{State, Tombstone};
2322
use crate::BytecodeHash;
@@ -29,33 +28,27 @@ use {
2928
fvm_ipld_kamt::{AsHashedKey, Config as KamtConfig, Kamt},
3029
};
3130

32-
lazy_static::lazy_static! {
33-
// The Solidity compiler creates contiguous array item keys.
34-
// To prevent the tree from going very deep we use extensions,
35-
// which the Kamt supports and does in all cases.
36-
//
37-
// There are maximum 32 levels in the tree with the default bit width of 8.
38-
// The top few levels will have a higher level of overlap in their hashes.
39-
// Intuitively these levels should be used for routing, not storing data.
40-
//
41-
// The only exception to this is the top level variables in the contract
42-
// which solidity puts in the first few slots. There having to do extra
43-
// lookups is burdensome, and they will always be accessed even for arrays
44-
// because that's where the array length is stored.
45-
//
46-
// However, for Solidity, the size of the KV pairs is 2x256, which is
47-
// comparable to a size of a CID pointer plus extension metadata.
48-
// We can keep the root small either by force-pushing data down,
49-
// or by not allowing many KV pairs in a slot.
50-
//
51-
// The following values have been set by looking at how the charts evolved
52-
// with the test contract. They might not be the best for other contracts.
53-
static ref KAMT_CONFIG: KamtConfig = KamtConfig {
54-
min_data_depth: 0,
55-
bit_width: 5,
56-
max_array_width: 1
57-
};
58-
}
31+
// The Solidity compiler creates contiguous array item keys.
32+
// To prevent the tree from going very deep we use extensions,
33+
// which the Kamt supports and does in all cases.
34+
//
35+
// There are maximum 32 levels in the tree with the default bit width of 8.
36+
// The top few levels will have a higher level of overlap in their hashes.
37+
// Intuitively these levels should be used for routing, not storing data.
38+
//
39+
// The only exception to this is the top level variables in the contract
40+
// which solidity puts in the first few slots. There having to do extra
41+
// lookups is burdensome, and they will always be accessed even for arrays
42+
// because that's where the array length is stored.
43+
//
44+
// However, for Solidity, the size of the KV pairs is 2x256, which is
45+
// comparable to a size of a CID pointer plus extension metadata.
46+
// We can keep the root small either by force-pushing data down,
47+
// or by not allowing many KV pairs in a slot.
48+
//
49+
// The following values have been set by looking at how the charts evolved
50+
// with the test contract. They might not be the best for other contracts.
51+
const KAMT_CONFIG: KamtConfig = KamtConfig { min_data_depth: 0, bit_width: 5, max_array_width: 1 };
5952

6053
pub struct StateHashAlgorithm;
6154

@@ -109,7 +102,7 @@ pub struct System<'r, RT: Runtime> {
109102
/// Read Only context (staticcall)
110103
pub readonly: bool,
111104
/// Randomness taken from the current epoch of chain randomness
112-
randomness: OnceCell<[u8; 32]>,
105+
randomness: Option<[u8; 32]>,
113106

114107
/// This is "some" if the actor is currently a "zombie". I.e., it has selfdestructed, but the
115108
/// current message is still executing. `System` cannot load a contracts state with a
@@ -129,7 +122,7 @@ impl<'r, RT: Runtime> System<'r, RT> {
129122
saved_state_root: None,
130123
bytecode: None,
131124
readonly,
132-
randomness: OnceCell::new(),
125+
randomness: None,
133126
tombstone: None,
134127
}
135128
}
@@ -197,7 +190,7 @@ impl<'r, RT: Runtime> System<'r, RT> {
197190
saved_state_root: Some(state_root),
198191
bytecode: Some(EvmBytecode::new(state.bytecode, state.bytecode_hash)),
199192
readonly: read_only,
200-
randomness: OnceCell::new(),
193+
randomness: None,
201194
tombstone: state.tombstone,
202195
})
203196
}
@@ -441,14 +434,15 @@ impl<'r, RT: Runtime> System<'r, RT> {
441434
/// Gets the cached EVM randomness seed of the current epoch
442435
pub fn get_randomness(&mut self) -> Result<&[u8; 32], ActorError> {
443436
const ENTROPY: &[u8] = b"prevrandao";
444-
self.randomness.get_or_try_init(|| {
437+
match &mut self.randomness {
438+
Some(rand) => Ok(&*rand),
445439
// get randomness from current beacon epoch with entropy of "prevrandao"
446-
self.rt.get_randomness_from_beacon(
440+
cache => Ok(cache.insert(self.rt.get_randomness_from_beacon(
447441
fil_actors_runtime::runtime::DomainSeparationTag::EvmPrevRandao,
448442
self.rt.curr_epoch(),
449443
ENTROPY,
450-
)
451-
})
444+
)?)),
445+
}
452446
}
453447

454448
/// Mark ourselves as "selfdestructed".

0 commit comments

Comments
 (0)