diff --git a/src/kernel_evm/ethereum/src/block.rs b/src/kernel_evm/ethereum/src/block.rs index 330b8b1ee72267e15cf8601a477bf2cf291d4ea0..34f416033f4371440eb26eb91139cd9a23e60762 100644 --- a/src/kernel_evm/ethereum/src/block.rs +++ b/src/kernel_evm/ethereum/src/block.rs @@ -24,7 +24,7 @@ pub struct BlockConstants { /// the value to an arbitrary value. pub difficulty: U256, /// Gas limit for the current block. - pub gas_limit: U256, + pub gas_limit: u64, /// The base fee per gas for doing a transaction. pub base_fee_per_gas: U256, /// Identifier for the chain. Normally this would identify the chain (Ethereum @@ -43,7 +43,7 @@ impl BlockConstants { coinbase: H160::zero(), timestamp: U256::zero(), difficulty: U256::zero(), - gas_limit: U256::one(), + gas_limit: 1u64, base_fee_per_gas: U256::one(), chain_id: U256::zero(), } @@ -68,7 +68,7 @@ pub struct L2Block { pub total_difficulty: U256, pub extra_data: OwnedHash, pub size: U256, - pub gas_limit: U256, + pub gas_limit: u64, pub gas_used: U256, pub timestamp: U256, pub transactions: Vec, @@ -103,7 +103,7 @@ impl L2Block { total_difficulty: U256::zero(), extra_data: L2Block::dummy_hash(), size: U256::zero(), - gas_limit: U256::one(), + gas_limit: 1u64, gas_used: U256::zero(), timestamp: U256::zero(), transactions, diff --git a/src/kernel_evm/ethereum/src/signatures.rs b/src/kernel_evm/ethereum/src/signatures.rs index 821297a7a296dcdbdf63bd79abdba05cbc95ea98..17d8517e7d17e6409d799c73dc9402ea9c278991 100644 --- a/src/kernel_evm/ethereum/src/signatures.rs +++ b/src/kernel_evm/ethereum/src/signatures.rs @@ -105,7 +105,7 @@ pub struct EthereumTransactionCommon { /// this transaction. This is paid up-front, before any /// computation is done and may not be increased /// later - pub gas_limit: U256, + pub gas_limit: u64, /// The 160-bit address of the message call’s recipient /// or, for a contract creation transaction pub to: EthereumAddress, @@ -315,7 +315,7 @@ impl Decodable for EthereumTransactionCommon { let mut it = decoder.iter(); let nonce: U256 = decode_field(&next(&mut it)?, "nonce")?; let gas_price: U256 = decode_field(&next(&mut it)?, "gas_price")?; - let gas_limit: U256 = decode_field(&next(&mut it)?, "gas_limit")?; + let gas_limit: u64 = decode_field(&next(&mut it)?, "gas_limit")?; let to: EthereumAddress = decode_field(&next(&mut it)?, "to")?; let value: U256 = decode_field(&next(&mut it)?, "value")?; let data: Vec = decode_field(&next(&mut it)?, "data")?; @@ -392,7 +392,7 @@ mod test { chain_id: U256::one(), nonce: U256::from(9), gas_price: U256::from(20000000000u64), - gas_limit: U256::from(21000), + gas_limit: 21000u64, to: EthereumAddress::from( "3535353535353535353535353535353535353535".to_string(), ), @@ -557,7 +557,7 @@ mod test { // signed tx : 0xf8572e8506c50218ba8304312280843b9aca0082ffff26a0e9637495be4c216a833ef390b1f6798917c8a102ab165c5085cced7ca1f2eb3aa057854e7044a8fee7bccb6a2c32c4229dd9cbacad74350789e0ce75bf40b6f713 let nonce = U256::from(46); let gas_price = U256::from(29075052730u64); - let gas_limit = U256::from(274722); + let gas_limit = 274722u64; let to = EthereumAddress::from("".to_string()); let value = U256::from(1000000000u64); let data: Vec = hex::decode("ffff").unwrap(); @@ -610,7 +610,7 @@ mod test { //setup let nonce = U256::from(0); let gas_price = U256::from(40000000000u64); - let gas_limit = U256::from(21000); + let gas_limit = 21000u64; let to = EthereumAddress::from("423163e58aabec5daa3dd1130b759d24bef0f6ea".to_string()); let value = U256::from(5000000000000000u64); @@ -674,7 +674,7 @@ mod test { //setup let nonce = U256::from(46); let gas_price = U256::from(29075052730u64); - let gas_limit = U256::from(274722); + let gas_limit = 274722u64; let to = EthereumAddress::from("ef1c6e67703c7bd7107eed8303fbe6ec2554bf6b".to_string()); let value = U256::from(760460536160301065u64); // /!\ > 2^53 -1 @@ -721,7 +721,7 @@ mod test { //setup let nonce = U256::from(46); let gas_price = U256::from(29075052730u64); - let gas_limit = U256::from(274722); + let gas_limit = 274722u64; let to = EthereumAddress::from("ef1c6e67703c7bd7107eed8303fbe6ec2554bf6b".to_string()); let value = U256::from(760460536160301065u64); // /!\ > 2^53 -1 @@ -774,7 +774,7 @@ mod test { chain_id: U256::one(), nonce: U256::from(1), gas_price: U256::from(30000000000u64), - gas_limit: U256::from(1048576), + gas_limit: 1048576u64, to: EthereumAddress::from( "4e1b2c985d729ae6e05ef7974013eeb48f394449".to_string(), ), @@ -818,7 +818,7 @@ mod test { chain_id: U256::one(), nonce: U256::from(1), gas_price: U256::from(30000000000u64), - gas_limit: U256::from(1048576), + gas_limit: 1048576u64, to: EthereumAddress::from( "4e1b2c985d729ae6e05ef7974013eeb48f394449".to_string(), ), @@ -863,7 +863,7 @@ mod test { chain_id: U256::one(), nonce: U256::from(1), gas_price: U256::from(30000000000u64), - gas_limit: U256::from(1048576), + gas_limit: 1048576u64, to: EthereumAddress::from( "4e1b2c985d729ae6e05ef7974013eeb48f394449".to_string(), ), @@ -941,7 +941,7 @@ mod test { chain_id: U256::one(), nonce: U256::from(46), gas_price: U256::from(29075052730u64), - gas_limit: U256::from(274722), + gas_limit: 274722u64, to: EthereumAddress::from( "ef1c6e67703c7bd7107eed8303fbe6ec2554bf6b".to_string(), ), @@ -977,7 +977,7 @@ mod test { chain_id: U256::one(), nonce: U256::from(46), gas_price: U256::from(29075052730u64), - gas_limit: U256::from(274722), + gas_limit: 274722u64, to: EthereumAddress::from( "ef1c6e67703c7bd7107eed8303fbe6ec2554bf6b".to_string(), ), @@ -1012,7 +1012,7 @@ mod test { chain_id: U256::one(), nonce: U256::from(46), gas_price: U256::from(29075052730u64), - gas_limit: U256::from(274722), + gas_limit: 274722u64, to: EthereumAddress::from( "ef1c6e67703c7bd7107eed8303fbe6ec2554bf6b".to_string(), ), diff --git a/src/kernel_evm/evm_execution/src/handler.rs b/src/kernel_evm/evm_execution/src/handler.rs index 3229ce3562eab4e3c5b017a3c25fee2bf9ccaa5f..c278b24398fc8f5b1f9ebb0f2d4c05848a59df79 100644 --- a/src/kernel_evm/evm_execution/src/handler.rs +++ b/src/kernel_evm/evm_execution/src/handler.rs @@ -804,7 +804,7 @@ impl<'a, Host: Runtime> Handler for EvmHandler<'a, Host> { } fn block_gas_limit(&self) -> U256 { - self.block.gas_limit + self.block.gas_limit.into() } fn block_base_fee_per_gas(&self) -> U256 { diff --git a/src/kernel_evm/kernel/src/block.rs b/src/kernel_evm/kernel/src/block.rs index 6897a245ca298df67e3132709e133501eefa23f3..5c0440458b084a3eee2a5a6c38c58173bfdb5e71 100644 --- a/src/kernel_evm/kernel/src/block.rs +++ b/src/kernel_evm/kernel/src/block.rs @@ -2,8 +2,6 @@ // // SPDX-License-Identifier: MIT -use std::panic::catch_unwind; - use crate::blueprint::Queue; use crate::error::Error; use crate::error::StorageError::AccountInitialisation; @@ -124,10 +122,6 @@ pub fn produce(host: &mut Host, queue: Queue) -> Result<(), Error let transactions = proposal.transactions; for (transaction, index) in transactions.into_iter().zip(0u32..) { - // TODO: https://gitlab.com/tezos/tezos/-/issues/5487 - // gas_limit representation should be the same through all modules to avoid - // odd conversions - let gas_limit = catch_unwind(|| transaction.tx.gas_limit.as_u64()).ok(); let caller = transaction .tx .caller() @@ -140,7 +134,7 @@ pub fn produce(host: &mut Host, queue: Queue) -> Result<(), Error transaction.tx.to.into(), caller.into(), transaction.tx.data, - gas_limit, + Some(transaction.tx.gas_limit), Some(transaction.tx.value), ) { Ok(outcome) => { @@ -234,7 +228,7 @@ mod tests { // corresponding caller's address is 0xaf1276cbb260bb13deddb4209ae99ae6e497f446 let nonce = U256::from(0); let gas_price = U256::from(40000000000u64); - let gas_limit = U256::from(21000); + let gas_limit = 21000u64; let to = EthereumAddress::from("423163e58aabec5daa3dd1130b759d24bef0f6ea".to_string()); let value = U256::from(5000000000000000u64); diff --git a/src/kernel_evm/kernel_benchmark/src/inbox.rs b/src/kernel_evm/kernel_benchmark/src/inbox.rs index a2d4e806a971a35887504aec4d4adc025d8f6ee7..ce2124970243842e3a03bef585a4ad62f22292c6 100644 --- a/src/kernel_evm/kernel_benchmark/src/inbox.rs +++ b/src/kernel_evm/kernel_benchmark/src/inbox.rs @@ -112,7 +112,7 @@ where e.to.into(), e.caller()?.into(), e.data, - Some(e.gas_limit.as_u64()), + Some(e.gas_limit), Some(e.value), )?;