From 780cf0ce1a638a0ad998341920c0d33b1a12d8eb Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 11 Nov 2016 11:56:58 +0100 Subject: [PATCH 1/6] Restrict max code size to 23999 bytes for EIP-150 and after. Former-commit-id: 379c1e17d6740be225ed99bad73732330bd9c10a --- ethcore/src/client/test_client.rs | 2 +- ethcore/src/ethereum/ethash.rs | 12 ++++++++---- ethcore/src/evm/schedule.rs | 6 +++++- ethcore/src/externalities.rs | 2 +- json/src/spec/ethash.rs | 4 ++++ 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 434edd3e8..3a9fa33d6 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -315,7 +315,7 @@ pub fn get_temp_state_db() -> GuardedTempResult { impl MiningBlockChainClient for TestBlockChainClient { fn latest_schedule(&self) -> Schedule { - Schedule::new_post_eip150(true, true, true) + Schedule::new_post_eip150(23999, true, true, true) } fn prepare_open_block(&self, author: Address, gas_range_target: (U256, U256), extra_data: Bytes) -> OpenBlock { diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index f2468dc95..8a1a497bd 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -70,6 +70,8 @@ pub struct EthashParams { pub eip161abc_transition: u64, /// Number of first block where EIP-161.d begins. pub eip161d_transition: u64, + /// Maximum amount of code that can be deploying into a contract. + pub max_code_size: u64, } impl From for EthashParams { @@ -83,17 +85,18 @@ impl From for EthashParams { block_reward: p.block_reward.into(), registrar: p.registrar.map_or_else(Address::new, Into::into), homestead_transition: p.homestead_transition.map_or(0, Into::into), - dao_hardfork_transition: p.dao_hardfork_transition.map_or(0x7fffffffffffffff, Into::into), + dao_hardfork_transition: p.dao_hardfork_transition.map_or(u64::max_value(), Into::into), dao_hardfork_beneficiary: p.dao_hardfork_beneficiary.map_or_else(Address::new, Into::into), dao_hardfork_accounts: p.dao_hardfork_accounts.unwrap_or_else(Vec::new).into_iter().map(Into::into).collect(), - difficulty_hardfork_transition: p.difficulty_hardfork_transition.map_or(0x7fffffffffffffff, Into::into), + difficulty_hardfork_transition: p.difficulty_hardfork_transition.map_or(u64::max_value(), Into::into), difficulty_hardfork_bound_divisor: p.difficulty_hardfork_bound_divisor.map_or(p.difficulty_bound_divisor.into(), Into::into), - bomb_defuse_transition: p.bomb_defuse_transition.map_or(0x7fffffffffffffff, Into::into), + bomb_defuse_transition: p.bomb_defuse_transition.map_or(u64::max_value(), Into::into), eip150_transition: p.eip150_transition.map_or(0, Into::into), eip155_transition: p.eip155_transition.map_or(0, Into::into), eip160_transition: p.eip160_transition.map_or(0, Into::into), eip161abc_transition: p.eip161abc_transition.map_or(0, Into::into), - eip161d_transition: p.eip161d_transition.map_or(0x7fffffffffffffff, Into::into), + eip161d_transition: p.eip161d_transition.map_or(u64::max_value(), Into::into), + max_code_size: p.max_code_size.map_or(u64::max_value(), Into::into), } } } @@ -146,6 +149,7 @@ impl Engine for Ethash { Schedule::new_homestead() } else { Schedule::new_post_eip150( + self.ethash_params.max_code_size as usize, env_info.number >= self.ethash_params.eip160_transition, env_info.number >= self.ethash_params.eip161abc_transition, env_info.number >= self.ethash_params.eip161d_transition diff --git a/ethcore/src/evm/schedule.rs b/ethcore/src/evm/schedule.rs index b68f6acb5..773708956 100644 --- a/ethcore/src/evm/schedule.rs +++ b/ethcore/src/evm/schedule.rs @@ -70,6 +70,8 @@ pub struct Schedule { pub quad_coeff_div: usize, /// Cost for contract length when executing `CREATE` pub create_data_gas: usize, + /// Maximum code size when creating a contract. + pub create_data_limit: usize, /// Transaction cost pub tx_gas: usize, /// `CREATE` transaction cost @@ -111,7 +113,7 @@ impl Schedule { } /// Schedule for the post-EIP-150-era of the Ethereum main net. - pub fn new_post_eip150(fix_exp: bool, no_empty: bool, kill_empty: bool) -> Schedule { + pub fn new_post_eip150(max_code_size: usize, fix_exp: bool, no_empty: bool, kill_empty: bool) -> Schedule { Schedule { exceptional_failed_code_deposit: true, have_delegate_call: true, @@ -139,6 +141,7 @@ impl Schedule { memory_gas: 3, quad_coeff_div: 512, create_data_gas: 200, + create_data_limit: max_code_size, tx_gas: 21000, tx_create_gas: 53000, tx_data_zero_gas: 4, @@ -183,6 +186,7 @@ impl Schedule { memory_gas: 3, quad_coeff_div: 512, create_data_gas: 200, + create_data_limit: usize::max_value(), tx_gas: 21000, tx_create_gas: tcg, tx_data_zero_gas: 4, diff --git a/ethcore/src/externalities.rs b/ethcore/src/externalities.rs index df1b64e67..3704ead67 100644 --- a/ethcore/src/externalities.rs +++ b/ethcore/src/externalities.rs @@ -242,7 +242,7 @@ impl<'a, T, V> Ext for Externalities<'a, T, V> where T: 'a + Tracer, V: 'a + VMT }, OutputPolicy::InitContract(ref mut copy) => { let return_cost = U256::from(data.len()) * U256::from(self.schedule.create_data_gas); - if return_cost > *gas { + if return_cost > *gas || data.len() > self.schedule.create_data_limit { return match self.schedule.exceptional_failed_code_deposit { true => Err(evm::Error::OutOfGas), false => Ok(*gas) diff --git a/json/src/spec/ethash.rs b/json/src/spec/ethash.rs index f8412bb97..812d7708e 100644 --- a/json/src/spec/ethash.rs +++ b/json/src/spec/ethash.rs @@ -85,6 +85,10 @@ pub struct EthashParams { /// See main EthashParams docs. #[serde(rename="eip161dTransition")] pub eip161d_transition: Option, + + /// See main EthashParams docs. + #[serde(rename="maxCodeSize")] + pub max_code_size: Option, } /// Ethash engine deserialization. From 0b2eb3a4c35a99bfd2200195997d688e25f05dba Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 11 Nov 2016 12:24:14 +0100 Subject: [PATCH 2/6] Introduce the actual max code size. Former-commit-id: c87dec7ec4ec4798ce00fb18f798fb762df04954 --- ethcore/res/ethereum/frontier.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ethcore/res/ethereum/frontier.json b/ethcore/res/ethereum/frontier.json index be473237c..399722a2c 100644 --- a/ethcore/res/ethereum/frontier.json +++ b/ethcore/res/ethereum/frontier.json @@ -134,7 +134,8 @@ "eip155Transition": "0x7fffffffffffffff", "eip160Transition": "0x7fffffffffffffff", "eip161abcTransition": "0x7fffffffffffffff", - "eip161dTransition": "0x7fffffffffffffff" + "eip161dTransition": "0x7fffffffffffffff", + "maxCodeSize": 23999 } } }, From b007c7225fa6d141cf09ed0fe88c0b7fac1df5bc Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 14 Nov 2016 11:51:23 +0100 Subject: [PATCH 3/6] Update max code size. Former-commit-id: 54bae3d00fab74f17767cef6d95ee52271d9486e --- ethcore/res/ethereum/frontier.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethcore/res/ethereum/frontier.json b/ethcore/res/ethereum/frontier.json index 399722a2c..b951973f8 100644 --- a/ethcore/res/ethereum/frontier.json +++ b/ethcore/res/ethereum/frontier.json @@ -135,7 +135,7 @@ "eip160Transition": "0x7fffffffffffffff", "eip161abcTransition": "0x7fffffffffffffff", "eip161dTransition": "0x7fffffffffffffff", - "maxCodeSize": 23999 + "maxCodeSize": 24576 } } }, From f91c3d9d62228dee2106c27f08697ea09c368e63 Mon Sep 17 00:00:00 2001 From: arkpar Date: Tue, 15 Nov 2016 19:46:25 +0100 Subject: [PATCH 4/6] fixed test Former-commit-id: 702d0066c7ed9ef019620e4f00e690c1cd730f91 --- ethcore/src/engines/instant_seal.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethcore/src/engines/instant_seal.rs b/ethcore/src/engines/instant_seal.rs index acead19b4..5d64814b7 100644 --- a/ethcore/src/engines/instant_seal.rs +++ b/ethcore/src/engines/instant_seal.rs @@ -55,7 +55,7 @@ impl Engine for InstantSeal { } fn schedule(&self, _env_info: &EnvInfo) -> Schedule { - Schedule::new_homestead() + Schedule::new_post_eip150(usize::max_value(), false, false, false) } fn is_sealer(&self, _author: &Address) -> Option { Some(true) } From f3693a0a4355d0cadb34e10e547566028d44b6ce Mon Sep 17 00:00:00 2001 From: Arkadiy Paronyan Date: Tue, 15 Nov 2016 19:48:15 +0100 Subject: [PATCH 5/6] Update test client with max code size Former-commit-id: 36244abbe86c4620fbfd258a382be819cae4145c --- ethcore/src/client/test_client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 3a9fa33d6..ea220fb1c 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -315,7 +315,7 @@ pub fn get_temp_state_db() -> GuardedTempResult { impl MiningBlockChainClient for TestBlockChainClient { fn latest_schedule(&self) -> Schedule { - Schedule::new_post_eip150(23999, true, true, true) + Schedule::new_post_eip150(24576, true, true, true) } fn prepare_open_block(&self, author: Address, gas_range_target: (U256, U256), extra_data: Bytes) -> OpenBlock { From 69d32b884ffada0935308eef75ef48bd53ccd27a Mon Sep 17 00:00:00 2001 From: arkpar Date: Tue, 15 Nov 2016 21:46:05 +0100 Subject: [PATCH 6/6] Set HF block number Former-commit-id: 5496abf21b140eb75842f6f87a3c56b0f0433876 --- ethcore/res/ethereum/frontier.json | 8 ++++---- ethcore/res/ethereum/morden.json | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ethcore/res/ethereum/frontier.json b/ethcore/res/ethereum/frontier.json index b951973f8..9bb9c50ff 100644 --- a/ethcore/res/ethereum/frontier.json +++ b/ethcore/res/ethereum/frontier.json @@ -131,10 +131,10 @@ "0x807640a13483f8ac783c557fcdf27be11ea4ac7a" ], "eip150Transition": "0x259518", - "eip155Transition": "0x7fffffffffffffff", - "eip160Transition": "0x7fffffffffffffff", - "eip161abcTransition": "0x7fffffffffffffff", - "eip161dTransition": "0x7fffffffffffffff", + "eip155Transition": 2675000, + "eip160Transition": 2675000, + "eip161abcTransition": 2675000, + "eip161dTransition": 2675000, "maxCodeSize": 24576 } } diff --git a/ethcore/res/ethereum/morden.json b/ethcore/res/ethereum/morden.json index 9d54169c3..6e725e8bf 100644 --- a/ethcore/res/ethereum/morden.json +++ b/ethcore/res/ethereum/morden.json @@ -11,10 +11,10 @@ "registrar": "0x52dff57a8a1532e6afb3dc07e2af58bb9eb05b3d", "homesteadTransition": "0x789b0", "eip150Transition": "0x1b34d8", - "eip155Transition": "0x7fffffffffffffff", - "eip160Transition": "0x7fffffffffffffff", - "eip161abcTransition": "0x7fffffffffffffff", - "eip161dTransition": "0x7fffffffffffffff" + "eip155Transition": 1885000, + "eip160Transition": 1885000, + "eip161abcTransition": 1885000, + "eip161dTransition": 1885000 } } },