Comply EIP-86 with the new definition (#9140)
* Comply EIP-86 with the new CREATE2 opcode * Fix rpc compile * Fix interpreter CREATE/CREATE2 stack pop difference * Add unreachable! to fix compile * Fix instruction_info * Fix gas check due to new stack item * Add new tests in executive * Fix have_create2 comment * Remove all unused references of eip86_transition and block_number
This commit is contained in:
@@ -61,10 +61,12 @@ pub fn contract_address(address_scheme: CreateContractAddress, sender: &Address,
|
||||
stream.append(nonce);
|
||||
(From::from(keccak(stream.as_raw())), None)
|
||||
},
|
||||
CreateContractAddress::FromCodeHash => {
|
||||
CreateContractAddress::FromSenderSaltAndCodeHash(salt) => {
|
||||
let code_hash = keccak(code);
|
||||
let mut buffer = [0xffu8; 20 + 32];
|
||||
&mut buffer[20..].copy_from_slice(&code_hash[..]);
|
||||
let mut buffer = [0u8; 20 + 32 + 32];
|
||||
&mut buffer[0..20].copy_from_slice(&sender[..]);
|
||||
&mut buffer[20..(20+32)].copy_from_slice(&salt[..]);
|
||||
&mut buffer[(20+32)..].copy_from_slice(&code_hash[..]);
|
||||
(From::from(keccak(&buffer[..])), Some(code_hash))
|
||||
},
|
||||
CreateContractAddress::FromSenderAndCodeHash => {
|
||||
|
||||
@@ -581,4 +581,44 @@ mod tests {
|
||||
|
||||
assert_eq!(setup.sub_state.suicides.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_create() {
|
||||
use std::str::FromStr;
|
||||
|
||||
let mut setup = TestSetup::new();
|
||||
let state = &mut setup.state;
|
||||
let mut tracer = NoopTracer;
|
||||
let mut vm_tracer = NoopVMTracer;
|
||||
|
||||
let address = {
|
||||
let mut ext = Externalities::new(state, &setup.env_info, &setup.machine, 0, get_test_origin(), &mut setup.sub_state, OutputPolicy::InitContract(None), &mut tracer, &mut vm_tracer, false);
|
||||
match ext.create(&U256::max_value(), &U256::zero(), &[], CreateContractAddress::FromSenderAndNonce) {
|
||||
ContractCreateResult::Created(address, _) => address,
|
||||
_ => panic!("Test create failed; expected Created, got Failed/Reverted."),
|
||||
}
|
||||
};
|
||||
|
||||
assert_eq!(address, Address::from_str("bd770416a3345f91e4b34576cb804a576fa48eb1").unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_create2() {
|
||||
use std::str::FromStr;
|
||||
|
||||
let mut setup = TestSetup::new();
|
||||
let state = &mut setup.state;
|
||||
let mut tracer = NoopTracer;
|
||||
let mut vm_tracer = NoopVMTracer;
|
||||
|
||||
let address = {
|
||||
let mut ext = Externalities::new(state, &setup.env_info, &setup.machine, 0, get_test_origin(), &mut setup.sub_state, OutputPolicy::InitContract(None), &mut tracer, &mut vm_tracer, false);
|
||||
match ext.create(&U256::max_value(), &U256::zero(), &[], CreateContractAddress::FromSenderSaltAndCodeHash(H256::default())) {
|
||||
ContractCreateResult::Created(address, _) => address,
|
||||
_ => panic!("Test create failed; expected Created, got Failed/Reverted."),
|
||||
}
|
||||
};
|
||||
|
||||
assert_eq!(address, Address::from_str("b7c227636666831278bacdb8d7f52933b8698ab9").unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,12 +310,8 @@ impl EthereumMachine {
|
||||
}
|
||||
|
||||
/// Returns new contract address generation scheme at given block number.
|
||||
pub fn create_address_scheme(&self, number: BlockNumber) -> CreateContractAddress {
|
||||
if number >= self.params().eip86_transition {
|
||||
CreateContractAddress::FromCodeHash
|
||||
} else {
|
||||
CreateContractAddress::FromSenderAndNonce
|
||||
}
|
||||
pub fn create_address_scheme(&self, _number: BlockNumber) -> CreateContractAddress {
|
||||
CreateContractAddress::FromSenderAndNonce
|
||||
}
|
||||
|
||||
/// Verify a particular transaction is valid, regardless of order.
|
||||
|
||||
Reference in New Issue
Block a user