Skip to content

Commit

Permalink
migrated to the latest fluentbase version
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry123 committed Oct 11, 2024
1 parent 2f2e21a commit 8363bf5
Show file tree
Hide file tree
Showing 24 changed files with 795 additions and 2,927 deletions.
2,379 changes: 752 additions & 1,627 deletions Cargo.lock

Large diffs are not rendered by default.

26 changes: 5 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -348,19 +348,16 @@ reth-trie-parallel = { path = "crates/trie/parallel" }
# "std",
#], default-features = false }
#revm-inspectors = { git = "https://github.com/paradigmxyz/revm-inspectors", rev = "4fe17f0" }

revm = { package = "revm-fluent", git = "https://github.com/fluentlabs-xyz/fluentbase", branch = "devel", features = [
revm = { git = "https://github.com/fluentlabs-xyz/fluentbase", branch = "devel", features = [
"std",
"secp256k1",
"blst",
"rwasm",
# "debug_print",
# "debug_print",
], default-features = false }
revm-primitives = { git = "https://github.com/fluentlabs-xyz/fluentbase", branch = "devel", features = ["rwasm"] }
revm-inspectors = { git = "https://github.com/fluentlabs-xyz/revm-inspectors.git", branch = "devel", features = [
"rwasm",
] }
#revm = { package = "revm-fluent", path = "../fluentbase/revm/crates/revm_fluent", features = [
revm-primitives = { git = "https://github.com/fluentlabs-xyz/fluentbase", branch = "devel" }
revm-inspectors = { git = "https://github.com/fluentlabs-xyz/revm-inspectors.git", branch = "devel" }
#revm = { path = "../fluentbase/revm/crates/revm", features = [
# "std",
# "secp256k1",
# "blst",
Expand All @@ -381,19 +378,6 @@ fluentbase-genesis = { git = "https://github.com/fluentlabs-xyz/fluentbase", bra
#fluentbase-sdk = { path = "../fluentbase/crates/sdk", default-features = false }
#fluentbase-genesis = { path = "../fluentbase/crates/genesis", default-features = false }

fuel-tx = { git = "https://github.com/fluentlabs-xyz/fuel-vm", branch = "develop", default-features = false, features = ["alloc"] }
fuel-vm = { git = "https://github.com/fluentlabs-xyz/fuel-vm", branch = "develop", default-features = false, features = ["alloc"] }
fuel-core = { git = "https://github.com/fluentlabs-xyz/fuel-core", branch = "devel" }
fuel-core-types = { git = "https://github.com/fluentlabs-xyz/fuel-core", branch = "devel", default-features = false, features = ["serde", "alloc"] }
fuel-core-executor = { git = "https://github.com/fluentlabs-xyz/fuel-core", branch = "devel", default-features = false, features = ["alloc"] }
fuel-core-storage = { git = "https://github.com/fluentlabs-xyz/fuel-core", branch = "devel", default-features = false, features = ["alloc"] }
#fuel-tx = { path = "../../fluentlabs-xyz/fuel-vm/fuel-tx", default-features = false, features = ["alloc"] }
#fuel-vm = { path = "../../fluentlabs-xyz/fuel-vm/fuel-vm", default-features = false, features = ["alloc"] }
#fuel-core = { path = "../fuel-core/crates/fuel-core" }
#fuel-core-types = { path = "../fuel-core/crates/types", default-features = false, features = ["serde", "alloc"] }
#fuel-core-executor = { path = "../fuel-core/crates/services/executor", default-features = false, features = ["alloc"] }
#fuel-core-storage = { path = "../fuel-core/crates/storage", default-features = false, features = ["alloc"] }

# eth
alloy-chains = "0.1.15"
alloy-primitives = "0.7.2"
Expand Down
4 changes: 2 additions & 2 deletions crates/primitives-traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ workspace = true
[dependencies]
# fluentbase
fluentbase-poseidon.workspace = true
fluentbase-genesis.workspace = true

reth-codecs.workspace = true

Expand Down Expand Up @@ -54,4 +53,5 @@ arbitrary = [
"dep:proptest",
"dep:proptest-derive"
]
alloy-compat = ["alloy-rpc-types-eth"]
alloy-compat = ["alloy-rpc-types-eth"]
rwasm = []
27 changes: 6 additions & 21 deletions crates/primitives-traits/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use alloy_consensus::constants::KECCAK_EMPTY;
use alloy_genesis::GenesisAccount;
use alloy_primitives::{keccak256, B256, U256};
use reth_codecs::{main_codec, Compact};
use std::ops::Deref;
use fluentbase_genesis::devnet::{GENESIS_POSEIDON_HASH_SLOT, GENESIS_KECCAK_HASH_SLOT};
use fluentbase_poseidon::poseidon_hash;

/// An Ethereum account.
Expand All @@ -16,8 +14,6 @@ pub struct Account {
pub balance: U256,
/// Hash of the account's bytecode.
pub bytecode_hash: Option<B256>,
/// Hash of the rWASM bytecode
pub rwasm_hash: Option<B256>,
}

impl Account {
Expand All @@ -26,7 +22,7 @@ impl Account {
self.bytecode_hash.is_some()
}

/// After `SpuriousDragon` empty account is defined as account with nonce == 0 && balance == 0
/// After `SpuriousDragon` empty account is defined as an account with nonce == 0 && balance == 0
/// && bytecode = None (or hash is [`KECCAK_EMPTY`]).
pub fn is_empty(&self) -> bool {
self.nonce == 0 &&
Expand All @@ -36,26 +32,15 @@ impl Account {

/// Makes an [Account] from [`GenesisAccount`] type
pub fn from_genesis_account(value: &GenesisAccount) -> Self {
// let bytecode_hash = value.storage
// .as_ref()
// .and_then(|s| s.get(&GENESIS_KECCAK_HASH_SLOT))
// .cloned()
// .or_else(|| {
// value.code.as_ref().map(|bytes| keccak256(bytes.as_ref()))
// });
let rwasm_hash = value.storage
.as_ref()
.and_then(|s| s.get(&GENESIS_KECCAK_HASH_SLOT))
.cloned()
.or_else(|| {
value.code.as_ref().map(|bytes| B256::from(poseidon_hash(bytes.as_ref())))
});
Self {
// nonce must exist, so we default to zero when converting a genesis account
nonce: value.nonce.unwrap_or_default(),
balance: value.balance,
bytecode_hash: value.code.as_ref().map(keccak256),
rwasm_hash,
bytecode_hash: value.code.as_ref().map(|v| if cfg!(feature = "rwasm") {
B256::from(poseidon_hash(v))
} else {
keccak256(v)
}),
}
}

Expand Down
15 changes: 1 addition & 14 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ reth-chainspec.workspace = true
revm.workspace = true
revm-primitives = { workspace = true, features = ["serde"] }

# fluentbase
fluentbase-core.workspace = true

# fuel
fuel-vm = { workspace = true, default-features = false, features = ["alloc"] }
fuel-tx = { workspace = true, default-features = false, features = ["alloc"] }
fuel-core = { workspace = true }
fuel-core-types = { workspace = true, default-features = false, features = ["serde", "alloc"] }
fuel-core-executor = { workspace = true, default-features = false, features = ["alloc"] }
fuel-core-storage = { workspace = true, default-features = false, features = ["alloc"] }

# ethereum
alloy-consensus = { workspace = true, features = ["serde"] }
alloy-primitives = { workspace = true, features = ["rand", "rlp"] }
Expand Down Expand Up @@ -77,9 +66,6 @@ alloy-trie = { workspace = true, features = ["arbitrary"] }
alloy-eips = { workspace = true, features = ["arbitrary"] }
alloy-consensus = { workspace = true, features = ["arbitrary"] }

# fuel-vm
fuel-vm = { workspace = true, default-features = false, features = ["test-helpers"] }

assert_matches.workspace = true
arbitrary = { workspace = true, features = ["derive"] }
proptest.workspace = true
Expand Down Expand Up @@ -137,6 +123,7 @@ alloy-compat = [
]
std = ["thiserror-no-std/std"]
test-utils = ["reth-primitives-traits/test-utils"]
rwasm = []

[[bench]]
name = "recover_ecdsa_crit"
Expand Down
35 changes: 1 addition & 34 deletions crates/primitives/src/alloy_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ use alloc::vec::Vec;

use alloy_primitives::TxKind;
use alloy_rlp::Error as RlpError;
use revm_primitives::{hex, Bytes};

use crate::{
constants::EMPTY_TRANSACTIONS,
transaction::{extract_chain_id, ExecutionEnvironment},
transaction::{extract_chain_id},
Block, Signature, Transaction, TransactionSigned, TransactionSignedEcRecovered, TxEip1559,
TxEip2930, TxEip4844, TxLegacy, TxType,
};
Expand Down Expand Up @@ -210,38 +209,6 @@ impl TryFrom<alloy_rpc_types::Transaction> for Transaction {
is_system_transaction: tx.from == crate::constants::OP_SYSTEM_TX_FROM_ADDR,
input: tx.input,
})),
Some(TxType::FluentV1) => {
let execution_environment_type = tx
.other
.get_deserialized::<String>("executionEnvironment")
.ok_or_else(|| {
ConversionError::Custom("MissingExecutionEnvironment".to_string())
})?
.map_err(|_| {
ConversionError::Custom("InvalidExecutionEnvironment".to_string())
})?;
let raw_data = tx
.other
.get_deserialized::<String>("rawData")
.ok_or_else(|| ConversionError::Custom("MissingRawData".to_string()))?
.map_err(|_| ConversionError::Custom("InvalidRawData".to_string()))?;

let raw_data = raw_data.trim_start_matches("0x");
let raw_data = hex::decode(raw_data)
.map_err(|_| ConversionError::Custom("InvalidRawData".to_string()))?;
let raw_data = Bytes::from(raw_data);

let execution_environment = ExecutionEnvironment::from_str_with_data(
&execution_environment_type,
raw_data.clone().into(),
)
.map_err(|_| ConversionError::Custom("InvalidExecutionEnvironment".to_string()))?;

Ok(Self::FluentV1(crate::transaction::TxFluentV1 {
execution_environment,
data: raw_data.into(),
}))
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ pub use transaction::{
AccessList, AccessListItem, IntoRecoveredTransaction, InvalidTransactionError, Signature,
Transaction, TransactionMeta, TransactionSigned, TransactionSignedEcRecovered,
TransactionSignedNoHash, TryFromRecoveredTransaction, TxEip1559, TxEip2930, TxEip4844,
TxFluentV1, TxHashOrNumber, TxLegacy, TxType, EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID,
EIP4844_TX_TYPE_ID, FLUENT_TX_V1_TYPE_ID, LEGACY_TX_TYPE_ID,
TxHashOrNumber, TxLegacy, TxType, EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID,
EIP4844_TX_TYPE_ID, LEGACY_TX_TYPE_ID,
};

pub use withdrawal::{Withdrawal, Withdrawals};
Expand Down
8 changes: 0 additions & 8 deletions crates/primitives/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,6 @@ impl Decodable for ReceiptWithBloom {
buf.advance(1);
Self::decode_receipt(buf, TxType::Deposit)
}
0x34 => {
// 0x34 == 52
buf.advance(1);
Self::decode_receipt(buf, TxType::FluentV1)
}
_ => Err(alloy_rlp::Error::Custom("invalid receipt type")),
}
}
Expand Down Expand Up @@ -513,9 +508,6 @@ impl<'a> ReceiptWithBloomEncoder<'a> {
TxType::Deposit => {
out.put_u8(0x7E);
}
TxType::FluentV1 => {
out.put_u8(0x52);
}
}
out.put_slice(payload.as_ref());
}
Expand Down
16 changes: 7 additions & 9 deletions crates/primitives/src/revm/compat.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{revm_primitives::AccountInfo, Account, Address, TxKind, KECCAK_EMPTY, U256};
use crate::{revm_primitives::{AccountInfo, POSEIDON_EMPTY}, Account, Address, TxKind, KECCAK_EMPTY, U256};
use revm::{interpreter::gas::validate_initial_tx_gas, primitives::SpecId};
use revm_primitives::POSEIDON_EMPTY;

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
Expand All @@ -9,13 +8,10 @@ use alloc::vec::Vec;
///
/// Sets `bytecode_hash` to `None` if `code_hash` is [`KECCAK_EMPTY`].
pub fn into_reth_acc(revm_acc: AccountInfo) -> Account {
let code_hash = revm_acc.code_hash;
let rwasm_code_hash = revm_acc.rwasm_code_hash;
Account {
balance: revm_acc.balance,
nonce: revm_acc.nonce,
bytecode_hash: (code_hash != KECCAK_EMPTY).then_some(code_hash),
rwasm_hash: (revm_acc.rwasm_code_hash != POSEIDON_EMPTY).then_some(rwasm_code_hash),
bytecode_hash: (!revm_acc.is_empty_code_hash()).then_some(revm_acc.code_hash),
}
}

Expand All @@ -26,10 +22,12 @@ pub fn into_revm_acc(reth_acc: Account) -> AccountInfo {
AccountInfo {
balance: reth_acc.balance,
nonce: reth_acc.nonce,
code_hash: reth_acc.bytecode_hash.unwrap_or(KECCAK_EMPTY),
rwasm_code_hash: reth_acc.rwasm_hash.unwrap_or(POSEIDON_EMPTY),
code_hash: reth_acc.bytecode_hash.unwrap_or(if cfg!(feature = "rwasm") {
POSEIDON_EMPTY
} else {
KECCAK_EMPTY
}),
code: None,
rwasm_code: None,
}
}

Expand Down
14 changes: 0 additions & 14 deletions crates/primitives/src/revm/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use revm_primitives::OptimismFields;

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use revm_primitives::ExecutionEnvironment;

/// Fill block environment from Block.
pub fn fill_block_env(
Expand Down Expand Up @@ -341,19 +340,6 @@ where
tx_env.chain_id = None;
tx_env.nonce = None;
}
Transaction::FluentV1(tx) => {
// TODO: d1r1 we need to use the ExecutionEnvironment from the transaction
let exec_env_u8: u8 = tx.execution_environment.clone().into();
let exec_env = ExecutionEnvironment::try_from(exec_env_u8).unwrap();

tx_env.gas_limit = tx.gas_limit();
tx_env.gas_price = U256::from(tx.gas_price());
tx_env.gas_priority_fee = Some(U256::from(tx.max_priority_fee_per_gas().unwrap()));
tx_env.transact_to = TransactTo::Blended(exec_env, tx.data.clone());
tx_env.value = *tx.value();
tx_env.chain_id = tx.chain_id();
tx_env.nonce = Some(tx.nonce());
}
}
}

Expand Down
Loading

0 comments on commit 8363bf5

Please sign in to comment.