Add wasmDisableTransition spec option (#60)

* Add wasmDisableTransition spec option
This commit is contained in:
varasev 2020-10-08 23:37:48 +03:00 committed by draganrakita
parent 6ecc6ddcdf
commit a95b2de645
4 changed files with 48 additions and 6 deletions

View File

@ -42,7 +42,8 @@
"eip211Transition": 5067000, "eip211Transition": 5067000,
"eip214Transition": 5067000, "eip214Transition": 5067000,
"eip658Transition": 5067000, "eip658Transition": 5067000,
"wasmActivationTransition": 10 "wasmActivationTransition": 10,
"wasmDisableTransition": 200
}, },
"genesis": { "genesis": {
"seal": { "seal": {

View File

@ -2919,7 +2919,7 @@ mod tests {
let mut info = EnvInfo::default(); let mut info = EnvInfo::default();
// 100 > 10 // 200 (wasmDisableTransition) > 100 > 10 (wasmActivationTransition)
info.number = 100; info.number = 100;
// Network with wasm activated at block 10 // Network with wasm activated at block 10
@ -2947,9 +2947,35 @@ mod tests {
// Transaction successfully returned sender // Transaction successfully returned sender
assert_eq!(output[..], sender[..]); assert_eq!(output[..], sender[..]);
// 1 < 10 // 1 < 10 (wasmActivationTransition)
info.number = 1; info.number = 1;
let mut output = [0u8; 20];
let FinalizationResult {
gas_left: result,
return_data,
..
} = {
let schedule = machine.schedule(info.number);
let mut ex = Executive::new(&mut state, &info, &machine, &schedule);
ex.call(
params.clone(),
&mut Substate::new(),
&mut NoopTracer,
&mut NoopVMTracer,
)
.unwrap()
};
(&mut output[..(cmp::min(20, return_data.len()))])
.copy_from_slice(&return_data[..(cmp::min(20, return_data.len()))]);
assert_eq!(result, U256::from(20025));
// Since transaction errored due to wasm was not activated, result is just empty
assert_eq!(output[..], [0u8; 20][..]);
// 200 == wasmDisableTransition
info.number = 200;
let mut output = [0u8; 20]; let mut output = [0u8; 20];
let FinalizationResult { let FinalizationResult {
gas_left: result, gas_left: result,
@ -2970,7 +2996,7 @@ mod tests {
.copy_from_slice(&return_data[..(cmp::min(20, return_data.len()))]); .copy_from_slice(&return_data[..(cmp::min(20, return_data.len()))]);
assert_eq!(result, U256::from(20025)); assert_eq!(result, U256::from(20025));
// Since transaction errored due to wasm was not activated, result is just empty // Since transaction errored due to wasm was deactivated, result is just empty
assert_eq!(output[..], [0u8; 20][..]); assert_eq!(output[..], [0u8; 20][..]);
} }
} }

View File

@ -143,6 +143,8 @@ pub struct CommonParams {
pub remove_dust_contracts: bool, pub remove_dust_contracts: bool,
/// Wasm activation blocknumber, if any disabled initially. /// Wasm activation blocknumber, if any disabled initially.
pub wasm_activation_transition: BlockNumber, pub wasm_activation_transition: BlockNumber,
/// Wasm deactivation blocknumber, if enabled.
pub wasm_disable_transition: BlockNumber,
/// Number of first block where KIP-4 rules begin. Only has effect if Wasm is activated. /// Number of first block where KIP-4 rules begin. Only has effect if Wasm is activated.
pub kip4_transition: BlockNumber, pub kip4_transition: BlockNumber,
/// Number of first block where KIP-6 rules begin. Only has effect if Wasm is activated. /// Number of first block where KIP-6 rules begin. Only has effect if Wasm is activated.
@ -226,7 +228,9 @@ impl CommonParams {
false => ::vm::CleanDustMode::BasicOnly, false => ::vm::CleanDustMode::BasicOnly,
}; };
} }
if block_number >= self.wasm_activation_transition { if block_number >= self.wasm_activation_transition
&& block_number < self.wasm_disable_transition
{
let mut wasm = ::vm::WasmCosts::default(); let mut wasm = ::vm::WasmCosts::default();
if block_number >= self.kip4_transition { if block_number >= self.kip4_transition {
wasm.have_create2 = true; wasm.have_create2 = true;
@ -362,6 +366,9 @@ impl From<ethjson::spec::Params> for CommonParams {
wasm_activation_transition: p wasm_activation_transition: p
.wasm_activation_transition .wasm_activation_transition
.map_or_else(BlockNumber::max_value, Into::into), .map_or_else(BlockNumber::max_value, Into::into),
wasm_disable_transition: p
.wasm_disable_transition
.map_or_else(BlockNumber::max_value, Into::into),
kip4_transition: p kip4_transition: p
.kip4_transition .kip4_transition
.map_or_else(BlockNumber::max_value, Into::into), .map_or_else(BlockNumber::max_value, Into::into),
@ -628,6 +635,7 @@ impl Spec {
params.eip2315_transition, params.eip2315_transition,
params.dust_protection_transition, params.dust_protection_transition,
params.wasm_activation_transition, params.wasm_activation_transition,
params.wasm_disable_transition,
params.kip4_transition, params.kip4_transition,
params.kip6_transition, params.kip6_transition,
params.max_code_size_transition, params.max_code_size_transition,

View File

@ -132,6 +132,8 @@ pub struct Params {
pub transaction_permission_contract_transition: Option<Uint>, pub transaction_permission_contract_transition: Option<Uint>,
/// Wasm activation block height, if not activated from start /// Wasm activation block height, if not activated from start
pub wasm_activation_transition: Option<Uint>, pub wasm_activation_transition: Option<Uint>,
/// Wasm deactivation block height, if activated.
pub wasm_disable_transition: Option<Uint>,
/// KIP4 activiation block height. /// KIP4 activiation block height.
pub kip4_transition: Option<Uint>, pub kip4_transition: Option<Uint>,
/// KIP6 activiation block height. /// KIP6 activiation block height.
@ -156,7 +158,8 @@ mod tests {
"accountStartNonce": "0x01", "accountStartNonce": "0x01",
"gasLimitBoundDivisor": "0x20", "gasLimitBoundDivisor": "0x20",
"maxCodeSize": "0x1000", "maxCodeSize": "0x1000",
"wasmActivationTransition": "0x1010" "wasmActivationTransition": "0x1010",
"wasmDisableTransition": "0x2010"
}"#; }"#;
let deserialized: Params = serde_json::from_str(s).unwrap(); let deserialized: Params = serde_json::from_str(s).unwrap();
@ -175,6 +178,10 @@ mod tests {
deserialized.wasm_activation_transition, deserialized.wasm_activation_transition,
Some(Uint(U256::from(0x1010))) Some(Uint(U256::from(0x1010)))
); );
assert_eq!(
deserialized.wasm_disable_transition,
Some(Uint(U256::from(0x2010)))
);
} }
#[test] #[test]