Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom ChainStart Genesis Time Delay in Deposit Contract #1666

Merged
merged 5 commits into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion beacon-chain/powchain/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func setup() (*testAccount, error) {
depositsRequired,
minDeposit,
maxDeposit,
false,
big.NewInt(1),
addr,
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion contracts/deposit-contract/abi.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"name": "Deposit", "inputs": [{"type": "bytes32", "name": "deposit_root", "indexed": false}, {"type": "bytes", "name": "data", "indexed": false}, {"type": "bytes", "name": "merkle_tree_index", "indexed": false}, {"type": "bytes32[32]", "name": "branch", "indexed": false}], "anonymous": false, "type": "event"}, {"name": "ChainStart", "inputs": [{"type": "bytes32", "name": "deposit_root", "indexed": false}, {"type": "bytes", "name": "time", "indexed": false}], "anonymous": false, "type": "event"}, {"name": "__init__", "outputs": [], "inputs": [{"type": "uint256", "name": "depositThreshold"}, {"type": "uint256", "name": "minDeposit"}, {"type": "uint256", "name": "maxDeposit"}, {"type": "bool", "name": "skipChainstartDelay"}, {"type": "address", "name": "_drain_address"}], "constant": false, "payable": false, "type": "constructor"}, {"name": "to_little_endian_64", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [{"type": "uint256", "name": "value"}], "constant": true, "payable": false, "type": "function", "gas": 15330}, {"name": "get_deposit_root", "outputs": [{"type": "bytes32", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 30835}, {"name": "deposit", "outputs": [], "inputs": [{"type": "bytes", "name": "deposit_input"}], "constant": false, "payable": true, "type": "function", "gas": 531258}, {"name": "drain", "outputs": [], "inputs": [], "constant": false, "payable": false, "type": "function", "gas": 35793}, {"name": "CHAIN_START_FULL_DEPOSIT_THRESHOLD", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 633}, {"name": "MIN_DEPOSIT_AMOUNT", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 663}, {"name": "MAX_DEPOSIT_AMOUNT", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 693}, {"name": "deposit_count", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 723}, {"name": "full_deposit_count", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 753}, {"name": "skip_chainstart_delay", "outputs": [{"type": "bool", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 783}, {"name": "genesisTime", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 3036}, {"name": "drain_address", "outputs": [{"type": "address", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 843}]
[{"name": "Deposit", "inputs": [{"type": "bytes32", "name": "deposit_root", "indexed": false}, {"type": "bytes", "name": "data", "indexed": false}, {"type": "bytes", "name": "merkle_tree_index", "indexed": false}, {"type": "bytes32[32]", "name": "branch", "indexed": false}], "anonymous": false, "type": "event"}, {"name": "ChainStart", "inputs": [{"type": "bytes32", "name": "deposit_root", "indexed": false}, {"type": "bytes", "name": "time", "indexed": false}], "anonymous": false, "type": "event"}, {"name": "__init__", "outputs": [], "inputs": [{"type": "uint256", "name": "depositThreshold"}, {"type": "uint256", "name": "minDeposit"}, {"type": "uint256", "name": "maxDeposit"}, {"type": "uint256", "name": "customChainstartDelay"}, {"type": "address", "name": "_drain_address"}], "constant": false, "payable": false, "type": "constructor"}, {"name": "to_little_endian_64", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [{"type": "uint256", "name": "value"}], "constant": true, "payable": false, "type": "function", "gas": 15330}, {"name": "get_deposit_root", "outputs": [{"type": "bytes32", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 30835}, {"name": "deposit", "outputs": [], "inputs": [{"type": "bytes", "name": "deposit_input"}], "constant": false, "payable": true, "type": "function", "gas": 535502}, {"name": "drain", "outputs": [], "inputs": [], "constant": false, "payable": false, "type": "function", "gas": 35793}, {"name": "CHAIN_START_FULL_DEPOSIT_THRESHOLD", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 633}, {"name": "MIN_DEPOSIT_AMOUNT", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 663}, {"name": "MAX_DEPOSIT_AMOUNT", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 693}, {"name": "deposit_count", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 723}, {"name": "full_deposit_count", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 753}, {"name": "custom_chainstart_delay", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 783}, {"name": "genesisTime", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 3036}, {"name": "drain_address", "outputs": [{"type": "address", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 843}]
2 changes: 1 addition & 1 deletion contracts/deposit-contract/bytecode.bin

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions contracts/deposit-contract/deployContract/deployContract.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {
var depositsForChainStart int64
var minDepositAmount int64
var maxDepositAmount int64
var skipChainstartDelay bool
var customChainstartDelay uint64
var drainAddress string

customFormatter := new(prefixed.TextFormatter)
Expand All @@ -55,10 +55,11 @@ func main() {
Usage: "Location of keystore",
Destination: &keystoreUTCPath,
},
cli.BoolFlag{
Name: "skipChainstartDelay",
Usage: "Whether to skip ChainStart log being fired a day later",
Destination: &skipChainstartDelay,
cli.Uint64Flag{
Name: "customChainstartDelay",
Usage: "Number of seconds to delay the ChainStart genesis timestamp",
Value: 0,
Destination: &customChainstartDelay,
},
cli.StringFlag{
Name: "ipcPath",
Expand Down Expand Up @@ -180,7 +181,7 @@ func main() {
big.NewInt(depositsForChainStart),
big.NewInt(minDepositAmount),
big.NewInt(maxDepositAmount),
skipChainstartDelay,
big.NewInt(int64(customChainstartDelay)),
drain,
)

Expand Down
60 changes: 30 additions & 30 deletions contracts/deposit-contract/depositContract.go

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions contracts/deposit-contract/depositContract.v.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
branch: bytes32[32]
deposit_count: public(uint256)
full_deposit_count: public(uint256)
skip_chainstart_delay: public(bool)
custom_chainstart_delay: public(uint256)
genesisTime: public(bytes[8])
drain_address: public(address)

Expand All @@ -23,12 +23,12 @@ def __init__( # Parameters for debugging, not for production use!
depositThreshold: uint256,
minDeposit: uint256,
maxDeposit: uint256,
skipChainstartDelay: bool,
customChainstartDelay: uint256,
_drain_address: address):
self.CHAIN_START_FULL_DEPOSIT_THRESHOLD = depositThreshold
self.MIN_DEPOSIT_AMOUNT = minDeposit
self.MAX_DEPOSIT_AMOUNT = maxDeposit
self.skip_chainstart_delay = skipChainstartDelay
self.custom_chainstart_delay = customChainstartDelay
self.drain_address = _drain_address
for i in range(31):
self.zerohashes[i+1] = sha3(concat(self.zerohashes[i], self.zerohashes[i]))
Expand Down Expand Up @@ -103,8 +103,9 @@ def deposit(deposit_input: bytes[512]):
if deposit_amount == self.MAX_DEPOSIT_AMOUNT:
self.full_deposit_count += 1
if self.full_deposit_count == self.CHAIN_START_FULL_DEPOSIT_THRESHOLD:
if self.skip_chainstart_delay:
self.genesisTime = self.to_little_endian_64(deposit_timestamp)
if self.custom_chainstart_delay > 0:
timestamp_boundary: uint256 = as_unitless_number(block.timestamp) - as_unitless_number(block.timestamp) % self.custom_chainstart_delay + self.custom_chainstart_delay
self.genesisTime = self.to_little_endian_64(timestamp_boundary)
log.ChainStart(self.get_deposit_root(), self.genesisTime)
else:
timestamp_day_boundary: uint256 = as_unitless_number(block.timestamp) - as_unitless_number(block.timestamp) % SECONDS_PER_DAY + SECONDS_PER_DAY
Expand Down
2 changes: 1 addition & 1 deletion contracts/deposit-contract/depositContract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func setup() (*testAccount, error) {
depositsRequired := big.NewInt(8)
minDeposit := big.NewInt(1e9)
maxDeposit := big.NewInt(32e9)
contractAddr, _, contract, err := DeployDepositContract(txOpts, backend, depositsRequired, minDeposit, maxDeposit, false, addr)
contractAddr, _, contract, err := DeployDepositContract(txOpts, backend, depositsRequired, minDeposit, maxDeposit, big.NewInt(1), addr)
if err != nil {
return nil, err
}
Expand Down