Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
ethash: implement EIP-1234 (#9187)
Browse files Browse the repository at this point in the history
  • Loading branch information
5chdn authored and andresilva committed Oct 9, 2018
1 parent 5977ea7 commit ae3aa43
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 27 deletions.
6 changes: 4 additions & 2 deletions ethcore/res/ethereum/constantinople_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000",
"homesteadTransition": "0x0",
"eip649Reward": "0x29A2241AF62C0000",
"eip100bTransition": "0x0",
"eip649Transition": "0x0"
"eip649Transition": "0x0",
"eip649Reward": "0x29A2241AF62C0000",
"eip1234Transition": "0x0",
"eip1234Reward": "0x1BC16D674EC80000"
}
}
},
Expand Down
6 changes: 4 additions & 2 deletions ethcore/res/ethereum/foundation.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@
"0xbb9bc244d798123fde783fcc1c72d3bb8c189413",
"0x807640a13483f8ac783c557fcdf27be11ea4ac7a"
],
"eip649Reward": "0x29A2241AF62C0000",
"eip100bTransition": 4370000,
"eip649Transition": 4370000
"eip649Transition": 4370000,
"eip649Reward": "0x29A2241AF62C0000",
"eip1234Transition": "0x7fffffffffffff",
"eip1234Reward": "0x1BC16D674EC80000"
}
}
},
Expand Down
6 changes: 4 additions & 2 deletions ethcore/res/ethereum/ropsten.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000",
"homesteadTransition": 0,
"eip649Reward": "0x29A2241AF62C0000",
"eip100bTransition": 1700000,
"eip649Transition": 1700000
"eip649Transition": 1700000,
"eip649Reward": "0x29A2241AF62C0000",
"eip1234Transition": "0x7fffffffffffff",
"eip1234Reward": "0x1BC16D674EC80000"
}
}
},
Expand Down
38 changes: 20 additions & 18 deletions ethcore/res/ethereum/transition_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
},
Expand All @@ -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": {
Expand All @@ -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 } } } }
}
}
24 changes: 21 additions & 3 deletions ethcore/src/ethereum/ethash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -120,6 +121,12 @@ pub struct EthashParams {
pub eip649_delay: u64,
/// EIP-649 base reward.
pub eip649_reward: Option<U256>,
/// EIP-1234 transition block.
pub eip1234_transition: u64,
/// EIP-1234 bomb delay.
pub eip1234_delay: u64,
/// EIP-1234 base reward.
pub eip1234_reward: Option<U256>,
/// EXPIP-2 block height
pub expip2_transition: u64,
/// EXPIP-2 duration limit
Expand Down Expand Up @@ -152,6 +159,9 @@ impl From<ethjson::spec::EthashParams> 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),
}
Expand Down Expand Up @@ -233,8 +243,10 @@ impl Engine<EthereumMachine> for Arc<Ethash> {

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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
}
Expand Down
18 changes: 18 additions & 0 deletions json/src/spec/ethash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ pub struct EthashParams {
#[serde(rename="eip649Reward")]
pub eip649_reward: Option<Uint>,

/// EIP-1234 transition block.
#[serde(rename="eip1234Transition")]
pub eip1234_transition: Option<Uint>,

/// EIP-1234 bomb delay.
#[serde(rename="eip1234Delay")]
pub eip1234_delay: Option<Uint>,

/// EIP-1234 base reward.
#[serde(rename="eip1234Reward")]
pub eip1234_reward: Option<Uint>,

/// EXPIP-2 block height
#[serde(rename="expip2Transition")]
pub expip2_transition: Option<Uint>,
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit ae3aa43

Please sign in to comment.