openethereum/ethcore/src/evm/schedule.rs

132 lines
4.1 KiB
Rust
Raw Normal View History

2016-02-05 13:40:41 +01:00
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
2016-01-11 19:25:37 +01:00
//! Cost schedule and other parameterisations for the EVM.
/// Definition of the cost schedule and other parameterisations for the EVM.
2016-01-11 16:28:30 +01:00
pub struct Schedule {
2016-01-26 10:48:33 +01:00
/// Does it support exceptional failed code deposit
pub exceptional_failed_code_deposit: bool,
2016-01-26 10:48:33 +01:00
/// Does it have a delegate cal
pub have_delegate_call: bool,
2016-01-26 10:48:33 +01:00
/// VM stack limit
pub stack_limit: usize,
2016-01-26 10:48:33 +01:00
/// Max number of nested calls/creates
2016-01-14 01:40:55 +01:00
pub max_depth: usize,
2016-01-26 10:48:33 +01:00
/// Gas prices for instructions in all tiers
pub tier_step_gas: [usize; 8],
2016-01-26 10:48:33 +01:00
/// Gas price for `EXP` opcode
pub exp_gas: usize,
2016-01-26 10:48:33 +01:00
/// Additional gas for `EXP` opcode for each byte of exponent
pub exp_byte_gas: usize,
2016-01-26 10:48:33 +01:00
/// Gas price for `SHA3` opcode
pub sha3_gas: usize,
2016-01-26 10:48:33 +01:00
/// Additional gas for `SHA3` opcode for each word of hashed memory
pub sha3_word_gas: usize,
2016-01-26 10:48:33 +01:00
/// Gas price for loading from storage
pub sload_gas: usize,
2016-01-26 10:48:33 +01:00
/// Gas price for setting new value to storage (`storage==0`, `new!=0`)
pub sstore_set_gas: usize,
2016-01-26 10:48:33 +01:00
/// Gas price for altering value in storage
pub sstore_reset_gas: usize,
2016-01-26 10:48:33 +01:00
/// Gas refund for `SSTORE` clearing (when `storage!=0`, `new==0`)
pub sstore_refund_gas: usize,
2016-01-26 10:48:33 +01:00
/// Gas price for `JUMPDEST` opcode
pub jumpdest_gas: usize,
2016-01-26 10:48:33 +01:00
/// Gas price for `LOG*`
pub log_gas: usize,
2016-01-26 10:48:33 +01:00
/// Additional gas for data in `LOG*`
pub log_data_gas: usize,
2016-01-26 10:48:33 +01:00
/// Additional gas for each topic in `LOG*`
pub log_topic_gas: usize,
2016-01-26 10:48:33 +01:00
/// Gas price for `CREATE` opcode
pub create_gas: usize,
2016-01-26 10:48:33 +01:00
/// Gas price for `*CALL*` opcodes
pub call_gas: usize,
2016-01-26 10:48:33 +01:00
/// Stipend for transfer for `CALL|CALLCODE` opcode when `value>0`
pub call_stipend: usize,
2016-01-26 10:48:33 +01:00
/// Additional gas required for value transfer (`CALL|CALLCODE`)
pub call_value_transfer_gas: usize,
2016-01-26 10:48:33 +01:00
/// Additional gas for creating new account (`CALL|CALLCODE`)
pub call_new_account_gas: usize,
2016-01-26 10:48:33 +01:00
/// Refund for SUICIDE
pub suicide_refund_gas: usize,
2016-01-26 10:48:33 +01:00
/// Gas for used memory
pub memory_gas: usize,
2016-01-26 10:48:33 +01:00
/// Coefficient used to convert memory size to gas price for memory
pub quad_coeff_div: usize,
2016-01-26 10:48:33 +01:00
/// Cost for contract length when executing `CREATE`
pub create_data_gas: usize,
2016-01-26 10:48:33 +01:00
/// Transaction cost
pub tx_gas: usize,
2016-01-26 10:48:33 +01:00
/// `CREATE` transaction cost
pub tx_create_gas: usize,
2016-01-26 10:48:33 +01:00
/// Additional cost for empty data transaction
pub tx_data_zero_gas: usize,
2016-01-26 10:48:33 +01:00
/// Aditional cost for non-empty data transaction
pub tx_data_non_zero_gas: usize,
2016-01-26 10:48:33 +01:00
/// Gas price for copying memory
pub copy_gas: usize,
}
2016-01-11 16:28:30 +01:00
impl Schedule {
/// Schedule for the Frontier-era of the Ethereum main net.
2016-01-11 16:28:30 +01:00
pub fn new_frontier() -> Schedule {
Self::new(false, false, 21000)
}
/// Schedule for the Homestead-era of the Ethereum main net.
2016-01-11 16:28:30 +01:00
pub fn new_homestead() -> Schedule {
Self::new(true, true, 53000)
}
2016-01-11 16:28:30 +01:00
fn new(efcd: bool, hdc: bool, tcg: usize) -> Schedule {
Schedule{
exceptional_failed_code_deposit: efcd,
have_delegate_call: hdc,
stack_limit: 1024,
2016-01-14 01:40:55 +01:00
max_depth: 1024,
2016-01-13 23:53:00 +01:00
tier_step_gas: [0, 2, 3, 5, 8, 10, 20, 0],
exp_gas: 10,
exp_byte_gas: 10,
sha3_gas: 30,
sha3_word_gas: 6,
sload_gas: 50,
sstore_set_gas: 20000,
sstore_reset_gas: 5000,
sstore_refund_gas: 15000,
jumpdest_gas: 1,
log_gas: 375,
log_data_gas: 8,
log_topic_gas: 375,
create_gas: 32000,
call_gas: 40,
call_stipend: 2300,
call_value_transfer_gas: 9000,
call_new_account_gas: 25000,
suicide_refund_gas: 24000,
memory_gas: 3,
quad_coeff_div: 512,
create_data_gas: 200,
tx_gas: 21000,
tx_create_gas: tcg,
tx_data_zero_gas: 4,
tx_data_non_zero_gas: 68,
copy_gas: 3,
}
}
2016-01-11 19:25:37 +01:00
}