Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(levm): change gas type from U256 to u64 #1528

Merged
merged 50 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
fa31055
A small step for man, a large leap for mankind
lima-limon-inc Dec 18, 2024
7b7a8d8
Change numeric values
lima-limon-inc Dec 18, 2024
e41f6b7
Change other numeric values
lima-limon-inc Dec 18, 2024
e5edf9a
Make functions return u64 instead of U256
lima-limon-inc Dec 18, 2024
0fce271
WIP: Gradual changes towards U256 -> u64
lima-limon-inc Dec 18, 2024
09178aa
WIP: Change gas from U256 to u64
lima-limon-inc Dec 18, 2024
42c9025
IN THEORY, only one bit is missing
lima-limon-inc Dec 18, 2024
c4b67cf
Changed the types? Is it done? It appears to be done
lima-limon-inc Dec 18, 2024
996d197
Fix test parsing using new u64 values
lima-limon-inc Dec 18, 2024
c0735b7
Fix lint errors
lima-limon-inc Dec 19, 2024
3f1aa51
Fix linter errors
lima-limon-inc Dec 19, 2024
510af03
Merge branch 'main' of github.com:lambdaclass/ethrex into fix/levm/ga…
lima-limon-inc Dec 19, 2024
7622e5d
Lint error
lima-limon-inc Dec 19, 2024
6832786
Fix linter errors
lima-limon-inc Dec 19, 2024
9403137
Change comments
lima-limon-inc Dec 19, 2024
7b3bccc
Change from VeryLargeNumber to InternalError
lima-limon-inc Dec 19, 2024
80a253d
Merge branch 'main' into fix/levm/gas_type
lima-limon-inc Dec 19, 2024
84c7b4f
Merge branch 'main' into fix/levm/gas_type
lima-limon-inc Dec 19, 2024
038c599
Change Error types and funciton name
lima-limon-inc Dec 19, 2024
78efd72
Merge branch 'main' into fix/levm/gas_type
lima-limon-inc Dec 19, 2024
9dfe812
Linter
lima-limon-inc Dec 19, 2024
96e289a
Merge branch 'main' into fix/levm/gas_type
lima-limon-inc Dec 19, 2024
35adb5c
Handle gas in u256 in generic_call; cast after capping
lima-limon-inc Dec 19, 2024
b438270
Merge branch 'fix/levm/gas_type' of github.com:lambdaclass/ethrex int…
lima-limon-inc Dec 19, 2024
15d8dde
ditto
lima-limon-inc Dec 19, 2024
e76d66c
Read the gas limit value as u64 directly
lima-limon-inc Dec 20, 2024
a0d2476
Serialize gas limit as u64 as well
lima-limon-inc Dec 20, 2024
0f0139a
Merge branch 'main' into fix/levm/gas_type
lima-limon-inc Dec 20, 2024
7bcfaf2
Change error comment
lima-limon-inc Dec 20, 2024
5e5a449
Merge branch 'fix/levm/gas_type' of github.com:lambdaclass/ethrex int…
lima-limon-inc Dec 20, 2024
027525c
Restore comments
lima-limon-inc Dec 20, 2024
d9c8e61
Rewrite comment
lima-limon-inc Dec 20, 2024
5219806
Remove debugging code
lima-limon-inc Dec 20, 2024
a6592d7
Spelling mistake
lima-limon-inc Dec 20, 2024
1e5bf00
Remove additional variable
lima-limon-inc Dec 20, 2024
17e8c68
Rollback error type
lima-limon-inc Dec 20, 2024
3f7852c
Remove gas_limit variable and use from(u64) directly
lima-limon-inc Dec 20, 2024
a0663bd
Merge branch 'main' into fix/levm/gas_type
lima-limon-inc Dec 20, 2024
85de951
Remove unused import
lima-limon-inc Dec 20, 2024
ef21d78
Recreate previous style to reduce changes in this PR
lima-limon-inc Dec 20, 2024
be608d8
Merge branch 'main' into fix/levm/gas_type
lima-limon-inc Dec 20, 2024
e0a5eec
Change variable name
lima-limon-inc Dec 20, 2024
e235e99
Change variable name
lima-limon-inc Dec 20, 2024
96b9bf5
Make gas_fee return U256
lima-limon-inc Dec 20, 2024
df0a717
Merge branch 'main' into fix/levm/gas_type
lima-limon-inc Dec 20, 2024
89edb87
Fix linter
lima-limon-inc Dec 20, 2024
04759e1
Revert "Change variable name"
lima-limon-inc Dec 20, 2024
669fb66
blob_gas_used -> blobhash_amount
lima-limon-inc Dec 20, 2024
c3c8b33
Revert "Change variable name"
lima-limon-inc Dec 20, 2024
341ca8d
Change variable name
lima-limon-inc Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/ef_tests/levm/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,11 @@ impl<'de> Deserialize<'de> for EFTests {
// 111, 112, 121, 122, 211, 212, 221, 222
for (data_id, data) in raw_tx.data.iter().enumerate() {
for (gas_limit_id, gas_limit) in raw_tx.gas_limit.iter().enumerate() {
let gas_limit_u64: u64 = (*gas_limit).as_u64();
for (value_id, value) in raw_tx.value.iter().enumerate() {
let tx = EFTestTransaction {
data: data.clone(),
gas_limit: *gas_limit,
gas_limit: gas_limit_u64,
gas_price: raw_tx.gas_price,
nonce: raw_tx.nonce,
secret_key: raw_tx.secret_key,
Expand Down
4 changes: 2 additions & 2 deletions cmd/ef_tests/levm/runner/levm_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub fn prepare_vm_for_tx(vector: &TestVector, test: &EFTest) -> Result<VM, EFTes
tx.to.clone(),
Environment {
origin: tx.sender,
refunded_gas: U256::default(),
refunded_gas: 0,
gas_limit: tx.gas_limit,
block_number: test.env.current_number,
coinbase: test.env.current_coinbase,
Expand All @@ -109,7 +109,7 @@ pub fn prepare_vm_for_tx(vector: &TestVector, test: &EFTest) -> Result<VM, EFTes
tx_max_priority_fee_per_gas: tx.max_priority_fee_per_gas,
tx_max_fee_per_gas: tx.max_fee_per_gas,
tx_max_fee_per_blob_gas: tx.max_fee_per_blob_gas,
block_gas_limit: test.env.current_gas_limit,
block_gas_limit: test.env.current_gas_limit.as_u64(),
},
tx.value,
tx.data.clone(),
Expand Down
8 changes: 5 additions & 3 deletions cmd/ef_tests/levm/runner/revm_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
utils::{effective_gas_price, load_initial_state},
};
use bytes::Bytes;
use ethrex_core::{types::TxKind, Address, H256};
use ethrex_core::{types::TxKind, Address, H256, U256};
use ethrex_levm::{
errors::{TransactionReport, TxResult},
Account, StorageSlot,
Expand Down Expand Up @@ -101,11 +101,13 @@ pub fn prepare_revm_for_tx<'state>(
let chain_spec = initial_state
.chain_config()
.map_err(|err| EFTestRunnerError::VMInitializationFailed(err.to_string()))?;

let gas_limit: U256 = test.env.current_gas_limit;
let block_env = RevmBlockEnv {
number: RevmU256::from_limbs(test.env.current_number.0),
coinbase: RevmAddress(test.env.current_coinbase.0.into()),
timestamp: RevmU256::from_limbs(test.env.current_timestamp.0),
gas_limit: RevmU256::from_limbs(test.env.current_gas_limit.0),
gas_limit: RevmU256::from_limbs(gas_limit.0),
lima-limon-inc marked this conversation as resolved.
Show resolved Hide resolved
basefee: RevmU256::from_limbs(test.env.current_base_fee.unwrap_or_default().0),
difficulty: RevmU256::from_limbs(test.env.current_difficulty.0),
prevrandao: test.env.current_random.map(|v| v.0.into()),
Expand Down Expand Up @@ -137,7 +139,7 @@ pub fn prepare_revm_for_tx<'state>(

let tx_env = RevmTxEnv {
caller: tx.sender.0.into(),
gas_limit: tx.gas_limit.as_u64(),
gas_limit: tx.gas_limit,
gas_price: RevmU256::from_limbs(effective_gas_price(test, tx)?.0),
transact_to: match tx.to {
TxKind::Call(to) => RevmTxKind::Call(to.0.into()),
Expand Down
2 changes: 1 addition & 1 deletion cmd/ef_tests/levm/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ pub struct EFTestRawTransaction {
#[serde(rename_all = "camelCase")]
pub struct EFTestTransaction {
pub data: Bytes,
pub gas_limit: U256,
pub gas_limit: u64,
pub gas_price: Option<U256>,
#[serde(deserialize_with = "deserialize_u256_safe")]
pub nonce: U256,
Expand Down
10 changes: 5 additions & 5 deletions crates/vm/levm/src/call_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ impl Stack {
/// the EVM is currently executing.
pub struct CallFrame {
/// Max gas a callframe can use
pub gas_limit: U256,
pub gas_limit: u64,
/// Keeps track of the gas that's been used in current context
pub gas_used: U256,
pub gas_used: u64,
/// Program Counter
pub pc: usize,
/// Address of the account that sent the message
Expand Down Expand Up @@ -95,7 +95,7 @@ impl CallFrame {
pub fn new_from_bytecode(bytecode: Bytes) -> Self {
let valid_jump_destinations = get_valid_jump_destinations(&bytecode).unwrap_or_default();
Self {
gas_limit: U256::MAX,
gas_limit: u64::MAX,
bytecode,
valid_jump_destinations,
..Default::default()
Expand All @@ -117,8 +117,8 @@ impl CallFrame {
msg_value: U256,
calldata: Bytes,
is_static: bool,
gas_limit: U256,
gas_used: U256,
gas_limit: u64,
gas_used: u64,
depth: usize,
create_op_called: bool,
) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/levm/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub const EMPTY_CODE_HASH: H256 = H256([
pub const MEMORY_EXPANSION_QUOTIENT: usize = 512;

// Transaction costs in gas (in wei)
pub const TX_BASE_COST: U256 = U256([21000, 0, 0, 0]);
pub const TX_BASE_COST: u64 = 21000;

pub const MAX_CODE_SIZE: usize = 0x6000;
pub const INIT_CODE_MAX_SIZE: usize = 49152;
Expand Down
10 changes: 5 additions & 5 deletions crates/vm/levm/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ pub struct Environment {
/// The sender address of the transaction that originated
/// this execution.
pub origin: Address,
pub refunded_gas: U256,
pub gas_limit: U256,
pub refunded_gas: u64,
pub gas_limit: u64,
pub block_number: U256,
pub coinbase: Address,
pub timestamp: U256,
Expand All @@ -20,15 +20,15 @@ pub struct Environment {
pub tx_max_priority_fee_per_gas: Option<U256>,
pub tx_max_fee_per_gas: Option<U256>,
pub tx_max_fee_per_blob_gas: Option<U256>,
pub block_gas_limit: U256,
pub block_gas_limit: u64,
}

impl Environment {
pub fn default_from_address(origin: Address) -> Self {
Self {
origin,
refunded_gas: U256::default(),
gas_limit: U256::MAX,
refunded_gas: 0,
gas_limit: u64::MAX,
block_number: Default::default(),
coinbase: Default::default(),
timestamp: Default::default(),
Expand Down
Loading
Loading