forked from lambdaclass/ethrex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(levm): opcodes gas consumption (lambdaclass#584)
**Motivation** Implement `GAS` opcode, which requires a first global handling of gas consumption. <!-- Why does this pull request exist? What are its goals? --> **Description** - Uses `VM::gas_limit` and `VM::consumed_gas` for handling all opcodes static and dynamic gas consumption. - Check if gas is enough before executing each one of them. - Save `warm_addresses` in `VM`. - Fixes a `jump` bug and a `CALL` test. - Adds gas checks to the tests. - `CALL`'s `code_execution_cost` is still to be implemented (lambdaclass#605). <!-- A clear and concise general description of the changes this PR introduces --> <!-- Link to issues: Resolves lambdaclass#111, Resolves lambdaclass#222 --> Closes lambdaclass#493 and lambdaclass#587. --------- Co-authored-by: Paolo Belforte <[email protected]> Co-authored-by: iinaki <[email protected]>
- Loading branch information
Showing
8 changed files
with
962 additions
and
661 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,84 @@ | ||
pub const SUCCESS_FOR_CALL: i32 = 1; | ||
pub const REVERT_FOR_CALL: i32 = 0; | ||
pub const SUCCESS_FOR_RETURN: i32 = 1; | ||
pub const TX_BASE_COST: u64 = 21_000; | ||
pub const WORD_SIZE: usize = 32; | ||
|
||
/// Contains the gas costs of the EVM instructions | ||
pub mod gas_cost { | ||
pub const ADD: u64 = 3; | ||
pub const MUL: u64 = 5; | ||
pub const SUB: u64 = 3; | ||
pub const DIV: u64 = 5; | ||
pub const SDIV: u64 = 5; | ||
pub const MOD: u64 = 5; | ||
pub const SMOD: u64 = 5; | ||
pub const ADDMOD: u64 = 8; | ||
pub const MULMOD: u64 = 8; | ||
pub const EXP_STATIC: u64 = 10; | ||
pub const EXP_DYNAMIC_BASE: u64 = 50; | ||
pub const SIGNEXTEND: u64 = 5; | ||
pub const LT: u64 = 3; | ||
pub const GT: u64 = 3; | ||
pub const SLT: u64 = 3; | ||
pub const SGT: u64 = 3; | ||
pub const EQ: u64 = 3; | ||
pub const ISZERO: u64 = 3; | ||
pub const AND: u64 = 3; | ||
pub const OR: u64 = 3; | ||
pub const XOR: u64 = 3; | ||
pub const NOT: u64 = 3; | ||
pub const BYTE: u64 = 3; | ||
pub const SHL: u64 = 3; | ||
pub const SHR: u64 = 3; | ||
pub const SAR: u64 = 3; | ||
pub const KECCAK25_STATIC: u64 = 30; | ||
pub const KECCAK25_DYNAMIC_BASE: u64 = 6; | ||
pub const CALLDATALOAD: u64 = 3; | ||
pub const CALLDATASIZE: u64 = 2; | ||
pub const CALLDATACOPY_STATIC: u64 = 3; | ||
pub const CALLDATACOPY_DYNAMIC_BASE: u64 = 3; | ||
pub const RETURNDATASIZE: u64 = 2; | ||
pub const RETURNDATACOPY_STATIC: u64 = 3; | ||
pub const RETURNDATACOPY_DYNAMIC_BASE: u64 = 3; | ||
pub const BLOCKHASH: u64 = 20; | ||
pub const COINBASE: u64 = 2; | ||
pub const TIMESTAMP: u64 = 2; | ||
pub const NUMBER: u64 = 2; | ||
pub const PREVRANDAO: u64 = 2; | ||
pub const GASLIMIT: u64 = 2; | ||
pub const CHAINID: u64 = 2; | ||
pub const SELFBALANCE: u64 = 5; | ||
pub const BASEFEE: u64 = 2; | ||
pub const BLOBHASH: u64 = 3; | ||
pub const BLOBBASEFEE: u64 = 2; | ||
pub const POP: u64 = 2; | ||
pub const MLOAD_STATIC: u64 = 3; | ||
pub const MSTORE_STATIC: u64 = 3; | ||
pub const MSTORE8_STATIC: u64 = 3; | ||
pub const JUMP: u64 = 8; | ||
pub const JUMPI: u64 = 10; | ||
pub const PC: u64 = 2; | ||
pub const MSIZE: u64 = 2; | ||
pub const GAS: u64 = 2; | ||
pub const JUMPDEST: u64 = 1; | ||
pub const TLOAD: u64 = 100; | ||
pub const TSTORE: u64 = 100; | ||
pub const MCOPY_STATIC: u64 = 3; | ||
pub const MCOPY_DYNAMIC_BASE: u64 = 3; | ||
pub const PUSH0: u64 = 2; | ||
pub const PUSHN: u64 = 3; | ||
pub const DUPN: u64 = 3; | ||
pub const SWAPN: u64 = 3; | ||
pub const LOGN_STATIC: u64 = 375; | ||
pub const LOGN_DYNAMIC_BASE: u64 = 375; | ||
pub const LOGN_DYNAMIC_BYTE_BASE: u64 = 8; | ||
} | ||
|
||
pub mod call_opcode { | ||
pub const WARM_ADDRESS_ACCESS_COST: u64 = 100; | ||
pub const COLD_ADDRESS_ACCESS_COST: u64 = 2_600; | ||
pub const NON_ZERO_VALUE_COST: u64 = 9_000; | ||
pub const BASIC_FALLBACK_FUNCTION_STIPEND: u64 = 2_300; | ||
pub const VALUE_TO_EMPTY_ACCOUNT_COST: u64 = 25_000; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.