Skip to content

Commit

Permalink
ethcore: mcip3 block reward contract (openethereum#9605)
Browse files Browse the repository at this point in the history
* Use static call and apparent value transfer for block reward contract code

* ethcore: implement musicoin block reward logic with contract

* ethcore: update musicoin block reward contract bytecode

* ethcore: add comment with source of musicoin block reward contract

* ethcore: remove unused mcip6_byz chain spec
  • Loading branch information
andresilva authored and 5chdn committed Oct 3, 2018
1 parent 2fc1679 commit 5b87327
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 245 deletions.
7 changes: 1 addition & 6 deletions ethcore/res/ethereum/mcip3_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
"homesteadTransition":"0x118c30",
"eip100bTransition":"0x7fffffffffffff",
"blockReward":"0x1105a0185b50a80000",
"mcip3Transition":"0x00",
"mcip3MinerReward":"0xd8d726b7177a80000",
"mcip3UbiReward":"0x2b5e3af16b1880000",
"mcip3UbiContract":"0x00efdd5883ec628983e9063c7d969fe268bbf310",
"mcip3DevReward":"0xc249fdd327780000",
"mcip3DevContract":"0x00756cf8159095948496617f5fb17ed95059f536"
"blockRewardContractCode": "0x6080604052600436106100405763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663f91c28988114610045575b600080fd5b34801561005157600080fd5b50610071602460048035828101929082013591813591820191013561010a565b604051808060200180602001838103835285818151815260200191508051906020019060200280838360005b838110156100b557818101518382015260200161009d565b50505050905001838103825284818151815260200191508051906020019060200280838360005b838110156100f45781810151838201526020016100dc565b5050505090500194505050505060405180910390f35b6060808080600080803373fffffffffffffffffffffffffffffffffffffffe1461013357600080fd5b89881461013f57600080fd5b60408051600380825260808201909252906020820160608038833950506040805160038082526080820190925292975090506020820160608038833901905050935072efdd5883ec628983e9063c7d969fe268bbf3108560018151811015156101a457fe5b73ffffffffffffffffffffffffffffffffffffffff90921660209283029091019091015283516802b5e3af16b188000090859060019081106101e257fe5b60209081029091010152845172756cf8159095948496617f5fb17ed95059f536908690600290811061021057fe5b73ffffffffffffffffffffffffffffffffffffffff909216602092830290910190910152835167c249fdd327780000908590600290811061024d57fe5b60209081029091010152600092505b898310156103b75788888481811061027057fe5b9050602002013561ffff1661ffff166000141561030c578a8a8481811061029357fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff168560008151811015156102bf57fe5b73ffffffffffffffffffffffffffffffffffffffff9092166020928302909101909101528351680d8d726b7177a8000090859060009081106102fd57fe5b602090810290910101526103ac565b606489898581811061031a57fe5b9050602002013561ffff1661ffff161015156103ac57606489898581811061033e57fe5b9050602002013561ffff1603915060038260080361ffff16681105a0185b50a80000029060020a9004905061039d858c8c86818110151561037b57fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff166103c8565b94506103a9848261049f565b93505b60019092019161025c565b509299919850909650505050505050565b606080600084516001016040519080825280602002602001820160405280156103fb578160200160208202803883390190505b509150600090505b845181101561045e57848181518110151561041a57fe5b90602001906020020151828281518110151561043257fe5b73ffffffffffffffffffffffffffffffffffffffff909216602092830290910190910152600101610403565b8382600184510381518110151561047157fe5b73ffffffffffffffffffffffffffffffffffffffff9290921660209283029190910190910152509392505050565b606080600084516001016040519080825280602002602001820160405280156104d2578160200160208202803883390190505b509150600090505b845181101561051b5784818151811015156104f157fe5b90602001906020020151828281518110151561050957fe5b602090810290910101526001016104da565b8382600184510381518110151561052e57fe5b60209081029190910101525093925050505600a165627a7a72305820c9ab92a56245040e76af5fc4f3ac4cf4315336b503db06677c21aa1e00aaa8e20029"
}
}
},
Expand Down
162 changes: 0 additions & 162 deletions ethcore/res/ethereum/mcip6_byz.json

This file was deleted.

8 changes: 2 additions & 6 deletions ethcore/res/ethereum/musicoin.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@
"homesteadTransition":"0x118c30",
"eip100bTransition":"0x21e88e",
"blockReward":"0x1105a0185b50a80000",
"mcip3Transition":"0x124f81",
"mcip3MinerReward":"0xd8d726b7177a80000",
"mcip3UbiReward":"0x2b5e3af16b1880000",
"mcip3UbiContract":"0x00efdd5883ec628983e9063c7d969fe268bbf310",
"mcip3DevReward":"0xc249fdd327780000",
"mcip3DevContract":"0x00756cf8159095948496617f5fb17ed95059f536",
"blockRewardContractTransition": "0x124f81",
"blockRewardContractCode": "0x6080604052600436106100405763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663f91c28988114610045575b600080fd5b34801561005157600080fd5b50610071602460048035828101929082013591813591820191013561010a565b604051808060200180602001838103835285818151815260200191508051906020019060200280838360005b838110156100b557818101518382015260200161009d565b50505050905001838103825284818151815260200191508051906020019060200280838360005b838110156100f45781810151838201526020016100dc565b5050505090500194505050505060405180910390f35b6060808080600080803373fffffffffffffffffffffffffffffffffffffffe1461013357600080fd5b89881461013f57600080fd5b60408051600380825260808201909252906020820160608038833950506040805160038082526080820190925292975090506020820160608038833901905050935072efdd5883ec628983e9063c7d969fe268bbf3108560018151811015156101a457fe5b73ffffffffffffffffffffffffffffffffffffffff90921660209283029091019091015283516802b5e3af16b188000090859060019081106101e257fe5b60209081029091010152845172756cf8159095948496617f5fb17ed95059f536908690600290811061021057fe5b73ffffffffffffffffffffffffffffffffffffffff909216602092830290910190910152835167c249fdd327780000908590600290811061024d57fe5b60209081029091010152600092505b898310156103b75788888481811061027057fe5b9050602002013561ffff1661ffff166000141561030c578a8a8481811061029357fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff168560008151811015156102bf57fe5b73ffffffffffffffffffffffffffffffffffffffff9092166020928302909101909101528351680d8d726b7177a8000090859060009081106102fd57fe5b602090810290910101526103ac565b606489898581811061031a57fe5b9050602002013561ffff1661ffff161015156103ac57606489898581811061033e57fe5b9050602002013561ffff1603915060038260080361ffff16681105a0185b50a80000029060020a9004905061039d858c8c86818110151561037b57fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff166103c8565b94506103a9848261049f565b93505b60019092019161025c565b509299919850909650505050505050565b606080600084516001016040519080825280602002602001820160405280156103fb578160200160208202803883390190505b509150600090505b845181101561045e57848181518110151561041a57fe5b90602001906020020151828281518110151561043257fe5b73ffffffffffffffffffffffffffffffffffffffff909216602092830290910190910152600101610403565b8382600184510381518110151561047157fe5b73ffffffffffffffffffffffffffffffffffffffff9290921660209283029190910190910152509392505050565b606080600084516001016040519080825280602002602001820160405280156104d2578160200160208202803883390190505b509150600090505b845181101561051b5784818151811015156104f157fe5b90602001906020020151828281518110151561050957fe5b602090810290910101526001016104da565b8382600184510381518110151561052e57fe5b60209081029190910101525093925050505600a165627a7a72305820c9ab92a56245040e76af5fc4f3ac4cf4315336b503db06677c21aa1e00aaa8e20029",
"difficultyBombDelays": {
"0x21e88e": 3000000
}
Expand Down
42 changes: 2 additions & 40 deletions ethcore/src/ethereum/ethash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::sync::Arc;
use hash::{KECCAK_EMPTY_LIST_RLP};
use engines::block_reward::{self, BlockRewardContract, RewardKind};
use ethash::{self, quick_get_difficulty, slow_hash_block_number, EthashManager, OptimizeFor};
use ethereum_types::{H256, H64, U256, Address};
use ethereum_types::{H256, H64, U256};
use unexpected::{OutOfBounds, Mismatch};
use block::*;
use error::{BlockError, Error};
Expand Down Expand Up @@ -98,18 +98,6 @@ pub struct EthashParams {
pub ecip1010_continue_transition: u64,
/// Total block number for one ECIP-1017 era.
pub ecip1017_era_rounds: u64,
/// Number of first block where MCIP-3 begins.
pub mcip3_transition: u64,
/// MCIP-3 Block reward coin-base for miners.
pub mcip3_miner_reward: U256,
/// MCIP-3 Block reward ubi-base for basic income.
pub mcip3_ubi_reward: U256,
/// MCIP-3 contract address for universal basic income.
pub mcip3_ubi_contract: Address,
/// MCIP-3 Block reward dev-base for dev funds.
pub mcip3_dev_reward: U256,
/// MCIP-3 contract address for the developer funds.
pub mcip3_dev_contract: Address,
/// Block reward in base units.
pub block_reward: BTreeMap<BlockNumber, U256>,
/// EXPIP-2 block height
Expand Down Expand Up @@ -140,12 +128,6 @@ impl From<ethjson::spec::EthashParams> for EthashParams {
ecip1010_pause_transition: p.ecip1010_pause_transition.map_or(u64::max_value(), Into::into),
ecip1010_continue_transition: p.ecip1010_continue_transition.map_or(u64::max_value(), Into::into),
ecip1017_era_rounds: p.ecip1017_era_rounds.map_or(u64::max_value(), Into::into),
mcip3_transition: p.mcip3_transition.map_or(u64::max_value(), Into::into),
mcip3_miner_reward: p.mcip3_miner_reward.map_or_else(Default::default, Into::into),
mcip3_ubi_reward: p.mcip3_ubi_reward.map_or(U256::from(0), Into::into),
mcip3_ubi_contract: p.mcip3_ubi_contract.map_or_else(Address::new, Into::into),
mcip3_dev_reward: p.mcip3_dev_reward.map_or(U256::from(0), Into::into),
mcip3_dev_contract: p.mcip3_dev_contract.map_or_else(Address::new, Into::into),
block_reward: p.block_reward.map_or_else(
|| {
let mut ret = BTreeMap::new();
Expand Down Expand Up @@ -287,21 +269,7 @@ impl Engine<EthereumMachine> for Arc<Ethash> {
// Bestow block rewards.
let mut result_block_reward = reward + reward.shr(5) * U256::from(n_uncles);

if number >= self.ethash_params.mcip3_transition {
result_block_reward = self.ethash_params.mcip3_miner_reward;

let ubi_contract = self.ethash_params.mcip3_ubi_contract;
let ubi_reward = self.ethash_params.mcip3_ubi_reward;
let dev_contract = self.ethash_params.mcip3_dev_contract;
let dev_reward = self.ethash_params.mcip3_dev_reward;

rewards.push((author, RewardKind::Author, result_block_reward));
rewards.push((ubi_contract, RewardKind::External, ubi_reward));
rewards.push((dev_contract, RewardKind::External, dev_reward));

} else {
rewards.push((author, RewardKind::Author, result_block_reward));
}
rewards.push((author, RewardKind::Author, result_block_reward));

// Bestow uncle rewards.
for u in LiveBlock::uncles(&*block) {
Expand Down Expand Up @@ -549,12 +517,6 @@ mod tests {
ecip1010_pause_transition: u64::max_value(),
ecip1010_continue_transition: u64::max_value(),
ecip1017_era_rounds: u64::max_value(),
mcip3_transition: u64::max_value(),
mcip3_miner_reward: 0.into(),
mcip3_ubi_reward: 0.into(),
mcip3_ubi_contract: "0000000000000000000000000000000000000001".into(),
mcip3_dev_reward: 0.into(),
mcip3_dev_contract: "0000000000000000000000000000000000000001".into(),
expip2_transition: u64::max_value(),
expip2_duration_limit: 30,
block_reward_contract: None,
Expand Down
2 changes: 2 additions & 0 deletions ethcore/src/ethereum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ pub fn new_expanse<'a, T: Into<SpecParams<'a>>>(params: T) -> Spec {

/// Create a new Musicoin mainnet chain spec.
pub fn new_musicoin<'a, T: Into<SpecParams<'a>>>(params: T) -> Spec {
// The musicoin chain spec uses a block reward contract which can be found at
// https://gist.github.com/andresilva/6f2afaf9486732a0797f4bdeae018ee9
load(params.into(), include_bytes!("../../res/ethereum/musicoin.json"))
}

Expand Down
31 changes: 0 additions & 31 deletions json/src/spec/ethash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,6 @@ pub struct EthashParams {
#[serde(rename="ecip1017EraRounds")]
pub ecip1017_era_rounds: Option<Uint>,

/// See main EthashParams docs.
#[serde(rename="mcip3Transition")]
pub mcip3_transition: Option<Uint>,
/// See main EthashParams docs.
#[serde(rename="mcip3MinerReward")]
pub mcip3_miner_reward: Option<Uint>,
/// See main EthashParams docs.
#[serde(rename="mcip3UbiReward")]
pub mcip3_ubi_reward: Option<Uint>,
/// See main EthashParams docs.
#[serde(rename="mcip3UbiContract")]
pub mcip3_ubi_contract: Option<Address>,
/// See main EthashParams docs.
#[serde(rename="mcip3DevReward")]
pub mcip3_dev_reward: Option<Uint>,
/// See main EthashParams docs.
#[serde(rename="mcip3DevContract")]
pub mcip3_dev_contract: Option<Address>,

/// Delays of difficulty bombs.
#[serde(rename="difficultyBombDelays")]
pub difficulty_bomb_delays: Option<BTreeMap<Uint, Uint>>,
Expand Down Expand Up @@ -236,12 +217,6 @@ mod tests {
ecip1010_pause_transition: None,
ecip1010_continue_transition: None,
ecip1017_era_rounds: None,
mcip3_transition: None,
mcip3_miner_reward: None,
mcip3_ubi_reward: None,
mcip3_ubi_contract: None,
mcip3_dev_reward: None,
mcip3_dev_contract: None,
expip2_transition: None,
expip2_duration_limit: None,
difficulty_bomb_delays: None,
Expand Down Expand Up @@ -281,12 +256,6 @@ mod tests {
ecip1010_pause_transition: None,
ecip1010_continue_transition: None,
ecip1017_era_rounds: None,
mcip3_transition: None,
mcip3_miner_reward: None,
mcip3_ubi_reward: None,
mcip3_ubi_contract: None,
mcip3_dev_reward: None,
mcip3_dev_contract: None,
expip2_transition: None,
expip2_duration_limit: None,
difficulty_bomb_delays: None,
Expand Down

0 comments on commit 5b87327

Please sign in to comment.