EIP-86 fixes (#5506)

This commit is contained in:
Arkadiy Paronyan
2017-05-05 16:00:40 +02:00
committed by Gav Wood
parent 8b9adb4d74
commit ed7c366b90
9 changed files with 32 additions and 26 deletions

View File

@@ -278,7 +278,7 @@ lazy_static! {
arr[RETURN as usize] = InstructionInfo::new("RETURN", 0, 2, 0, true, GasPriceTier::Zero);
arr[DELEGATECALL as usize] = InstructionInfo::new("DELEGATECALL", 0, 6, 1, true, GasPriceTier::Special);
arr[SUICIDE as usize] = InstructionInfo::new("SUICIDE", 0, 1, 0, true, GasPriceTier::Special);
arr[CREATE_P2SH as usize] = InstructionInfo::new("CREATE_P2SH", 0, 3, 1, true, GasPriceTier::Special);
arr[CREATE2 as usize] = InstructionInfo::new("CREATE2", 0, 3, 1, true, GasPriceTier::Special);
arr
};
}
@@ -555,7 +555,7 @@ pub const RETURN: Instruction = 0xf3;
/// like CALLCODE but keeps caller's value and sender
pub const DELEGATECALL: Instruction = 0xf4;
/// create a new account and set creation address to sha3(sender + sha3(init code)) % 2**160
pub const CREATE_P2SH: Instruction = 0xfb;
pub const CREATE2: Instruction = 0xfb;
/// halt execution and register account for later deletion
pub const SUICIDE: Instruction = 0xff;

View File

@@ -223,7 +223,7 @@ impl<Gas: CostType> Gasometer<Gas> {
Request::GasMemProvide(gas, mem, Some(requested))
},
instructions::CREATE | instructions::CREATE_P2SH => {
instructions::CREATE | instructions::CREATE2 => {
let gas = Gas::from(schedule.create_gas);
let mem = mem_needed(stack.peek(1), stack.peek(2))?;

View File

@@ -183,7 +183,7 @@ impl<Cost: CostType> Interpreter<Cost> {
let schedule = ext.schedule();
if (instruction == instructions::DELEGATECALL && !schedule.have_delegate_call) ||
(instruction == instructions::CREATE_P2SH && !schedule.have_create_p2sh) {
(instruction == instructions::CREATE2 && !schedule.have_create2) {
return Err(evm::Error::BadInstruction {
instruction: instruction
@@ -268,12 +268,12 @@ impl<Cost: CostType> Interpreter<Cost> {
instructions::JUMPDEST => {
// ignore
},
instructions::CREATE | instructions::CREATE_P2SH => {
instructions::CREATE | instructions::CREATE2 => {
let endowment = stack.pop_back();
let init_off = stack.pop_back();
let init_size = stack.pop_back();
let address_scheme = if instruction == instructions::CREATE { ext.schedule().create_address } else { CreateContractAddress::FromSenderAndCodeHash };
let address_scheme = if instruction == instructions::CREATE { CreateContractAddress::FromSenderAndNonce } else { CreateContractAddress::FromSenderAndCodeHash };
let create_gas = provided.expect("`provided` comes through Self::exec from `Gasometer::get_gas_cost_mem`; `gas_gas_mem_cost` guarantees `Some` when instruction is `CALL`/`CALLCODE`/`DELEGATECALL`/`CREATE`; this is `CREATE`; qed");
let contract_code = self.mem.read_slice(init_off, init_size);

View File

@@ -15,7 +15,6 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Cost schedule and other parameterisations for the EVM.
use evm::CreateContractAddress;
/// Definition of the cost schedule and other parameterisations for the EVM.
pub struct Schedule {
@@ -24,7 +23,7 @@ pub struct Schedule {
/// Does it have a delegate cal
pub have_delegate_call: bool,
/// Does it have a CREATE_P2SH instruction
pub have_create_p2sh: bool,
pub have_create2: bool,
/// VM stack limit
pub stack_limit: usize,
/// Max number of nested calls/creates
@@ -102,8 +101,6 @@ pub struct Schedule {
pub no_empty: bool,
/// Kill empty accounts if touched.
pub kill_empty: bool,
/// Contract address generation scheme
pub create_address: CreateContractAddress,
}
impl Schedule {
@@ -118,11 +115,11 @@ impl Schedule {
}
/// Schedule for the post-EIP-150-era of the Ethereum main net.
pub fn new_post_eip150(max_code_size: usize, fix_exp: bool, no_empty: bool, kill_empty: bool, have_create_p2sh: bool) -> Schedule {
pub fn new_post_eip150(max_code_size: usize, fix_exp: bool, no_empty: bool, kill_empty: bool, have_metropolis_instructions: bool) -> Schedule {
Schedule {
exceptional_failed_code_deposit: true,
have_delegate_call: true,
have_create_p2sh: have_create_p2sh,
have_create2: have_metropolis_instructions,
stack_limit: 1024,
max_depth: 1024,
tier_step_gas: [0, 2, 3, 5, 8, 10, 20, 0],
@@ -161,7 +158,6 @@ impl Schedule {
sub_gas_cap_divisor: Some(64),
no_empty: no_empty,
kill_empty: kill_empty,
create_address: if have_create_p2sh { CreateContractAddress::FromCodeHash } else { CreateContractAddress::FromSenderAndNonce },
}
}
@@ -174,7 +170,7 @@ impl Schedule {
Schedule {
exceptional_failed_code_deposit: efcd,
have_delegate_call: hdc,
have_create_p2sh: false,
have_create2: false,
stack_limit: 1024,
max_depth: 1024,
tier_step_gas: [0, 2, 3, 5, 8, 10, 20, 0],
@@ -213,7 +209,6 @@ impl Schedule {
sub_gas_cap_divisor: None,
no_empty: false,
kill_empty: false,
create_address: CreateContractAddress::FromSenderAndNonce,
}
}
}