From ae3aa435be4a861a3c272a541c60c3b44e8f224c Mon Sep 17 00:00:00 2001 From: 5chdn <5chdn@users.noreply.github.com> Date: Sun, 22 Jul 2018 18:31:13 +0200 Subject: [PATCH] ethash: implement EIP-1234 (#9187) --- ethcore/res/ethereum/constantinople_test.json | 6 ++- ethcore/res/ethereum/foundation.json | 6 ++- ethcore/res/ethereum/ropsten.json | 6 ++- ethcore/res/ethereum/transition_test.json | 38 ++++++++++--------- ethcore/src/ethereum/ethash.rs | 24 ++++++++++-- json/src/spec/ethash.rs | 18 +++++++++ 6 files changed, 71 insertions(+), 27 deletions(-) diff --git a/ethcore/res/ethereum/constantinople_test.json b/ethcore/res/ethereum/constantinople_test.json index 9e7df1f7fba..73df56a3207 100644 --- a/ethcore/res/ethereum/constantinople_test.json +++ b/ethcore/res/ethereum/constantinople_test.json @@ -8,9 +8,11 @@ "durationLimit": "0x0d", "blockReward": "0x4563918244F40000", "homesteadTransition": "0x0", - "eip649Reward": "0x29A2241AF62C0000", "eip100bTransition": "0x0", - "eip649Transition": "0x0" + "eip649Transition": "0x0", + "eip649Reward": "0x29A2241AF62C0000", + "eip1234Transition": "0x0", + "eip1234Reward": "0x1BC16D674EC80000" } } }, diff --git a/ethcore/res/ethereum/foundation.json b/ethcore/res/ethereum/foundation.json index 59e8daa8cbd..891cc2dbade 100644 --- a/ethcore/res/ethereum/foundation.json +++ b/ethcore/res/ethereum/foundation.json @@ -129,9 +129,11 @@ "0xbb9bc244d798123fde783fcc1c72d3bb8c189413", "0x807640a13483f8ac783c557fcdf27be11ea4ac7a" ], - "eip649Reward": "0x29A2241AF62C0000", "eip100bTransition": 4370000, - "eip649Transition": 4370000 + "eip649Transition": 4370000, + "eip649Reward": "0x29A2241AF62C0000", + "eip1234Transition": "0x7fffffffffffff", + "eip1234Reward": "0x1BC16D674EC80000" } } }, diff --git a/ethcore/res/ethereum/ropsten.json b/ethcore/res/ethereum/ropsten.json index fd24bbe6d54..1a0d4f36084 100644 --- a/ethcore/res/ethereum/ropsten.json +++ b/ethcore/res/ethereum/ropsten.json @@ -9,9 +9,11 @@ "durationLimit": "0x0d", "blockReward": "0x4563918244F40000", "homesteadTransition": 0, - "eip649Reward": "0x29A2241AF62C0000", "eip100bTransition": 1700000, - "eip649Transition": 1700000 + "eip649Transition": 1700000, + "eip649Reward": "0x29A2241AF62C0000", + "eip1234Transition": "0x7fffffffffffff", + "eip1234Reward": "0x1BC16D674EC80000" } } }, diff --git a/ethcore/res/ethereum/transition_test.json b/ethcore/res/ethereum/transition_test.json index 9dc00fd5d8c..f7b496de6e0 100644 --- a/ethcore/res/ethereum/transition_test.json +++ b/ethcore/res/ethereum/transition_test.json @@ -7,10 +7,12 @@ "difficultyBoundDivisor": "0x0800", "durationLimit": "0x0d", "blockReward": "0x4563918244F40000", - "homesteadTransition": "0", + "homesteadTransition": "0x0", + "eip100bTransition": "0x5", + "eip649Transition": "0x5", "eip649Reward": "0x29A2241AF62C0000", - "eip100bTransition": "5", - "eip649Transition": "5" + "eip1234Transition": "0x0", + "eip1234Reward": "0x1BC16D674EC80000" } } }, @@ -22,17 +24,17 @@ "minGasLimit": "0x1388", "networkID" : "0x1", "maxCodeSize": 24576, - "maxCodeSizeTransition": "0", - "eip150Transition": "0", - "eip160Transition": "0", - "eip161abcTransition": "0", - "eip161dTransition": "0", - "eip98Transition": "5", - "eip140Transition": "5", - "eip211Transition": "5", - "eip214Transition": "5", - "eip155Transition": "5", - "eip658Transition": "5" + "maxCodeSizeTransition": "0x0", + "eip150Transition": "0x0", + "eip160Transition": "0x0", + "eip161abcTransition": "0x0", + "eip161dTransition": "0x0", + "eip98Transition": "0x5", + "eip140Transition": "0x5", + "eip211Transition": "0x5", + "eip214Transition": "0x5", + "eip155Transition": "0x5", + "eip658Transition": "0x5" }, "genesis": { "seal": { @@ -53,9 +55,9 @@ "0000000000000000000000000000000000000002": { "balance": "1", "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } }, "0000000000000000000000000000000000000003": { "balance": "1", "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } }, "0000000000000000000000000000000000000004": { "balance": "1", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } }, - "0000000000000000000000000000000000000005": { "builtin": { "name": "modexp", "activate_at": "5", "pricing": { "modexp": { "divisor": 100 } } } }, - "0000000000000000000000000000000000000006": { "builtin": { "name": "alt_bn128_add", "activate_at": "5", "pricing": { "linear": { "base": 500, "word": 0 } } } }, - "0000000000000000000000000000000000000007": { "builtin": { "name": "alt_bn128_mul", "activate_at": "5", "pricing": { "linear": { "base": 2000, "word": 0 } } } }, - "0000000000000000000000000000000000000008": { "builtin": { "name": "alt_bn128_pairing", "activate_at": "5", "pricing": { "alt_bn128_pairing": { "base": 100000, "pair": 80000 } } } } + "0000000000000000000000000000000000000005": { "builtin": { "name": "modexp", "activate_at": "0x5", "pricing": { "modexp": { "divisor": 100 } } } }, + "0000000000000000000000000000000000000006": { "builtin": { "name": "alt_bn128_add", "activate_at": "0x5", "pricing": { "linear": { "base": 500, "word": 0 } } } }, + "0000000000000000000000000000000000000007": { "builtin": { "name": "alt_bn128_mul", "activate_at": "0x5", "pricing": { "linear": { "base": 2000, "word": 0 } } } }, + "0000000000000000000000000000000000000008": { "builtin": { "name": "alt_bn128_pairing", "activate_at": "0x5", "pricing": { "alt_bn128_pairing": { "base": 100000, "pair": 80000 } } } } } } diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 26151df4416..40ecd6ada8e 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -36,8 +36,9 @@ use machine::EthereumMachine; const SNAPSHOT_BLOCKS: u64 = 5000; /// Maximum number of blocks allowed in an ethash snapshot. const MAX_SNAPSHOT_BLOCKS: u64 = 30000; - +/// Default number of blocks the difficulty bomb is delayed in EIP-{649,1234} const DEFAULT_EIP649_DELAY: u64 = 3_000_000; +const DEFAULT_EIP1234_DELAY: u64 = 3_000_000; /// Ethash specific seal #[derive(Debug, PartialEq)] @@ -120,6 +121,12 @@ pub struct EthashParams { pub eip649_delay: u64, /// EIP-649 base reward. pub eip649_reward: Option, + /// EIP-1234 transition block. + pub eip1234_transition: u64, + /// EIP-1234 bomb delay. + pub eip1234_delay: u64, + /// EIP-1234 base reward. + pub eip1234_reward: Option, /// EXPIP-2 block height pub expip2_transition: u64, /// EXPIP-2 duration limit @@ -152,6 +159,9 @@ impl From for EthashParams { eip649_transition: p.eip649_transition.map_or(u64::max_value(), Into::into), eip649_delay: p.eip649_delay.map_or(DEFAULT_EIP649_DELAY, Into::into), eip649_reward: p.eip649_reward.map(Into::into), + eip1234_transition: p.eip1234_transition.map_or(u64::max_value(), Into::into), + eip1234_delay: p.eip1234_delay.map_or(DEFAULT_EIP1234_DELAY, Into::into), + eip1234_reward: p.eip1234_reward.map(Into::into), expip2_transition: p.expip2_transition.map_or(u64::max_value(), Into::into), expip2_duration_limit: p.expip2_duration_limit.map_or(30, Into::into), } @@ -233,8 +243,10 @@ impl Engine for Arc { let mut rewards = Vec::new(); - // Applies EIP-649 reward. - let reward = if number >= self.ethash_params.eip649_transition { + // Applies EIP-{649,1234} reward, defaults to block_reward. + let reward = if number >= self.ethash_params.eip1234_transition { + self.ethash_params.eip1234_reward.unwrap_or(self.ethash_params.block_reward) + } else if number >= self.ethash_params.eip649_transition { self.ethash_params.eip649_reward.unwrap_or(self.ethash_params.block_reward) } else { self.ethash_params.block_reward @@ -427,6 +439,9 @@ impl Ethash { if header.number() < self.ethash_params.bomb_defuse_transition { if header.number() < self.ethash_params.ecip1010_pause_transition { let mut number = header.number(); + if number >= self.ethash_params.eip1234_transition { + number = number.saturating_sub(self.ethash_params.eip1234_delay); + } if number >= self.ethash_params.eip649_transition { number = number.saturating_sub(self.ethash_params.eip649_delay); } @@ -510,6 +525,9 @@ mod tests { eip649_transition: u64::max_value(), eip649_delay: 3_000_000, eip649_reward: None, + eip1234_transition: u64::max_value(), + eip1234_delay: 3_000_000, + eip1234_reward: None, expip2_transition: u64::max_value(), expip2_duration_limit: 30, } diff --git a/json/src/spec/ethash.rs b/json/src/spec/ethash.rs index fd6b9fca59f..806a940a286 100644 --- a/json/src/spec/ethash.rs +++ b/json/src/spec/ethash.rs @@ -116,6 +116,18 @@ pub struct EthashParams { #[serde(rename="eip649Reward")] pub eip649_reward: Option, + /// EIP-1234 transition block. + #[serde(rename="eip1234Transition")] + pub eip1234_transition: Option, + + /// EIP-1234 bomb delay. + #[serde(rename="eip1234Delay")] + pub eip1234_delay: Option, + + /// EIP-1234 base reward. + #[serde(rename="eip1234Reward")] + pub eip1234_reward: Option, + /// EXPIP-2 block height #[serde(rename="expip2Transition")] pub expip2_transition: Option, @@ -231,6 +243,9 @@ mod tests { eip649_transition: None, eip649_delay: None, eip649_reward: None, + eip1234_transition: None, + eip1234_delay: None, + eip1234_reward: None, expip2_transition: None, expip2_duration_limit: None, } @@ -275,6 +290,9 @@ mod tests { eip649_transition: None, eip649_delay: None, eip649_reward: None, + eip1234_transition: None, + eip1234_delay: None, + eip1234_reward: None, expip2_transition: None, expip2_duration_limit: None, }