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

Commit aa95a5e

Browse files
5chdnandresilva
authored andcommitted
ethash: implement EIP-1234 (#9187)
1 parent 5eb45c9 commit aa95a5e

File tree

6 files changed

+71
-27
lines changed

6 files changed

+71
-27
lines changed

ethcore/res/ethereum/constantinople_test.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
"durationLimit": "0x0d",
99
"blockReward": "0x4563918244F40000",
1010
"homesteadTransition": "0x0",
11-
"eip649Reward": "0x29A2241AF62C0000",
1211
"eip100bTransition": "0x0",
13-
"eip649Transition": "0x0"
12+
"eip649Transition": "0x0",
13+
"eip649Reward": "0x29A2241AF62C0000",
14+
"eip1234Transition": "0x0",
15+
"eip1234Reward": "0x1BC16D674EC80000"
1416
}
1517
}
1618
},

ethcore/res/ethereum/foundation.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@
129129
"0xbb9bc244d798123fde783fcc1c72d3bb8c189413",
130130
"0x807640a13483f8ac783c557fcdf27be11ea4ac7a"
131131
],
132-
"eip649Reward": "0x29A2241AF62C0000",
133132
"eip100bTransition": 4370000,
134-
"eip649Transition": 4370000
133+
"eip649Transition": 4370000,
134+
"eip649Reward": "0x29A2241AF62C0000",
135+
"eip1234Transition": "0x7fffffffffffff",
136+
"eip1234Reward": "0x1BC16D674EC80000"
135137
}
136138
}
137139
},

ethcore/res/ethereum/ropsten.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
"durationLimit": "0x0d",
1010
"blockReward": "0x4563918244F40000",
1111
"homesteadTransition": 0,
12-
"eip649Reward": "0x29A2241AF62C0000",
1312
"eip100bTransition": 1700000,
14-
"eip649Transition": 1700000
13+
"eip649Transition": 1700000,
14+
"eip649Reward": "0x29A2241AF62C0000",
15+
"eip1234Transition": "0x7fffffffffffff",
16+
"eip1234Reward": "0x1BC16D674EC80000"
1517
}
1618
}
1719
},

ethcore/res/ethereum/transition_test.json

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
"difficultyBoundDivisor": "0x0800",
88
"durationLimit": "0x0d",
99
"blockReward": "0x4563918244F40000",
10-
"homesteadTransition": "0",
10+
"homesteadTransition": "0x0",
11+
"eip100bTransition": "0x5",
12+
"eip649Transition": "0x5",
1113
"eip649Reward": "0x29A2241AF62C0000",
12-
"eip100bTransition": "5",
13-
"eip649Transition": "5"
14+
"eip1234Transition": "0x0",
15+
"eip1234Reward": "0x1BC16D674EC80000"
1416
}
1517
}
1618
},
@@ -22,17 +24,17 @@
2224
"minGasLimit": "0x1388",
2325
"networkID" : "0x1",
2426
"maxCodeSize": 24576,
25-
"maxCodeSizeTransition": "0",
26-
"eip150Transition": "0",
27-
"eip160Transition": "0",
28-
"eip161abcTransition": "0",
29-
"eip161dTransition": "0",
30-
"eip98Transition": "5",
31-
"eip140Transition": "5",
32-
"eip211Transition": "5",
33-
"eip214Transition": "5",
34-
"eip155Transition": "5",
35-
"eip658Transition": "5"
27+
"maxCodeSizeTransition": "0x0",
28+
"eip150Transition": "0x0",
29+
"eip160Transition": "0x0",
30+
"eip161abcTransition": "0x0",
31+
"eip161dTransition": "0x0",
32+
"eip98Transition": "0x5",
33+
"eip140Transition": "0x5",
34+
"eip211Transition": "0x5",
35+
"eip214Transition": "0x5",
36+
"eip155Transition": "0x5",
37+
"eip658Transition": "0x5"
3638
},
3739
"genesis": {
3840
"seal": {
@@ -53,9 +55,9 @@
5355
"0000000000000000000000000000000000000002": { "balance": "1", "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } },
5456
"0000000000000000000000000000000000000003": { "balance": "1", "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } },
5557
"0000000000000000000000000000000000000004": { "balance": "1", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } },
56-
"0000000000000000000000000000000000000005": { "builtin": { "name": "modexp", "activate_at": "5", "pricing": { "modexp": { "divisor": 100 } } } },
57-
"0000000000000000000000000000000000000006": { "builtin": { "name": "alt_bn128_add", "activate_at": "5", "pricing": { "linear": { "base": 500, "word": 0 } } } },
58-
"0000000000000000000000000000000000000007": { "builtin": { "name": "alt_bn128_mul", "activate_at": "5", "pricing": { "linear": { "base": 2000, "word": 0 } } } },
59-
"0000000000000000000000000000000000000008": { "builtin": { "name": "alt_bn128_pairing", "activate_at": "5", "pricing": { "alt_bn128_pairing": { "base": 100000, "pair": 80000 } } } }
58+
"0000000000000000000000000000000000000005": { "builtin": { "name": "modexp", "activate_at": "0x5", "pricing": { "modexp": { "divisor": 100 } } } },
59+
"0000000000000000000000000000000000000006": { "builtin": { "name": "alt_bn128_add", "activate_at": "0x5", "pricing": { "linear": { "base": 500, "word": 0 } } } },
60+
"0000000000000000000000000000000000000007": { "builtin": { "name": "alt_bn128_mul", "activate_at": "0x5", "pricing": { "linear": { "base": 2000, "word": 0 } } } },
61+
"0000000000000000000000000000000000000008": { "builtin": { "name": "alt_bn128_pairing", "activate_at": "0x5", "pricing": { "alt_bn128_pairing": { "base": 100000, "pair": 80000 } } } }
6062
}
6163
}

ethcore/src/ethereum/ethash.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ use machine::EthereumMachine;
3636
const SNAPSHOT_BLOCKS: u64 = 5000;
3737
/// Maximum number of blocks allowed in an ethash snapshot.
3838
const MAX_SNAPSHOT_BLOCKS: u64 = 30000;
39-
39+
/// Default number of blocks the difficulty bomb is delayed in EIP-{649,1234}
4040
const DEFAULT_EIP649_DELAY: u64 = 3_000_000;
41+
const DEFAULT_EIP1234_DELAY: u64 = 3_000_000;
4142

4243
/// Ethash specific seal
4344
#[derive(Debug, PartialEq)]
@@ -120,6 +121,12 @@ pub struct EthashParams {
120121
pub eip649_delay: u64,
121122
/// EIP-649 base reward.
122123
pub eip649_reward: Option<U256>,
124+
/// EIP-1234 transition block.
125+
pub eip1234_transition: u64,
126+
/// EIP-1234 bomb delay.
127+
pub eip1234_delay: u64,
128+
/// EIP-1234 base reward.
129+
pub eip1234_reward: Option<U256>,
123130
/// EXPIP-2 block height
124131
pub expip2_transition: u64,
125132
/// EXPIP-2 duration limit
@@ -152,6 +159,9 @@ impl From<ethjson::spec::EthashParams> for EthashParams {
152159
eip649_transition: p.eip649_transition.map_or(u64::max_value(), Into::into),
153160
eip649_delay: p.eip649_delay.map_or(DEFAULT_EIP649_DELAY, Into::into),
154161
eip649_reward: p.eip649_reward.map(Into::into),
162+
eip1234_transition: p.eip1234_transition.map_or(u64::max_value(), Into::into),
163+
eip1234_delay: p.eip1234_delay.map_or(DEFAULT_EIP1234_DELAY, Into::into),
164+
eip1234_reward: p.eip1234_reward.map(Into::into),
155165
expip2_transition: p.expip2_transition.map_or(u64::max_value(), Into::into),
156166
expip2_duration_limit: p.expip2_duration_limit.map_or(30, Into::into),
157167
}
@@ -233,8 +243,10 @@ impl Engine<EthereumMachine> for Arc<Ethash> {
233243

234244
let mut rewards = Vec::new();
235245

236-
// Applies EIP-649 reward.
237-
let reward = if number >= self.ethash_params.eip649_transition {
246+
// Applies EIP-{649,1234} reward, defaults to block_reward.
247+
let reward = if number >= self.ethash_params.eip1234_transition {
248+
self.ethash_params.eip1234_reward.unwrap_or(self.ethash_params.block_reward)
249+
} else if number >= self.ethash_params.eip649_transition {
238250
self.ethash_params.eip649_reward.unwrap_or(self.ethash_params.block_reward)
239251
} else {
240252
self.ethash_params.block_reward
@@ -427,6 +439,9 @@ impl Ethash {
427439
if header.number() < self.ethash_params.bomb_defuse_transition {
428440
if header.number() < self.ethash_params.ecip1010_pause_transition {
429441
let mut number = header.number();
442+
if number >= self.ethash_params.eip1234_transition {
443+
number = number.saturating_sub(self.ethash_params.eip1234_delay);
444+
}
430445
if number >= self.ethash_params.eip649_transition {
431446
number = number.saturating_sub(self.ethash_params.eip649_delay);
432447
}
@@ -510,6 +525,9 @@ mod tests {
510525
eip649_transition: u64::max_value(),
511526
eip649_delay: 3_000_000,
512527
eip649_reward: None,
528+
eip1234_transition: u64::max_value(),
529+
eip1234_delay: 3_000_000,
530+
eip1234_reward: None,
513531
expip2_transition: u64::max_value(),
514532
expip2_duration_limit: 30,
515533
}

json/src/spec/ethash.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ pub struct EthashParams {
116116
#[serde(rename="eip649Reward")]
117117
pub eip649_reward: Option<Uint>,
118118

119+
/// EIP-1234 transition block.
120+
#[serde(rename="eip1234Transition")]
121+
pub eip1234_transition: Option<Uint>,
122+
123+
/// EIP-1234 bomb delay.
124+
#[serde(rename="eip1234Delay")]
125+
pub eip1234_delay: Option<Uint>,
126+
127+
/// EIP-1234 base reward.
128+
#[serde(rename="eip1234Reward")]
129+
pub eip1234_reward: Option<Uint>,
130+
119131
/// EXPIP-2 block height
120132
#[serde(rename="expip2Transition")]
121133
pub expip2_transition: Option<Uint>,
@@ -231,6 +243,9 @@ mod tests {
231243
eip649_transition: None,
232244
eip649_delay: None,
233245
eip649_reward: None,
246+
eip1234_transition: None,
247+
eip1234_delay: None,
248+
eip1234_reward: None,
234249
expip2_transition: None,
235250
expip2_duration_limit: None,
236251
}
@@ -275,6 +290,9 @@ mod tests {
275290
eip649_transition: None,
276291
eip649_delay: None,
277292
eip649_reward: None,
293+
eip1234_transition: None,
294+
eip1234_delay: None,
295+
eip1234_reward: None,
278296
expip2_transition: None,
279297
expip2_duration_limit: None,
280298
}

0 commit comments

Comments
 (0)