From d1e589f11fd854a7ec8ac7fee05e91c88c199d1d Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Sat, 8 Jun 2019 19:00:50 +0100 Subject: [PATCH 01/10] Remove eth2 genesis in favour of genesis trigger --- .../contracts/validator_registration.json | 2 +- .../contracts/validator_registration.v.py | 22 -------- deposit_contract/tests/contracts/conftest.py | 26 ++-------- .../tests/contracts/test_deposit.py | 50 ------------------ specs/core/0_beacon-chain.md | 51 ++++++++++++++----- specs/core/0_deposit-contract.md | 20 -------- 6 files changed, 42 insertions(+), 129 deletions(-) diff --git a/deposit_contract/contracts/validator_registration.json b/deposit_contract/contracts/validator_registration.json index 08d57f80a..a885ef0a1 100644 --- a/deposit_contract/contracts/validator_registration.json +++ b/deposit_contract/contracts/validator_registration.json @@ -1 +1 @@ -{"abi": [{"name": "Deposit", "inputs": [{"type": "bytes", "name": "pubkey", "indexed": false}, {"type": "bytes", "name": "withdrawal_credentials", "indexed": false}, {"type": "bytes", "name": "amount", "indexed": false}, {"type": "bytes", "name": "signature", "indexed": false}, {"type": "bytes", "name": "merkle_tree_index", "indexed": false}], "anonymous": false, "type": "event"}, {"name": "Eth2Genesis", "inputs": [{"type": "bytes32", "name": "deposit_root", "indexed": false}, {"type": "bytes", "name": "deposit_count", "indexed": false}, {"type": "bytes", "name": "time", "indexed": false}], "anonymous": false, "type": "event"}, {"outputs": [], "inputs": [], "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": 7077}, {"name": "get_deposit_root", "outputs": [{"type": "bytes32", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 79221}, {"name": "get_deposit_count", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 11026}, {"name": "deposit", "outputs": [], "inputs": [{"type": "bytes", "name": "pubkey"}, {"type": "bytes", "name": "withdrawal_credentials"}, {"type": "bytes", "name": "signature"}], "constant": false, "payable": true, "type": "function", "gas": 445994}, {"name": "chainStarted", "outputs": [{"type": "bool", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 603}], "bytecode": "0x600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009e57600080fd5b6101406000601f818352015b600061014051602081106100bd57600080fd5b600060c052602060c020015460208261016001015260208101905061014051602081106100e957600080fd5b600060c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012757600080fd5b60c0519050606051600161014051018060405190131561014657600080fd5b809190121561015457600080fd5b6020811061016157600080fd5b600060c052602060c02001555b81516001018083528114156100aa575b505061140756600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a0526380673289600051141561026b57602060046101403734156100b457600080fd5b67ffffffffffffffff6101405111156100cc57600080fd5b60006101605261014051610180526101a060006008818352015b6101605160086000811215610103578060000360020a820461010a565b8060020a82025b905090506101605260ff61018051166101c052610160516101c0516101605101101561013557600080fd5b6101c051610160510161016052610180517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8600081121561017e578060000360020a8204610185565b8060020a82025b90509050610180525b81516001018083528114156100e6575b505060186008602082066101e001602082840111156101bc57600080fd5b60208061020082610160600060046015f15050818152809050905090508051602001806102a0828460006004600a8704601201f16101f957600080fd5b50506102a05160206001820306601f82010390506103006102a0516008818352015b8261030051111561022b57610247565b6000610300516102c001535b815160010180835281141561021b575b50505060206102805260406102a0510160206001820306601f8201039050610280f3005b63c5f2892f60005114156103c357341561028457600080fd5b6000610140526002546101605261018060006020818352015b600160016101605116141561031e57600061018051602081106102bf57600080fd5b600160c052602060c02001546020826102200101526020810190506101405160208261022001015260208101905080610220526102209050602060c0825160208401600060025af161031057600080fd5b60c05190506101405261038c565b6000610140516020826101a0010152602081019050610180516020811061034457600080fd5b600060c052602060c02001546020826101a0010152602081019050806101a0526101a09050602060c0825160208401600060025af161038257600080fd5b60c0519050610140525b610160600261039a57600080fd5b60028151048152505b815160010180835281141561029d575b50506101405160005260206000f3005b63621fd13060005114156104995734156103dc57600080fd5b60606101c060246380673289610140526002546101605261015c6000305af161040457600080fd5b6101e0805160200180610260828460006004600a8704601201f161042757600080fd5b50506102605160206001820306601f82010390506102c0610260516008818352015b826102c051111561045957610475565b60006102c05161028001535b8151600101808352811415610449575b5050506020610240526040610260510160206001820306601f8201039050610240f3005b63c47e300d600051141561125657606060046101403760506004356004016101a03760306004356004013511156104cf57600080fd5b60406024356004016102203760206024356004013511156104ef57600080fd5b608060443560040161028037606060443560040135111561050f57600080fd5b63ffffffff6002541061052157600080fd5b60306101a0511461053157600080fd5b6020610220511461054157600080fd5b6060610280511461055157600080fd5b633b9aca00610340526103405161056757600080fd5b61034051340461032052633b9aca0061032051101561058557600080fd5b6060610440602463806732896103c052610320516103e0526103dc6000305af16105ae57600080fd5b610460805160200180610360828460006004600a8704601201f16105d157600080fd5b50506002546104a05260006104c0526104a05160016104a0510110156105f657600080fd5b60016104a051016104e05261050060006020818352015b600160016104e05116141561062157610674565b6104c060605160018251018060405190131561063c57600080fd5b809190121561064a57600080fd5b8152506104e0600261065b57600080fd5b60028151048152505b815160010180835281141561060d575b505060006101a06030806020846105e001018260208501600060046016f1505080518201915050600060106020820661056001602082840111156106b757600080fd5b60208061058082610520600060046015f15050818152809050905090506010806020846105e001018260208501600060046013f1505080518201915050806105e0526105e09050602060c0825160208401600060025af161071757600080fd5b60c051905061054052600060006040602082066106800161028051828401111561074057600080fd5b6060806106a0826020602088068803016102800160006004601bf1505081815280905090509050602060c0825160208401600060025af161078057600080fd5b60c051905060208261088001015260208101905060006040602060208206610740016102805182840111156107b457600080fd5b606080610760826020602088068803016102800160006004601bf150508181528090509050905060208060208461080001018260208501600060046015f15050805182019150506105205160208261080001015260208101905080610800526108009050602060c0825160208401600060025af161083157600080fd5b60c051905060208261088001015260208101905080610880526108809050602060c0825160208401600060025af161086857600080fd5b60c051905061066052600060006105405160208261092001015260208101905061022060208060208461092001018260208501600060046015f150508051820191505080610920526109209050602060c0825160208401600060025af16108ce57600080fd5b60c0519050602082610aa00101526020810190506000610360600880602084610a2001018260208501600060046012f150508051820191505060006018602082066109a0016020828401111561092357600080fd5b6020806109c082610520600060046015f1505081815280905090509050601880602084610a2001018260208501600060046014f150508051820191505061066051602082610a2001015260208101905080610a2052610a209050602060c0825160208401600060025af161099657600080fd5b60c0519050602082610aa001015260208101905080610aa052610aa09050602060c0825160208401600060025af16109cd57600080fd5b60c051905061090052610b2060006020818352015b6104c051610b20511215610a62576000610b205160208110610a0357600080fd5b600160c052602060c0200154602082610b4001015260208101905061090051602082610b4001015260208101905080610b4052610b409050602060c0825160208401600060025af1610a5457600080fd5b60c051905061090052610a67565b610a78565b5b81516001018083528114156109e2575b5050610900516104c05160208110610a8f57600080fd5b600160c052602060c02001556002805460018254011015610aaf57600080fd5b60018154018155506060610c4060246380673289610bc0526104a051610be052610bdc6000305af1610ae057600080fd5b610c60805160200180610ca0828460006004600a8704601201f1610b0357600080fd5b505060a0610d2052610d2051610d60526101a0805160200180610d2051610d6001828460006004600a8704601201f1610b3b57600080fd5b5050610d2051610d60015160206001820306601f8201039050610d2051610d6001610d0081516040818352015b83610d0051101515610b7957610b96565b6000610d00516020850101535b8151600101808352811415610b68575b505050506020610d2051610d60015160206001820306601f8201039050610d20510101610d2052610d2051610d8052610220805160200180610d2051610d6001828460006004600a8704601201f1610bed57600080fd5b5050610d2051610d60015160206001820306601f8201039050610d2051610d6001610d0081516020818352015b83610d0051101515610c2b57610c48565b6000610d00516020850101535b8151600101808352811415610c1a575b505050506020610d2051610d60015160206001820306601f8201039050610d20510101610d2052610d2051610da052610360805160200180610d2051610d6001828460006004600a8704601201f1610c9f57600080fd5b5050610d2051610d60015160206001820306601f8201039050610d2051610d6001610d0081516020818352015b83610d0051101515610cdd57610cfa565b6000610d00516020850101535b8151600101808352811415610ccc575b505050506020610d2051610d60015160206001820306601f8201039050610d20510101610d2052610d2051610dc052610280805160200180610d2051610d6001828460006004600a8704601201f1610d5157600080fd5b5050610d2051610d60015160206001820306601f8201039050610d2051610d6001610d0081516060818352015b83610d0051101515610d8f57610dac565b6000610d00516020850101535b8151600101808352811415610d7e575b505050506020610d2051610d60015160206001820306601f8201039050610d20510101610d2052610d2051610de052610ca0805160200180610d2051610d6001828460006004600a8704601201f1610e0357600080fd5b5050610d2051610d60015160206001820306601f8201039050610d2051610d6001610d0081516020818352015b83610d0051101515610e4157610e5e565b6000610d00516020850101535b8151600101808352811415610e30575b505050506020610d2051610d60015160206001820306601f8201039050610d20510101610d20527fdc5fc95703516abd38fa03c3737ff3b52dc52347055c8028460fdf5bbe2f12ce610d2051610d60a164077359400061032051101515611254576003805460018254011015610ed357600080fd5b60018154018155506201000060035414156112535742610e205242610e405262015180610eff57600080fd5b62015180610e405106610e20511015610f1757600080fd5b42610e405262015180610f2957600080fd5b62015180610e405106610e2051036202a30042610e205242610e405262015180610f5257600080fd5b62015180610e405106610e20511015610f6a57600080fd5b42610e405262015180610f7c57600080fd5b62015180610e405106610e205103011015610f9657600080fd5b6202a30042610e205242610e405262015180610fb157600080fd5b62015180610e405106610e20511015610fc957600080fd5b42610e405262015180610fdb57600080fd5b62015180610e405106610e20510301610e00526020610ee0600463c5f2892f610e8052610e9c6000305af161100f57600080fd5b610ee051610e60526060610f8060246380673289610f0052600254610f2052610f1c6000305af161103f57600080fd5b610fa0805160200180610fe0828460006004600a8704601201f161106257600080fd5b505060606110c06024638067328961104052610e00516110605261105c6000305af161108d57600080fd5b6110e0805160200180611120828460006004600a8704601201f16110b057600080fd5b5050610e60516111e05260606111a0526111a05161120052610fe08051602001806111a0516111e001828460006004600a8704601201f16110f057600080fd5b50506111a0516111e0015160206001820306601f82010390506111a0516111e00161118081516020818352015b836111805110151561112e5761114b565b6000611180516020850101535b815160010180835281141561111d575b5050505060206111a0516111e0015160206001820306601f82010390506111a05101016111a0526111a051611220526111208051602001806111a0516111e001828460006004600a8704601201f16111a257600080fd5b50506111a0516111e0015160206001820306601f82010390506111a0516111e00161118081516020818352015b83611180511015156111e0576111fd565b6000611180516020850101535b81516001018083528114156111cf575b5050505060206111a0516111e0015160206001820306601f82010390506111a05101016111a0527f08b71ef3f1b58f7a23ffb82e27f12f0888c8403f1ceb0ea7ea26b274e2189d4c6111a0516111e0a160016004555b5b005b63845980e8600051141561127c57341561126f57600080fd5b60045460005260206000f3005b60006000fd5b61018561140703610185600039610185611407036000f3"} \ No newline at end of file +{"abi": [{"name": "Deposit", "inputs": [{"type": "bytes", "name": "pubkey", "indexed": false}, {"type": "bytes", "name": "withdrawal_credentials", "indexed": false}, {"type": "bytes", "name": "amount", "indexed": false}, {"type": "bytes", "name": "signature", "indexed": false}, {"type": "bytes", "name": "merkle_tree_index", "indexed": false}], "anonymous": false, "type": "event"}, {"outputs": [], "inputs": [], "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": 7077}, {"name": "get_deposit_root", "outputs": [{"type": "bytes32", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 79221}, {"name": "get_deposit_count", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 11026}, {"name": "deposit", "outputs": [], "inputs": [{"type": "bytes", "name": "pubkey"}, {"type": "bytes", "name": "withdrawal_credentials"}, {"type": "bytes", "name": "signature"}], "constant": false, "payable": true, "type": "function", "gas": 255244}], "bytecode": "0x600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009e57600080fd5b6101406000601f818352015b600061014051602081106100bd57600080fd5b600060c052602060c020015460208261016001015260208101905061014051602081106100e957600080fd5b600060c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012757600080fd5b60c0519050606051600161014051018060405190131561014657600080fd5b809190121561015457600080fd5b6020811061016157600080fd5b600060c052602060c02001555b81516001018083528114156100aa575b505061103b56600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a0526380673289600051141561026b57602060046101403734156100b457600080fd5b67ffffffffffffffff6101405111156100cc57600080fd5b60006101605261014051610180526101a060006008818352015b6101605160086000811215610103578060000360020a820461010a565b8060020a82025b905090506101605260ff61018051166101c052610160516101c0516101605101101561013557600080fd5b6101c051610160510161016052610180517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8600081121561017e578060000360020a8204610185565b8060020a82025b90509050610180525b81516001018083528114156100e6575b505060186008602082066101e001602082840111156101bc57600080fd5b60208061020082610160600060046015f15050818152809050905090508051602001806102a0828460006004600a8704601201f16101f957600080fd5b50506102a05160206001820306601f82010390506103006102a0516008818352015b8261030051111561022b57610247565b6000610300516102c001535b815160010180835281141561021b575b50505060206102805260406102a0510160206001820306601f8201039050610280f3005b63c5f2892f60005114156103c357341561028457600080fd5b6000610140526002546101605261018060006020818352015b600160016101605116141561031e57600061018051602081106102bf57600080fd5b600160c052602060c02001546020826102200101526020810190506101405160208261022001015260208101905080610220526102209050602060c0825160208401600060025af161031057600080fd5b60c05190506101405261038c565b6000610140516020826101a0010152602081019050610180516020811061034457600080fd5b600060c052602060c02001546020826101a0010152602081019050806101a0526101a09050602060c0825160208401600060025af161038257600080fd5b60c0519050610140525b610160600261039a57600080fd5b60028151048152505b815160010180835281141561029d575b50506101405160005260206000f3005b63621fd13060005114156104995734156103dc57600080fd5b60606101c060246380673289610140526002546101605261015c6000305af161040457600080fd5b6101e0805160200180610260828460006004600a8704601201f161042757600080fd5b50506102605160206001820306601f82010390506102c0610260516008818352015b826102c051111561045957610475565b60006102c05161028001535b8151600101808352811415610449575b5050506020610240526040610260510160206001820306601f8201039050610240f3005b63c47e300d6000511415610eb057606060046101403760506004356004016101a03760306004356004013511156104cf57600080fd5b60406024356004016102203760206024356004013511156104ef57600080fd5b608060443560040161028037606060443560040135111561050f57600080fd5b63ffffffff6002541061052157600080fd5b60306101a0511461053157600080fd5b6020610220511461054157600080fd5b6060610280511461055157600080fd5b633b9aca00610340526103405161056757600080fd5b61034051340461032052633b9aca0061032051101561058557600080fd5b6060610440602463806732896103c052610320516103e0526103dc6000305af16105ae57600080fd5b610460805160200180610360828460006004600a8704601201f16105d157600080fd5b50506002546104a05260006104c0526104a05160016104a0510110156105f657600080fd5b60016104a051016104e05261050060006020818352015b600160016104e05116141561062157610674565b6104c060605160018251018060405190131561063c57600080fd5b809190121561064a57600080fd5b8152506104e0600261065b57600080fd5b60028151048152505b815160010180835281141561060d575b505060006101a06030806020846105e001018260208501600060046016f1505080518201915050600060106020820661056001602082840111156106b757600080fd5b60208061058082610520600060046015f15050818152809050905090506010806020846105e001018260208501600060046013f1505080518201915050806105e0526105e09050602060c0825160208401600060025af161071757600080fd5b60c051905061054052600060006040602082066106800161028051828401111561074057600080fd5b6060806106a0826020602088068803016102800160006004601bf1505081815280905090509050602060c0825160208401600060025af161078057600080fd5b60c051905060208261088001015260208101905060006040602060208206610740016102805182840111156107b457600080fd5b606080610760826020602088068803016102800160006004601bf150508181528090509050905060208060208461080001018260208501600060046015f15050805182019150506105205160208261080001015260208101905080610800526108009050602060c0825160208401600060025af161083157600080fd5b60c051905060208261088001015260208101905080610880526108809050602060c0825160208401600060025af161086857600080fd5b60c051905061066052600060006105405160208261092001015260208101905061022060208060208461092001018260208501600060046015f150508051820191505080610920526109209050602060c0825160208401600060025af16108ce57600080fd5b60c0519050602082610aa00101526020810190506000610360600880602084610a2001018260208501600060046012f150508051820191505060006018602082066109a0016020828401111561092357600080fd5b6020806109c082610520600060046015f1505081815280905090509050601880602084610a2001018260208501600060046014f150508051820191505061066051602082610a2001015260208101905080610a2052610a209050602060c0825160208401600060025af161099657600080fd5b60c0519050602082610aa001015260208101905080610aa052610aa09050602060c0825160208401600060025af16109cd57600080fd5b60c051905061090052610b2060006020818352015b6104c051610b20511215610a62576000610b205160208110610a0357600080fd5b600160c052602060c0200154602082610b4001015260208101905061090051602082610b4001015260208101905080610b4052610b409050602060c0825160208401600060025af1610a5457600080fd5b60c051905061090052610a67565b610a78565b5b81516001018083528114156109e2575b5050610900516104c05160208110610a8f57600080fd5b600160c052602060c02001556002805460018254011015610aaf57600080fd5b60018154018155506060610c4060246380673289610bc0526104a051610be052610bdc6000305af1610ae057600080fd5b610c60805160200180610ca0828460006004600a8704601201f1610b0357600080fd5b505060a0610d2052610d2051610d60526101a0805160200180610d2051610d6001828460006004600a8704601201f1610b3b57600080fd5b5050610d2051610d60015160206001820306601f8201039050610d2051610d6001610d0081516040818352015b83610d0051101515610b7957610b96565b6000610d00516020850101535b8151600101808352811415610b68575b505050506020610d2051610d60015160206001820306601f8201039050610d20510101610d2052610d2051610d8052610220805160200180610d2051610d6001828460006004600a8704601201f1610bed57600080fd5b5050610d2051610d60015160206001820306601f8201039050610d2051610d6001610d0081516020818352015b83610d0051101515610c2b57610c48565b6000610d00516020850101535b8151600101808352811415610c1a575b505050506020610d2051610d60015160206001820306601f8201039050610d20510101610d2052610d2051610da052610360805160200180610d2051610d6001828460006004600a8704601201f1610c9f57600080fd5b5050610d2051610d60015160206001820306601f8201039050610d2051610d6001610d0081516020818352015b83610d0051101515610cdd57610cfa565b6000610d00516020850101535b8151600101808352811415610ccc575b505050506020610d2051610d60015160206001820306601f8201039050610d20510101610d2052610d2051610dc052610280805160200180610d2051610d6001828460006004600a8704601201f1610d5157600080fd5b5050610d2051610d60015160206001820306601f8201039050610d2051610d6001610d0081516060818352015b83610d0051101515610d8f57610dac565b6000610d00516020850101535b8151600101808352811415610d7e575b505050506020610d2051610d60015160206001820306601f8201039050610d20510101610d2052610d2051610de052610ca0805160200180610d2051610d6001828460006004600a8704601201f1610e0357600080fd5b5050610d2051610d60015160206001820306601f8201039050610d2051610d6001610d0081516020818352015b83610d0051101515610e4157610e5e565b6000610d00516020850101535b8151600101808352811415610e30575b505050506020610d2051610d60015160206001820306601f8201039050610d20510101610d20527fdc5fc95703516abd38fa03c3737ff3b52dc52347055c8028460fdf5bbe2f12ce610d2051610d60a1005b60006000fd5b61018561103b0361018560003961018561103b036000f3"} \ No newline at end of file diff --git a/deposit_contract/contracts/validator_registration.v.py b/deposit_contract/contracts/validator_registration.v.py index 1d475311a..c67ed2841 100644 --- a/deposit_contract/contracts/validator_registration.v.py +++ b/deposit_contract/contracts/validator_registration.v.py @@ -1,8 +1,5 @@ MIN_DEPOSIT_AMOUNT: constant(uint256) = 1000000000 # Gwei -FULL_DEPOSIT_AMOUNT: constant(uint256) = 32000000000 # Gwei -CHAIN_START_FULL_DEPOSIT_THRESHOLD: constant(uint256) = 65536 # 2**16 DEPOSIT_CONTRACT_TREE_DEPTH: constant(uint256) = 32 -SECONDS_PER_DAY: constant(uint256) = 86400 MAX_64_BIT_VALUE: constant(uint256) = 18446744073709551615 # 2**64 - 1 PUBKEY_LENGTH: constant(uint256) = 48 # bytes WITHDRAWAL_CREDENTIALS_LENGTH: constant(uint256) = 32 # bytes @@ -16,13 +13,10 @@ Deposit: event({ signature: bytes[96], merkle_tree_index: bytes[8], }) -Eth2Genesis: event({deposit_root: bytes32, deposit_count: bytes[8], time: bytes[8]}) zerohashes: bytes32[DEPOSIT_CONTRACT_TREE_DEPTH] branch: bytes32[DEPOSIT_CONTRACT_TREE_DEPTH] deposit_count: uint256 -full_deposit_count: uint256 -chainStarted: public(bool) @public @@ -30,7 +24,6 @@ def __init__(): for i in range(DEPOSIT_CONTRACT_TREE_DEPTH - 1): self.zerohashes[i+1] = sha256(concat(self.zerohashes[i], self.zerohashes[i])) - @public @constant def to_little_endian_64(value: uint256) -> bytes[8]: @@ -47,7 +40,6 @@ def to_little_endian_64(value: uint256) -> bytes[8]: return slice(convert(y, bytes32), start=24, len=8) - @public @constant def get_deposit_root() -> bytes32: @@ -124,17 +116,3 @@ def deposit(pubkey: bytes[PUBKEY_LENGTH], signature, self.to_little_endian_64(index), ) - - if deposit_amount >= FULL_DEPOSIT_AMOUNT: - self.full_deposit_count += 1 - if self.full_deposit_count == CHAIN_START_FULL_DEPOSIT_THRESHOLD: - timestamp_day_boundary: uint256 = ( - as_unitless_number(block.timestamp) - - as_unitless_number(block.timestamp) % SECONDS_PER_DAY + - 2 * SECONDS_PER_DAY - ) - new_deposit_root: bytes32 = self.get_deposit_root() - log.Eth2Genesis(new_deposit_root, - self.to_little_endian_64(self.deposit_count), - self.to_little_endian_64(timestamp_day_boundary)) - self.chainStarted = True diff --git a/deposit_contract/tests/contracts/conftest.py b/deposit_contract/tests/contracts/conftest.py index 69ece247d..b8b488abe 100644 --- a/deposit_contract/tests/contracts/conftest.py +++ b/deposit_contract/tests/contracts/conftest.py @@ -26,7 +26,6 @@ from .utils import ( # Constants MIN_DEPOSIT_AMOUNT = 1000000000 # Gwei FULL_DEPOSIT_AMOUNT = 32000000000 # Gwei -CHAIN_START_FULL_DEPOSIT_THRESHOLD = 65536 # 2**16 DEPOSIT_CONTRACT_TREE_DEPTH = 32 TWO_TO_POWER_OF_TREE_DEPTH = 2**DEPOSIT_CONTRACT_TREE_DEPTH @@ -63,28 +62,14 @@ def registration_contract(w3, tester): return registration_deployed -@pytest.fixture(scope="session") -def chain_start_full_deposit_thresholds(): - return [randint(1, 5), randint(6, 10), randint(11, 15)] - - @pytest.fixture(params=[0, 1, 2]) def modified_registration_contract( request, w3, - tester, - chain_start_full_deposit_thresholds): - # Set CHAIN_START_FULL_DEPOSIT_THRESHOLD to different threshold t + tester): registration_code = get_deposit_contract_code() - t = str(chain_start_full_deposit_thresholds[request.param]) - modified_registration_code = re.sub( - r'CHAIN_START_FULL_DEPOSIT_THRESHOLD: constant\(uint256\) = [0-9]+', - 'CHAIN_START_FULL_DEPOSIT_THRESHOLD: constant(uint256) = ' + t, - registration_code, - ) - assert modified_registration_code != registration_code - contract_bytecode = compiler.compile_code(modified_registration_code)['bytecode'] - contract_abi = compiler.mk_full_signature(modified_registration_code) + contract_bytecode = compiler.compile_code(registration_code)['bytecode'] + contract_abi = compiler.mk_full_signature(registration_code) registration = w3.eth.contract( abi=contract_abi, bytecode=contract_bytecode) @@ -94,11 +79,6 @@ def modified_registration_contract( address=tx_receipt.contractAddress, abi=contract_abi ) - setattr( - registration_deployed, - 'chain_start_full_deposit_threshold', - chain_start_full_deposit_thresholds[request.param] - ) return registration_deployed diff --git a/deposit_contract/tests/contracts/test_deposit.py b/deposit_contract/tests/contracts/test_deposit.py index 8492d6347..25c1a73bb 100644 --- a/deposit_contract/tests/contracts/test_deposit.py +++ b/deposit_contract/tests/contracts/test_deposit.py @@ -184,53 +184,3 @@ def test_deposit_tree(registration_contract, w3, assert_tx_failed, deposit_input leaf_nodes.append(hash_tree_root_result) root = compute_merkle_root(leaf_nodes) assert root == registration_contract.functions.get_deposit_root().call() - - -def test_chain_start(modified_registration_contract, w3, assert_tx_failed, deposit_input): - t = getattr(modified_registration_contract, 'chain_start_full_deposit_threshold') - # CHAIN_START_FULL_DEPOSIT_THRESHOLD is set to t - min_deposit_amount = MIN_DEPOSIT_AMOUNT * eth_utils.denoms.gwei # in wei - full_deposit_amount = FULL_DEPOSIT_AMOUNT * eth_utils.denoms.gwei - log_filter = modified_registration_contract.events.Eth2Genesis.createFilter( - fromBlock='latest', - ) - - index_not_full_deposit = randint(0, t - 1) - for i in range(t): - if i == index_not_full_deposit: - # Deposit with value below FULL_DEPOSIT_AMOUNT - modified_registration_contract.functions.deposit( - *deposit_input, - ).transact({"value": min_deposit_amount}) - logs = log_filter.get_new_entries() - # Eth2Genesis event should not be triggered - assert len(logs) == 0 - else: - # Deposit with value FULL_DEPOSIT_AMOUNT - modified_registration_contract.functions.deposit( - *deposit_input, - ).transact({"value": full_deposit_amount}) - logs = log_filter.get_new_entries() - # Eth2Genesis event should not be triggered - assert len(logs) == 0 - - # Make 1 more deposit with value FULL_DEPOSIT_AMOUNT to trigger Eth2Genesis event - modified_registration_contract.functions.deposit( - *deposit_input, - ).transact({"value": full_deposit_amount}) - logs = log_filter.get_new_entries() - assert len(logs) == 1 - timestamp = int(w3.eth.getBlock(w3.eth.blockNumber)['timestamp']) - timestamp_day_boundary = timestamp + (86400 - timestamp % 86400) + 86400 - log = logs[0]['args'] - assert log['deposit_root'] == modified_registration_contract.functions.get_deposit_root().call() - assert int.from_bytes(log['time'], byteorder='little') == timestamp_day_boundary - assert modified_registration_contract.functions.chainStarted().call() is True - - # Make 1 deposit with value FULL_DEPOSIT_AMOUNT and - # check that Eth2Genesis event is not triggered - modified_registration_contract.functions.deposit( - *deposit_input, - ).transact({"value": full_deposit_amount}) - logs = log_filter.get_new_entries() - assert len(logs) == 0 diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index a6d9d23c5..70e9e2b27 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -95,7 +95,7 @@ - [`initiate_validator_exit`](#initiate_validator_exit) - [`slash_validator`](#slash_validator) - [Genesis](#genesis) - - [`Eth2Genesis`](#eth2genesis) + - [Genesis trigger](#genesis-trigger) - [Genesis state](#genesis-state) - [Genesis block](#genesis-block) - [Beacon chain state transition function](#beacon-chain-state-transition-function) @@ -370,12 +370,12 @@ class PendingAttestation(Container): ```python class Eth1Data(Container): + # Block hash + block_hash: Bytes32 # Root of the deposit tree deposit_root: Bytes32 # Total number of deposits deposit_count: uint64 - # Block hash - block_hash: Bytes32 ``` #### `HistoricalBatch` @@ -1156,20 +1156,45 @@ def slash_validator(state: BeaconState, ## Genesis -### `Eth2Genesis` +### Genesis trigger -When enough deposits of size `MAX_EFFECTIVE_BALANCE` have been made to the deposit contract an `Eth2Genesis` log is emitted triggering the genesis of the beacon chain. Let: +Whenever the deposit contract emits a `Deposit` log call the function `is_genesis_trigger(deposits: List[Deposit], timestamp: uint64) -> bool` where: -* `eth2genesis` be the object corresponding to `Eth2Genesis` -* `genesis_eth1_data` be object of type `Eth1Data` where - * `genesis_eth1_data.deposit_root = eth2genesis.deposit_root` - * `genesis_eth1_data.deposit_count = eth2genesis.deposit_count` - * `genesis_eth1_data.block_hash` is the hash of the Ethereum 1.0 block that emitted the `Eth2Genesis` log -* `genesis_deposits` be the object of type `List[Deposit]` with deposits ordered chronologically up to and including the deposit that triggered the `Eth2Genesis` log +* `deposits` is the list of all deposits, ordered chronologically, up to and including the deposit triggering the latest `Deposit` log +* `timestamp` is the Unix timestamp in the Ethereum 1.0 block that emitted the latest `Deposit` log + +When `is_genesis_trigger(deposits, timestamp) == True` for the first time let: + +* `genesis_deposits = deposits` +* `genesis_time = timestamp % SECONDS_PER_DAY + 2 * SECONDS_PER_DAY` where `SECONDS_PER_DAY = 86400` +* `genesis_eth1_data` be the object of type `Eth1Data` where: + * `genesis_eth1_data.block_hash` is the block hash corresponding to `deposits` + * `genesis_eth1_data.deposit_root` is the deposit root corresponding to `deposits` + * `genesis_eth1_data.deposit_count = len(genesis_deposits)` + +*Note*: The function `is_genesis_trigger` has yet to be agreed by the community, and can be updated as necessary. We define the following testing placeholder: + +```python +def is_genesis_trigger(deposits: List[Deposit], timestamp: uint64) -> bool: + # Process deposits + state = BeaconState() + for deposit in deposits: + process_deposit(state, deposit) + + # Count active validators at genesis + active_validator_count = 0 + for validator in state.validator_registry: + if validator.effective_balance >= MAX_EFFECTIVE_BALANCE: + active_validator_count += 1 + + # Check effective balance to trigger genesis + GENESIS_EFFECTIVE_BALANCE = 2**21 + return active_validator_count * MAX_EFFECTIVE_BALANCE == GENESIS_EFFECTIVE_BALANCE +``` ### Genesis state -Let `genesis_state = get_genesis_beacon_state(genesis_deposits, eth2genesis.genesis_time, genesis_eth1_data)`. +Let `genesis_state = get_genesis_beacon_state(genesis_deposits, genesis_time, genesis_eth1_data)`. ```python def get_genesis_beacon_state(deposits: List[Deposit], genesis_time: int, genesis_eth1_data: Eth1Data) -> BeaconState: @@ -1246,7 +1271,7 @@ def process_slot(state: BeaconState) -> None: ### Epoch processing -Note: the `# @LabelHere` lines below are placeholders to show that code will be inserted here in a future phase. +*Note*: the `# @LabelHere` lines below are placeholders to show that code will be inserted here in a future phase. ```python def process_epoch(state: BeaconState) -> None: diff --git a/specs/core/0_deposit-contract.md b/specs/core/0_deposit-contract.md index 5d9398589..047e992c0 100644 --- a/specs/core/0_deposit-contract.md +++ b/specs/core/0_deposit-contract.md @@ -9,7 +9,6 @@ - [Table of contents](#table-of-contents) - [Introduction](#introduction) - [Constants](#constants) - - [Gwei values](#gwei-values) - [Contract](#contract) - [Ethereum 1.0 deposit contract](#ethereum-10-deposit-contract) - [Arguments](#arguments) @@ -17,7 +16,6 @@ - [Amount](#amount) - [Event logs](#event-logs) - [`Deposit` logs](#deposit-logs) - - [`Eth2Genesis` log](#eth2genesis-log) - [Vyper code](#vyper-code) @@ -28,19 +26,12 @@ This document represents the specification for the beacon chain deposit contract ## Constants -### Gwei values - -| Name | Value | Unit | -| - | - | - | -| `FULL_DEPOSIT_AMOUNT` | `32 * 10**9` | Gwei | - ### Contract | Name | Value | | - | - | | `DEPOSIT_CONTRACT_ADDRESS` | **TBD** | | `DEPOSIT_CONTRACT_TREE_DEPTH` | `2**5` (= 32) | -| `CHAIN_START_FULL_DEPOSIT_THRESHOLD` | `2**16` (= 65,536) | ## Ethereum 1.0 deposit contract @@ -62,7 +53,6 @@ The private key corresponding to `withdrawal_pubkey` will be required to initiat #### Amount * A valid deposit amount should be at least `MIN_DEPOSIT_AMOUNT` in Gwei. -* A deposit with an amount greater than or equal to `FULL_DEPOSIT_AMOUNT` in Gwei is considered as a full deposit. ## Event logs @@ -70,16 +60,6 @@ The private key corresponding to `withdrawal_pubkey` will be required to initiat Every Ethereum 1.0 deposit, of size at least `MIN_DEPOSIT_AMOUNT`, emits a `Deposit` log for consumption by the beacon chain. The deposit contract does little validation, pushing most of the validator onboarding logic to the beacon chain. In particular, the proof of possession (a BLS12-381 signature) is not verified by the deposit contract. -### `Eth2Genesis` log - -When `CHAIN_START_FULL_DEPOSIT_THRESHOLD` of full deposits have been made, the deposit contract emits the `Eth2Genesis` log. The beacon chain state may then be initialized by calling the `get_genesis_beacon_state` function (defined [here](./0_beacon-chain.md#genesis-state)) where: - -* `genesis_time` equals `time` in the `Eth2Genesis` log -* `latest_eth1_data.deposit_root` equals `deposit_root` in the `Eth2Genesis` log -* `latest_eth1_data.deposit_count` equals `deposit_count` in the `Eth2Genesis` log -* `latest_eth1_data.block_hash` equals the hash of the block that included the log -* `genesis_validator_deposits` is a list of `Deposit` objects built according to the `Deposit` logs up to the deposit that triggered the `Eth2Genesis` log, processed in the order in which they were emitted (oldest to newest) - ## Vyper code The source for the Vyper contract lives in a [separate repository](https://github.com/ethereum/deposit_contract) at [https://github.com/ethereum/deposit_contract/blob/master/deposit_contract/contracts/validator_registration.v.py](https://github.com/ethereum/deposit_contract/blob/master/deposit_contract/contracts/validator_registration.v.py). From 4ee00c9cbddd0872b2878897a1b56b43c0e56094 Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Sun, 9 Jun 2019 11:03:38 +0100 Subject: [PATCH 02/10] Address HW's comments --- .../contracts/validator_registration.v.py | 4 ++ specs/core/0_beacon-chain.md | 12 +++--- specs/core/0_deposit-contract.md | 37 +++++++------------ 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/deposit_contract/contracts/validator_registration.v.py b/deposit_contract/contracts/validator_registration.v.py index c67ed2841..0411bdb78 100644 --- a/deposit_contract/contracts/validator_registration.v.py +++ b/deposit_contract/contracts/validator_registration.v.py @@ -24,6 +24,7 @@ def __init__(): for i in range(DEPOSIT_CONTRACT_TREE_DEPTH - 1): self.zerohashes[i+1] = sha256(concat(self.zerohashes[i], self.zerohashes[i])) + @public @constant def to_little_endian_64(value: uint256) -> bytes[8]: @@ -40,6 +41,7 @@ def to_little_endian_64(value: uint256) -> bytes[8]: return slice(convert(y, bytes32), start=24, len=8) + @public @constant def get_deposit_root() -> bytes32: @@ -53,11 +55,13 @@ def get_deposit_root() -> bytes32: size /= 2 return root + @public @constant def get_deposit_count() -> bytes[8]: return self.to_little_endian_64(self.deposit_count) + @payable @public def deposit(pubkey: bytes[PUBKEY_LENGTH], diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 70e9e2b27..8cacde746 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1163,13 +1163,13 @@ Whenever the deposit contract emits a `Deposit` log call the function `is_genesi * `deposits` is the list of all deposits, ordered chronologically, up to and including the deposit triggering the latest `Deposit` log * `timestamp` is the Unix timestamp in the Ethereum 1.0 block that emitted the latest `Deposit` log -When `is_genesis_trigger(deposits, timestamp) == True` for the first time let: +When `is_genesis_trigger(deposits, timestamp) is True` for the first time let: * `genesis_deposits = deposits` * `genesis_time = timestamp % SECONDS_PER_DAY + 2 * SECONDS_PER_DAY` where `SECONDS_PER_DAY = 86400` * `genesis_eth1_data` be the object of type `Eth1Data` where: - * `genesis_eth1_data.block_hash` is the block hash corresponding to `deposits` - * `genesis_eth1_data.deposit_root` is the deposit root corresponding to `deposits` + * `genesis_eth1_data.block_hash` is the block hash for the last deposit in `deposits` + * `genesis_eth1_data.deposit_root` is the deposit root for the last deposit in `deposits` * `genesis_eth1_data.deposit_count = len(genesis_deposits)` *Note*: The function `is_genesis_trigger` has yet to be agreed by the community, and can be updated as necessary. We define the following testing placeholder: @@ -1184,12 +1184,12 @@ def is_genesis_trigger(deposits: List[Deposit], timestamp: uint64) -> bool: # Count active validators at genesis active_validator_count = 0 for validator in state.validator_registry: - if validator.effective_balance >= MAX_EFFECTIVE_BALANCE: + if validator.effective_balance == MAX_EFFECTIVE_BALANCE: active_validator_count += 1 # Check effective balance to trigger genesis - GENESIS_EFFECTIVE_BALANCE = 2**21 - return active_validator_count * MAX_EFFECTIVE_BALANCE == GENESIS_EFFECTIVE_BALANCE + GENESIS_ACTIVE_VALIDATOR_COUNT = 2**16 + return active_validator_count == GENESIS_ACTIVE_VALIDATOR_COUNT ``` ### Genesis state diff --git a/specs/core/0_deposit-contract.md b/specs/core/0_deposit-contract.md index 047e992c0..50f52fd37 100644 --- a/specs/core/0_deposit-contract.md +++ b/specs/core/0_deposit-contract.md @@ -11,11 +11,10 @@ - [Constants](#constants) - [Contract](#contract) - [Ethereum 1.0 deposit contract](#ethereum-10-deposit-contract) - - [Arguments](#arguments) + - [`deposit` function](#deposit-function) + - [Deposit amount](#deposit-amount) - [Withdrawal credentials](#withdrawal-credentials) - - [Amount](#amount) - - [Event logs](#event-logs) - - [`Deposit` logs](#deposit-logs) + - [`Deposit` log](#deposit-log) - [Vyper code](#vyper-code) @@ -37,37 +36,29 @@ This document represents the specification for the beacon chain deposit contract The initial deployment phases of Ethereum 2.0 are implemented without consensus changes to Ethereum 1.0. A deposit contract at address `DEPOSIT_CONTRACT_ADDRESS` is added to Ethereum 1.0 for deposits of ETH to the beacon chain. Validator balances will be withdrawable to the shards in Phase 2 (i.e. when the EVM 2.0 is deployed and the shards have state). -### Arguments +### `deposit` function -The deposit contract has a `deposit` function which takes the amount in Ethereum 1.0 transaction, and arguments `pubkey: bytes[48], withdrawal_credentials: bytes[32], signature: bytes[96]` corresponding to `DepositData`. +The deposit contract has a public `deposit` function to make deposits. It takes as arguments `pubkey: bytes[48], withdrawal_credentials: bytes[32], signature: bytes[96]` corresponding to a `DepositData` object. + +#### Deposit amount + +The ETH sent to the deposit contract, i.e. the deposit amount, is burnt on Ethereum 1.0. The minimum deposit amount is `MIN_DEPOSIT_AMOUNT` Gwei. #### Withdrawal credentials -One of the `DepositData` fields is `withdrawal_credentials`. It is a commitment to credentials for withdrawals to shards. The first byte of `withdrawal_credentials` is a version number. As of now, the only expected format is as follows: +One of the `DepositData` fields is `withdrawal_credentials`. It is a commitment to credentials for withdrawing validator balance (e.g. to another validator, or to shards). The first byte of `withdrawal_credentials` is a version number. As of now, the only expected format is as follows: * `withdrawal_credentials[:1] == BLS_WITHDRAWAL_PREFIX_BYTE` * `withdrawal_credentials[1:] == hash(withdrawal_pubkey)[1:]` where `withdrawal_pubkey` is a BLS pubkey The private key corresponding to `withdrawal_pubkey` will be required to initiate a withdrawal. It can be stored separately until a withdrawal is required, e.g. in cold storage. -#### Amount +#### `Deposit` log -* A valid deposit amount should be at least `MIN_DEPOSIT_AMOUNT` in Gwei. - -## Event logs - -### `Deposit` logs - -Every Ethereum 1.0 deposit, of size at least `MIN_DEPOSIT_AMOUNT`, emits a `Deposit` log for consumption by the beacon chain. The deposit contract does little validation, pushing most of the validator onboarding logic to the beacon chain. In particular, the proof of possession (a BLS12-381 signature) is not verified by the deposit contract. +Every Ethereum 1.0 deposit emits a `Deposit` log for consumption by the beacon chain. The deposit contract does little validation, pushing most of the validator onboarding logic to the beacon chain. In particular, the proof of possession (a BLS12-381 signature) is not verified by the deposit contract. ## Vyper code -The source for the Vyper contract lives in a [separate repository](https://github.com/ethereum/deposit_contract) at [https://github.com/ethereum/deposit_contract/blob/master/deposit_contract/contracts/validator_registration.v.py](https://github.com/ethereum/deposit_contract/blob/master/deposit_contract/contracts/validator_registration.v.py). +The deposit contract source code, written in Vyper, is available [here](https://github.com/ethereum/eth2.0-specs/blob/dev/deposit_contract/contracts/validator_registration.v.py). -*Note*: To save ~10x on gas, this contract uses a somewhat unintuitive progressive Merkle root calculation algo that requires only O(log(n)) storage. See https://github.com/ethereum/research/blob/master/beacon_chain_impl/progressive_merkle_tree.py for an implementation of the same algo in Python tested for correctness. - -For convenience, we provide the interface to the contract here: - -* `__init__()`: initializes the contract -* `get_deposit_root() -> bytes32`: returns the current root of the deposit tree -* `deposit(pubkey: bytes[48], withdrawal_credentials: bytes[32], signature: bytes[96])`: adds a deposit instance to the deposit tree, incorporating the input arguments and the value transferred in the given call. *Note*: The amount of value transferred *must* be at least `MIN_DEPOSIT_AMOUNT`. Each of these constants are specified in units of Gwei. +*Note*: To save on gas the deposit contract uses a progressive Merkle root calculation algorithm that requires only O(log(n)) storage. See [here](https://github.com/ethereum/research/blob/master/beacon_chain_impl/progressive_merkle_tree.py) for a Python implementation, and [here](https://github.com/runtimeverification/verified-smart-contracts/blob/master/deposit/formal-incremental-merkle-tree-algorithm.pdf) for a formal correctness proof. From c293b9dcef4d25a3a0ae4ebfe2a0405811b0d86d Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Sun, 9 Jun 2019 11:29:22 +0100 Subject: [PATCH 03/10] Cleanups --- .../contracts/validator_registration.json | 2 +- .../contracts/validator_registration.v.py | 91 +++++++------------ .../tests/contracts/test_deposit.py | 5 +- 3 files changed, 36 insertions(+), 62 deletions(-) diff --git a/deposit_contract/contracts/validator_registration.json b/deposit_contract/contracts/validator_registration.json index a885ef0a1..9da4a015c 100644 --- a/deposit_contract/contracts/validator_registration.json +++ b/deposit_contract/contracts/validator_registration.json @@ -1 +1 @@ -{"abi": [{"name": "Deposit", "inputs": [{"type": "bytes", "name": "pubkey", "indexed": false}, {"type": "bytes", "name": "withdrawal_credentials", "indexed": false}, {"type": "bytes", "name": "amount", "indexed": false}, {"type": "bytes", "name": "signature", "indexed": false}, {"type": "bytes", "name": "merkle_tree_index", "indexed": false}], "anonymous": false, "type": "event"}, {"outputs": [], "inputs": [], "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": 7077}, {"name": "get_deposit_root", "outputs": [{"type": "bytes32", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 79221}, {"name": "get_deposit_count", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 11026}, {"name": "deposit", "outputs": [], "inputs": [{"type": "bytes", "name": "pubkey"}, {"type": "bytes", "name": "withdrawal_credentials"}, {"type": "bytes", "name": "signature"}], "constant": false, "payable": true, "type": "function", "gas": 255244}], "bytecode": "0x600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009e57600080fd5b6101406000601f818352015b600061014051602081106100bd57600080fd5b600060c052602060c020015460208261016001015260208101905061014051602081106100e957600080fd5b600060c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012757600080fd5b60c0519050606051600161014051018060405190131561014657600080fd5b809190121561015457600080fd5b6020811061016157600080fd5b600060c052602060c02001555b81516001018083528114156100aa575b505061103b56600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a0526380673289600051141561026b57602060046101403734156100b457600080fd5b67ffffffffffffffff6101405111156100cc57600080fd5b60006101605261014051610180526101a060006008818352015b6101605160086000811215610103578060000360020a820461010a565b8060020a82025b905090506101605260ff61018051166101c052610160516101c0516101605101101561013557600080fd5b6101c051610160510161016052610180517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8600081121561017e578060000360020a8204610185565b8060020a82025b90509050610180525b81516001018083528114156100e6575b505060186008602082066101e001602082840111156101bc57600080fd5b60208061020082610160600060046015f15050818152809050905090508051602001806102a0828460006004600a8704601201f16101f957600080fd5b50506102a05160206001820306601f82010390506103006102a0516008818352015b8261030051111561022b57610247565b6000610300516102c001535b815160010180835281141561021b575b50505060206102805260406102a0510160206001820306601f8201039050610280f3005b63c5f2892f60005114156103c357341561028457600080fd5b6000610140526002546101605261018060006020818352015b600160016101605116141561031e57600061018051602081106102bf57600080fd5b600160c052602060c02001546020826102200101526020810190506101405160208261022001015260208101905080610220526102209050602060c0825160208401600060025af161031057600080fd5b60c05190506101405261038c565b6000610140516020826101a0010152602081019050610180516020811061034457600080fd5b600060c052602060c02001546020826101a0010152602081019050806101a0526101a09050602060c0825160208401600060025af161038257600080fd5b60c0519050610140525b610160600261039a57600080fd5b60028151048152505b815160010180835281141561029d575b50506101405160005260206000f3005b63621fd13060005114156104995734156103dc57600080fd5b60606101c060246380673289610140526002546101605261015c6000305af161040457600080fd5b6101e0805160200180610260828460006004600a8704601201f161042757600080fd5b50506102605160206001820306601f82010390506102c0610260516008818352015b826102c051111561045957610475565b60006102c05161028001535b8151600101808352811415610449575b5050506020610240526040610260510160206001820306601f8201039050610240f3005b63c47e300d6000511415610eb057606060046101403760506004356004016101a03760306004356004013511156104cf57600080fd5b60406024356004016102203760206024356004013511156104ef57600080fd5b608060443560040161028037606060443560040135111561050f57600080fd5b63ffffffff6002541061052157600080fd5b60306101a0511461053157600080fd5b6020610220511461054157600080fd5b6060610280511461055157600080fd5b633b9aca00610340526103405161056757600080fd5b61034051340461032052633b9aca0061032051101561058557600080fd5b6060610440602463806732896103c052610320516103e0526103dc6000305af16105ae57600080fd5b610460805160200180610360828460006004600a8704601201f16105d157600080fd5b50506002546104a05260006104c0526104a05160016104a0510110156105f657600080fd5b60016104a051016104e05261050060006020818352015b600160016104e05116141561062157610674565b6104c060605160018251018060405190131561063c57600080fd5b809190121561064a57600080fd5b8152506104e0600261065b57600080fd5b60028151048152505b815160010180835281141561060d575b505060006101a06030806020846105e001018260208501600060046016f1505080518201915050600060106020820661056001602082840111156106b757600080fd5b60208061058082610520600060046015f15050818152809050905090506010806020846105e001018260208501600060046013f1505080518201915050806105e0526105e09050602060c0825160208401600060025af161071757600080fd5b60c051905061054052600060006040602082066106800161028051828401111561074057600080fd5b6060806106a0826020602088068803016102800160006004601bf1505081815280905090509050602060c0825160208401600060025af161078057600080fd5b60c051905060208261088001015260208101905060006040602060208206610740016102805182840111156107b457600080fd5b606080610760826020602088068803016102800160006004601bf150508181528090509050905060208060208461080001018260208501600060046015f15050805182019150506105205160208261080001015260208101905080610800526108009050602060c0825160208401600060025af161083157600080fd5b60c051905060208261088001015260208101905080610880526108809050602060c0825160208401600060025af161086857600080fd5b60c051905061066052600060006105405160208261092001015260208101905061022060208060208461092001018260208501600060046015f150508051820191505080610920526109209050602060c0825160208401600060025af16108ce57600080fd5b60c0519050602082610aa00101526020810190506000610360600880602084610a2001018260208501600060046012f150508051820191505060006018602082066109a0016020828401111561092357600080fd5b6020806109c082610520600060046015f1505081815280905090509050601880602084610a2001018260208501600060046014f150508051820191505061066051602082610a2001015260208101905080610a2052610a209050602060c0825160208401600060025af161099657600080fd5b60c0519050602082610aa001015260208101905080610aa052610aa09050602060c0825160208401600060025af16109cd57600080fd5b60c051905061090052610b2060006020818352015b6104c051610b20511215610a62576000610b205160208110610a0357600080fd5b600160c052602060c0200154602082610b4001015260208101905061090051602082610b4001015260208101905080610b4052610b409050602060c0825160208401600060025af1610a5457600080fd5b60c051905061090052610a67565b610a78565b5b81516001018083528114156109e2575b5050610900516104c05160208110610a8f57600080fd5b600160c052602060c02001556002805460018254011015610aaf57600080fd5b60018154018155506060610c4060246380673289610bc0526104a051610be052610bdc6000305af1610ae057600080fd5b610c60805160200180610ca0828460006004600a8704601201f1610b0357600080fd5b505060a0610d2052610d2051610d60526101a0805160200180610d2051610d6001828460006004600a8704601201f1610b3b57600080fd5b5050610d2051610d60015160206001820306601f8201039050610d2051610d6001610d0081516040818352015b83610d0051101515610b7957610b96565b6000610d00516020850101535b8151600101808352811415610b68575b505050506020610d2051610d60015160206001820306601f8201039050610d20510101610d2052610d2051610d8052610220805160200180610d2051610d6001828460006004600a8704601201f1610bed57600080fd5b5050610d2051610d60015160206001820306601f8201039050610d2051610d6001610d0081516020818352015b83610d0051101515610c2b57610c48565b6000610d00516020850101535b8151600101808352811415610c1a575b505050506020610d2051610d60015160206001820306601f8201039050610d20510101610d2052610d2051610da052610360805160200180610d2051610d6001828460006004600a8704601201f1610c9f57600080fd5b5050610d2051610d60015160206001820306601f8201039050610d2051610d6001610d0081516020818352015b83610d0051101515610cdd57610cfa565b6000610d00516020850101535b8151600101808352811415610ccc575b505050506020610d2051610d60015160206001820306601f8201039050610d20510101610d2052610d2051610dc052610280805160200180610d2051610d6001828460006004600a8704601201f1610d5157600080fd5b5050610d2051610d60015160206001820306601f8201039050610d2051610d6001610d0081516060818352015b83610d0051101515610d8f57610dac565b6000610d00516020850101535b8151600101808352811415610d7e575b505050506020610d2051610d60015160206001820306601f8201039050610d20510101610d2052610d2051610de052610ca0805160200180610d2051610d6001828460006004600a8704601201f1610e0357600080fd5b5050610d2051610d60015160206001820306601f8201039050610d2051610d6001610d0081516020818352015b83610d0051101515610e4157610e5e565b6000610d00516020850101535b8151600101808352811415610e30575b505050506020610d2051610d60015160206001820306601f8201039050610d20510101610d20527fdc5fc95703516abd38fa03c3737ff3b52dc52347055c8028460fdf5bbe2f12ce610d2051610d60a1005b60006000fd5b61018561103b0361018560003961018561103b036000f3"} \ No newline at end of file +{"abi": [{"name": "Deposit", "inputs": [{"type": "bytes", "name": "pubkey", "indexed": false}, {"type": "bytes", "name": "withdrawal_credentials", "indexed": false}, {"type": "bytes", "name": "amount", "indexed": false}, {"type": "bytes", "name": "signature", "indexed": false}], "anonymous": false, "type": "event"}, {"outputs": [], "inputs": [], "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": 6973}, {"name": "get_deposit_root", "outputs": [{"type": "bytes32", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 79221}, {"name": "get_deposit_count", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 10922}, {"name": "deposit", "outputs": [], "inputs": [{"type": "bytes", "name": "pubkey"}, {"type": "bytes", "name": "withdrawal_credentials"}, {"type": "bytes", "name": "signature"}], "constant": false, "payable": true, "type": "function", "gas": 1318334}], "bytecode": "0x600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009e57600080fd5b6101406000601f818352015b600061014051602081106100bd57600080fd5b600260c052602060c020015460208261016001015260208101905061014051602081106100e957600080fd5b600260c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012757600080fd5b60c0519050606051600161014051018060405190131561014657600080fd5b809190121561015457600080fd5b6020811061016157600080fd5b600260c052602060c02001555b81516001018083528114156100aa575b5050610e9956600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a0526380673289600051141561025357602060046101403734156100b457600080fd5b60006101605261014051610180526101a060006008818352015b61016051600860008112156100eb578060000360020a82046100f2565b8060020a82025b905090506101605260ff61018051166101c052610160516101c0516101605101101561011d57600080fd5b6101c051610160510161016052610180517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff86000811215610166578060000360020a820461016d565b8060020a82025b90509050610180525b81516001018083528114156100ce575b505060186008602082066101e001602082840111156101a457600080fd5b60208061020082610160600060046015f15050818152809050905090508051602001806102a0828460006004600a8704601201f16101e157600080fd5b50506102a05160206001820306601f82010390506103006102a0516008818352015b826103005111156102135761022f565b6000610300516102c001535b8151600101808352811415610203575b50505060206102805260406102a0510160206001820306601f8201039050610280f3005b63c5f2892f60005114156103ab57341561026c57600080fd5b6000610140526001546101605261018060006020818352015b600160016101605116141561030657600061018051602081106102a757600080fd5b600060c052602060c02001546020826102200101526020810190506101405160208261022001015260208101905080610220526102209050602060c0825160208401600060025af16102f857600080fd5b60c051905061014052610374565b6000610140516020826101a0010152602081019050610180516020811061032c57600080fd5b600260c052602060c02001546020826101a0010152602081019050806101a0526101a09050602060c0825160208401600060025af161036a57600080fd5b60c0519050610140525b610160600261038257600080fd5b60028151048152505b8151600101808352811415610285575b50506101405160005260206000f3005b63621fd13060005114156104815734156103c457600080fd5b60606101c060246380673289610140526001546101605261015c6000305af16103ec57600080fd5b6101e0805160200180610260828460006004600a8704601201f161040f57600080fd5b50506102605160206001820306601f82010390506102c0610260516008818352015b826102c05111156104415761045d565b60006102c05161028001535b8151600101808352811415610431575b5050506020610240526040610260510160206001820306601f8201039050610240f3005b63c47e300d6000511415610d0e57606060046101403760506004356004016101a03760306004356004013511156104b757600080fd5b60406024356004016102203760206024356004013511156104d757600080fd5b60806044356004016102803760606044356004013511156104f757600080fd5b63ffffffff6001541061050957600080fd5b633b9aca00610340526103405161051f57600080fd5b61034051340461032052633b9aca0061032051101561053d57600080fd5b60306101a0511461054d57600080fd5b6020610220511461055d57600080fd5b6060610280511461056d57600080fd5b6060610440602463806732896103c052610320516103e0526103dc6000305af161059657600080fd5b610460805160200180610360828460006004600a8704601201f16105b957600080fd5b505060806104c0526104c051610500526101a08051602001806104c05161050001828460006004600a8704601201f16105f157600080fd5b50506104c051610500015160206001820306601f82010390506104c051610500016104a081516040818352015b836104a05110151561062f5761064c565b60006104a0516020850101535b815160010180835281141561061e575b5050505060206104c051610500015160206001820306601f82010390506104c05101016104c0526104c051610520526102208051602001806104c05161050001828460006004600a8704601201f16106a357600080fd5b50506104c051610500015160206001820306601f82010390506104c051610500016104a081516020818352015b836104a0511015156106e1576106fe565b60006104a0516020850101535b81516001018083528114156106d0575b5050505060206104c051610500015160206001820306601f82010390506104c05101016104c0526104c051610540526103608051602001806104c05161050001828460006004600a8704601201f161075557600080fd5b50506104c051610500015160206001820306601f82010390506104c051610500016104a081516020818352015b836104a051101515610793576107b0565b60006104a0516020850101535b8151600101808352811415610782575b5050505060206104c051610500015160206001820306601f82010390506104c05101016104c0526104c051610560526102808051602001806104c05161050001828460006004600a8704601201f161080757600080fd5b50506104c051610500015160206001820306601f82010390506104c051610500016104a081516060818352015b836104a05110151561084557610862565b60006104a0516020850101535b8151600101808352811415610834575b5050505060206104c051610500015160206001820306601f82010390506104c05101016104c0527f9d0a206c338cfcaf9198c04fe61b39a988e26b623ef97cb2f72bafcfbf8bb93e6104c051610500a160006101a060308060208461064001018260208501600060046016f150508051820191505060006010602082066105c001602082840111156108f357600080fd5b6020806105e082610580600060046015f150508181528090509050905060108060208461064001018260208501600060046013f150508051820191505080610640526106409050602060c0825160208401600060025af161095357600080fd5b60c05190506105a052600060006040602082066106e00161028051828401111561097c57600080fd5b606080610700826020602088068803016102800160006004601bf1505081815280905090509050602060c0825160208401600060025af16109bc57600080fd5b60c05190506020826108e0010152602081019050600060406020602082066107a0016102805182840111156109f057600080fd5b6060806107c0826020602088068803016102800160006004601bf150508181528090509050905060208060208461086001018260208501600060046015f15050805182019150506105805160208261086001015260208101905080610860526108609050602060c0825160208401600060025af1610a6d57600080fd5b60c05190506020826108e0010152602081019050806108e0526108e09050602060c0825160208401600060025af1610aa457600080fd5b60c05190506106c052600060006105a05160208261098001015260208101905061022060208060208461098001018260208501600060046015f150508051820191505080610980526109809050602060c0825160208401600060025af1610b0a57600080fd5b60c0519050602082610b000101526020810190506000610360600880602084610a8001018260208501600060046012f15050805182019150506000601860208206610a000160208284011115610b5f57600080fd5b602080610a2082610580600060046015f1505081815280905090509050601880602084610a8001018260208501600060046014f15050805182019150506106c051602082610a8001015260208101905080610a8052610a809050602060c0825160208401600060025af1610bd257600080fd5b60c0519050602082610b0001015260208101905080610b0052610b009050602060c0825160208401600060025af1610c0957600080fd5b60c0519050610960526001805460018254011015610c2657600080fd5b6001815401815550600154610b8052610ba060006020818352015b60016001610b8051161415610c765761096051610ba05160208110610c6557600080fd5b600060c052602060c0200155610d0a565b6000610ba05160208110610c8957600080fd5b600060c052602060c0200154602082610bc001015260208101905061096051602082610bc001015260208101905080610bc052610bc09050602060c0825160208401600060025af1610cda57600080fd5b60c051905061096052610b806002610cf157600080fd5b60028151048152505b8151600101808352811415610c41575b5050005b60006000fd5b610185610e9903610185600039610185610e99036000f3"} \ No newline at end of file diff --git a/deposit_contract/contracts/validator_registration.v.py b/deposit_contract/contracts/validator_registration.v.py index 0411bdb78..6c4bd7dc7 100644 --- a/deposit_contract/contracts/validator_registration.v.py +++ b/deposit_contract/contracts/validator_registration.v.py @@ -1,59 +1,54 @@ MIN_DEPOSIT_AMOUNT: constant(uint256) = 1000000000 # Gwei DEPOSIT_CONTRACT_TREE_DEPTH: constant(uint256) = 32 -MAX_64_BIT_VALUE: constant(uint256) = 18446744073709551615 # 2**64 - 1 PUBKEY_LENGTH: constant(uint256) = 48 # bytes WITHDRAWAL_CREDENTIALS_LENGTH: constant(uint256) = 32 # bytes +AMOUNT_LENGTH: constant(uint256) = 8 # bytes SIGNATURE_LENGTH: constant(uint256) = 96 # bytes -MAX_DEPOSIT_COUNT: constant(uint256) = 4294967295 # 2**DEPOSIT_CONTRACT_TREE_DEPTH - 1 Deposit: event({ pubkey: bytes[48], withdrawal_credentials: bytes[32], amount: bytes[8], signature: bytes[96], - merkle_tree_index: bytes[8], }) -zerohashes: bytes32[DEPOSIT_CONTRACT_TREE_DEPTH] branch: bytes32[DEPOSIT_CONTRACT_TREE_DEPTH] deposit_count: uint256 - +# Compute hashes in empty sparse Merkle tree +zero_hashes: bytes32[DEPOSIT_CONTRACT_TREE_DEPTH] @public def __init__(): for i in range(DEPOSIT_CONTRACT_TREE_DEPTH - 1): - self.zerohashes[i+1] = sha256(concat(self.zerohashes[i], self.zerohashes[i])) + self.zero_hashes[i + 1] = sha256(concat(self.zero_hashes[i], self.zero_hashes[i])) @public @constant def to_little_endian_64(value: uint256) -> bytes[8]: - assert value <= MAX_64_BIT_VALUE - - # array access for bytes[] not currently supported in vyper so - # reversing bytes using bitwise uint256 manipulations + # Reversing bytes using bitwise uint256 manipulations + # (array accesses of bytes[] are not currently supported in Vyper) y: uint256 = 0 x: uint256 = value - for i in range(8): + for _ in range(8): y = shift(y, 8) y = y + bitwise_and(x, 255) x = shift(x, -8) - return slice(convert(y, bytes32), start=24, len=8) @public @constant def get_deposit_root() -> bytes32: - root: bytes32 = 0x0000000000000000000000000000000000000000000000000000000000000000 + node: bytes32 = 0x0000000000000000000000000000000000000000000000000000000000000000 size: uint256 = self.deposit_count - for h in range(DEPOSIT_CONTRACT_TREE_DEPTH): - if bitwise_and(size, 1) == 1: - root = sha256(concat(self.branch[h], root)) + for height in range(DEPOSIT_CONTRACT_TREE_DEPTH): + if bitwise_and(size, 1) == 1: # More gas efficient than `size % 2 == 1` + node = sha256(concat(self.branch[height], node)) else: - root = sha256(concat(root, self.zerohashes[h])) + node = sha256(concat(node, self.zero_hashes[height])) size /= 2 - return root + return node @public @@ -67,56 +62,38 @@ def get_deposit_count() -> bytes[8]: def deposit(pubkey: bytes[PUBKEY_LENGTH], withdrawal_credentials: bytes[WITHDRAWAL_CREDENTIALS_LENGTH], signature: bytes[SIGNATURE_LENGTH]): - # Prevent edge case in computing `self.branch` when `self.deposit_count == MAX_DEPOSIT_COUNT` - # NOTE: reaching this point with the constants as currently defined is impossible due to the - # uni-directional nature of transfers from eth1 to eth2 and the total ether supply (< 130M). - assert self.deposit_count < MAX_DEPOSIT_COUNT + # Avoid overflowing the Merkle tree + assert self.deposit_count < 2**DEPOSIT_CONTRACT_TREE_DEPTH - 1 + # Validate deposit data + deposit_amount: uint256 = msg.value / as_wei_value(1, "gwei") + assert deposit_amount >= MIN_DEPOSIT_AMOUNT assert len(pubkey) == PUBKEY_LENGTH assert len(withdrawal_credentials) == WITHDRAWAL_CREDENTIALS_LENGTH assert len(signature) == SIGNATURE_LENGTH - deposit_amount: uint256 = msg.value / as_wei_value(1, "gwei") - assert deposit_amount >= MIN_DEPOSIT_AMOUNT + # Emit `Deposit` log amount: bytes[8] = self.to_little_endian_64(deposit_amount) + log.Deposit(pubkey, withdrawal_credentials, amount, signature) - index: uint256 = self.deposit_count - - # add deposit to merkle tree - i: int128 = 0 - size: uint256 = index + 1 - for _ in range(DEPOSIT_CONTRACT_TREE_DEPTH): - if bitwise_and(size, 1) == 1: - break - i += 1 - size /= 2 - - zero_bytes_32: bytes32 - pubkey_root: bytes32 = sha256(concat(pubkey, slice(zero_bytes_32, start=0, len=16))) + # Compute `DepositData` root + zero_bytes32: bytes32 + pubkey_root: bytes32 = sha256(concat(pubkey, slice(zero_bytes32, start=0, len=64 - PUBKEY_LENGTH))) signature_root: bytes32 = sha256(concat( sha256(slice(signature, start=0, len=64)), - sha256(concat(slice(signature, start=64, len=32), zero_bytes_32)) + sha256(concat(slice(signature, start=64, len=SIGNATURE_LENGTH - 64), zero_bytes32)), )) - value: bytes32 = sha256(concat( + node: bytes32 = sha256(concat( sha256(concat(pubkey_root, withdrawal_credentials)), - sha256(concat( - amount, - slice(zero_bytes_32, start=0, len=24), - signature_root, - )) + sha256(concat(amount, slice(zero_bytes32, start=0, len=32 - AMOUNT_LENGTH), signature_root)), )) - for j in range(DEPOSIT_CONTRACT_TREE_DEPTH): - if j < i: - value = sha256(concat(self.branch[j], value)) - else: - break - self.branch[i] = value + # Add `DepositData` root to Merkle tree (update a single `branch` node) self.deposit_count += 1 - log.Deposit( - pubkey, - withdrawal_credentials, - amount, - signature, - self.to_little_endian_64(index), - ) + size: uint256 = self.deposit_count + for height in range(DEPOSIT_CONTRACT_TREE_DEPTH): + if bitwise_and(size, 1) == 1: # More gas efficient than `size % 2 == 1` + self.branch[height] = node + break + node = sha256(concat(self.branch[height], node)) + size /= 2 diff --git a/deposit_contract/tests/contracts/test_deposit.py b/deposit_contract/tests/contracts/test_deposit.py index 25c1a73bb..c1c07aac9 100644 --- a/deposit_contract/tests/contracts/test_deposit.py +++ b/deposit_contract/tests/contracts/test_deposit.py @@ -56,7 +56,7 @@ def deposit_input(): (10, True), (55555, True), (2**64 - 1, True), - (2**64, False), + (2**64, True), # Note that all calls to `to_little_endian_64` have an input less than 2**64 ] ) def test_to_little_endian_64(registration_contract, value, success, assert_tx_failed): @@ -151,7 +151,6 @@ def test_deposit_log(registration_contract, a0, w3, deposit_input): assert log['withdrawal_credentials'] == deposit_input[1] assert log['amount'] == deposit_amount_list[i].to_bytes(8, 'little') assert log['signature'] == deposit_input[2] - assert log['merkle_tree_index'] == i.to_bytes(8, 'little') def test_deposit_tree(registration_contract, w3, assert_tx_failed, deposit_input): @@ -172,8 +171,6 @@ def test_deposit_tree(registration_contract, w3, assert_tx_failed, deposit_input assert len(logs) == 1 log = logs[0]['args'] - assert log["merkle_tree_index"] == i.to_bytes(8, 'little') - deposit_data = DepositData( pubkey=deposit_input[0], withdrawal_credentials=deposit_input[1], From 29129d06cf762889312ed6eeeec783751d76cda7 Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Sun, 9 Jun 2019 17:03:35 +0100 Subject: [PATCH 04/10] Fix tests --- deposit_contract/contracts/validator_registration.json | 2 +- deposit_contract/contracts/validator_registration.v.py | 8 ++++---- deposit_contract/tests/contracts/test_deposit.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/deposit_contract/contracts/validator_registration.json b/deposit_contract/contracts/validator_registration.json index 9da4a015c..676bf470a 100644 --- a/deposit_contract/contracts/validator_registration.json +++ b/deposit_contract/contracts/validator_registration.json @@ -1 +1 @@ -{"abi": [{"name": "Deposit", "inputs": [{"type": "bytes", "name": "pubkey", "indexed": false}, {"type": "bytes", "name": "withdrawal_credentials", "indexed": false}, {"type": "bytes", "name": "amount", "indexed": false}, {"type": "bytes", "name": "signature", "indexed": false}], "anonymous": false, "type": "event"}, {"outputs": [], "inputs": [], "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": 6973}, {"name": "get_deposit_root", "outputs": [{"type": "bytes32", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 79221}, {"name": "get_deposit_count", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 10922}, {"name": "deposit", "outputs": [], "inputs": [{"type": "bytes", "name": "pubkey"}, {"type": "bytes", "name": "withdrawal_credentials"}, {"type": "bytes", "name": "signature"}], "constant": false, "payable": true, "type": "function", "gas": 1318334}], "bytecode": "0x600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009e57600080fd5b6101406000601f818352015b600061014051602081106100bd57600080fd5b600260c052602060c020015460208261016001015260208101905061014051602081106100e957600080fd5b600260c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012757600080fd5b60c0519050606051600161014051018060405190131561014657600080fd5b809190121561015457600080fd5b6020811061016157600080fd5b600260c052602060c02001555b81516001018083528114156100aa575b5050610e9956600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a0526380673289600051141561025357602060046101403734156100b457600080fd5b60006101605261014051610180526101a060006008818352015b61016051600860008112156100eb578060000360020a82046100f2565b8060020a82025b905090506101605260ff61018051166101c052610160516101c0516101605101101561011d57600080fd5b6101c051610160510161016052610180517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff86000811215610166578060000360020a820461016d565b8060020a82025b90509050610180525b81516001018083528114156100ce575b505060186008602082066101e001602082840111156101a457600080fd5b60208061020082610160600060046015f15050818152809050905090508051602001806102a0828460006004600a8704601201f16101e157600080fd5b50506102a05160206001820306601f82010390506103006102a0516008818352015b826103005111156102135761022f565b6000610300516102c001535b8151600101808352811415610203575b50505060206102805260406102a0510160206001820306601f8201039050610280f3005b63c5f2892f60005114156103ab57341561026c57600080fd5b6000610140526001546101605261018060006020818352015b600160016101605116141561030657600061018051602081106102a757600080fd5b600060c052602060c02001546020826102200101526020810190506101405160208261022001015260208101905080610220526102209050602060c0825160208401600060025af16102f857600080fd5b60c051905061014052610374565b6000610140516020826101a0010152602081019050610180516020811061032c57600080fd5b600260c052602060c02001546020826101a0010152602081019050806101a0526101a09050602060c0825160208401600060025af161036a57600080fd5b60c0519050610140525b610160600261038257600080fd5b60028151048152505b8151600101808352811415610285575b50506101405160005260206000f3005b63621fd13060005114156104815734156103c457600080fd5b60606101c060246380673289610140526001546101605261015c6000305af16103ec57600080fd5b6101e0805160200180610260828460006004600a8704601201f161040f57600080fd5b50506102605160206001820306601f82010390506102c0610260516008818352015b826102c05111156104415761045d565b60006102c05161028001535b8151600101808352811415610431575b5050506020610240526040610260510160206001820306601f8201039050610240f3005b63c47e300d6000511415610d0e57606060046101403760506004356004016101a03760306004356004013511156104b757600080fd5b60406024356004016102203760206024356004013511156104d757600080fd5b60806044356004016102803760606044356004013511156104f757600080fd5b63ffffffff6001541061050957600080fd5b633b9aca00610340526103405161051f57600080fd5b61034051340461032052633b9aca0061032051101561053d57600080fd5b60306101a0511461054d57600080fd5b6020610220511461055d57600080fd5b6060610280511461056d57600080fd5b6060610440602463806732896103c052610320516103e0526103dc6000305af161059657600080fd5b610460805160200180610360828460006004600a8704601201f16105b957600080fd5b505060806104c0526104c051610500526101a08051602001806104c05161050001828460006004600a8704601201f16105f157600080fd5b50506104c051610500015160206001820306601f82010390506104c051610500016104a081516040818352015b836104a05110151561062f5761064c565b60006104a0516020850101535b815160010180835281141561061e575b5050505060206104c051610500015160206001820306601f82010390506104c05101016104c0526104c051610520526102208051602001806104c05161050001828460006004600a8704601201f16106a357600080fd5b50506104c051610500015160206001820306601f82010390506104c051610500016104a081516020818352015b836104a0511015156106e1576106fe565b60006104a0516020850101535b81516001018083528114156106d0575b5050505060206104c051610500015160206001820306601f82010390506104c05101016104c0526104c051610540526103608051602001806104c05161050001828460006004600a8704601201f161075557600080fd5b50506104c051610500015160206001820306601f82010390506104c051610500016104a081516020818352015b836104a051101515610793576107b0565b60006104a0516020850101535b8151600101808352811415610782575b5050505060206104c051610500015160206001820306601f82010390506104c05101016104c0526104c051610560526102808051602001806104c05161050001828460006004600a8704601201f161080757600080fd5b50506104c051610500015160206001820306601f82010390506104c051610500016104a081516060818352015b836104a05110151561084557610862565b60006104a0516020850101535b8151600101808352811415610834575b5050505060206104c051610500015160206001820306601f82010390506104c05101016104c0527f9d0a206c338cfcaf9198c04fe61b39a988e26b623ef97cb2f72bafcfbf8bb93e6104c051610500a160006101a060308060208461064001018260208501600060046016f150508051820191505060006010602082066105c001602082840111156108f357600080fd5b6020806105e082610580600060046015f150508181528090509050905060108060208461064001018260208501600060046013f150508051820191505080610640526106409050602060c0825160208401600060025af161095357600080fd5b60c05190506105a052600060006040602082066106e00161028051828401111561097c57600080fd5b606080610700826020602088068803016102800160006004601bf1505081815280905090509050602060c0825160208401600060025af16109bc57600080fd5b60c05190506020826108e0010152602081019050600060406020602082066107a0016102805182840111156109f057600080fd5b6060806107c0826020602088068803016102800160006004601bf150508181528090509050905060208060208461086001018260208501600060046015f15050805182019150506105805160208261086001015260208101905080610860526108609050602060c0825160208401600060025af1610a6d57600080fd5b60c05190506020826108e0010152602081019050806108e0526108e09050602060c0825160208401600060025af1610aa457600080fd5b60c05190506106c052600060006105a05160208261098001015260208101905061022060208060208461098001018260208501600060046015f150508051820191505080610980526109809050602060c0825160208401600060025af1610b0a57600080fd5b60c0519050602082610b000101526020810190506000610360600880602084610a8001018260208501600060046012f15050805182019150506000601860208206610a000160208284011115610b5f57600080fd5b602080610a2082610580600060046015f1505081815280905090509050601880602084610a8001018260208501600060046014f15050805182019150506106c051602082610a8001015260208101905080610a8052610a809050602060c0825160208401600060025af1610bd257600080fd5b60c0519050602082610b0001015260208101905080610b0052610b009050602060c0825160208401600060025af1610c0957600080fd5b60c0519050610960526001805460018254011015610c2657600080fd5b6001815401815550600154610b8052610ba060006020818352015b60016001610b8051161415610c765761096051610ba05160208110610c6557600080fd5b600060c052602060c0200155610d0a565b6000610ba05160208110610c8957600080fd5b600060c052602060c0200154602082610bc001015260208101905061096051602082610bc001015260208101905080610bc052610bc09050602060c0825160208401600060025af1610cda57600080fd5b60c051905061096052610b806002610cf157600080fd5b60028151048152505b8151600101808352811415610c41575b5050005b60006000fd5b610185610e9903610185600039610185610e99036000f3"} \ No newline at end of file +{"abi": [{"name": "Deposit", "inputs": [{"type": "bytes", "name": "pubkey", "indexed": false}, {"type": "bytes", "name": "withdrawal_credentials", "indexed": false}, {"type": "bytes", "name": "amount", "indexed": false}, {"type": "bytes", "name": "signature", "indexed": false}], "anonymous": false, "type": "event"}, {"outputs": [], "inputs": [], "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": 6973}, {"name": "get_deposit_root", "outputs": [{"type": "bytes32", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 79221}, {"name": "get_deposit_count", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 10922}, {"name": "deposit", "outputs": [], "inputs": [{"type": "bytes", "name": "pubkey"}, {"type": "bytes", "name": "withdrawal_credentials"}, {"type": "bytes", "name": "signature"}], "constant": false, "payable": true, "type": "function", "gas": 1318334}], "bytecode": "0x600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009e57600080fd5b6101406000601f818352015b600061014051602081106100bd57600080fd5b600260c052602060c020015460208261016001015260208101905061014051602081106100e957600080fd5b600260c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012757600080fd5b60c0519050606051600161014051018060405190131561014657600080fd5b809190121561015457600080fd5b6020811061016157600080fd5b600260c052602060c02001555b81516001018083528114156100aa575b5050610e9956600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a0526380673289600051141561025357602060046101403734156100b457600080fd5b60006101605261014051610180526101a060006008818352015b61016051600860008112156100eb578060000360020a82046100f2565b8060020a82025b905090506101605260ff61018051166101c052610160516101c0516101605101101561011d57600080fd5b6101c051610160510161016052610180517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff86000811215610166578060000360020a820461016d565b8060020a82025b90509050610180525b81516001018083528114156100ce575b505060186008602082066101e001602082840111156101a457600080fd5b60208061020082610160600060046015f15050818152809050905090508051602001806102a0828460006004600a8704601201f16101e157600080fd5b50506102a05160206001820306601f82010390506103006102a0516008818352015b826103005111156102135761022f565b6000610300516102c001535b8151600101808352811415610203575b50505060206102805260406102a0510160206001820306601f8201039050610280f3005b63c5f2892f60005114156103ab57341561026c57600080fd5b6000610140526001546101605261018060006020818352015b600160016101605116141561030657600061018051602081106102a757600080fd5b600060c052602060c02001546020826102200101526020810190506101405160208261022001015260208101905080610220526102209050602060c0825160208401600060025af16102f857600080fd5b60c051905061014052610374565b6000610140516020826101a0010152602081019050610180516020811061032c57600080fd5b600260c052602060c02001546020826101a0010152602081019050806101a0526101a09050602060c0825160208401600060025af161036a57600080fd5b60c0519050610140525b610160600261038257600080fd5b60028151048152505b8151600101808352811415610285575b50506101405160005260206000f3005b63621fd13060005114156104815734156103c457600080fd5b60606101c060246380673289610140526001546101605261015c6000305af16103ec57600080fd5b6101e0805160200180610260828460006004600a8704601201f161040f57600080fd5b50506102605160206001820306601f82010390506102c0610260516008818352015b826102c05111156104415761045d565b60006102c05161028001535b8151600101808352811415610431575b5050506020610240526040610260510160206001820306601f8201039050610240f3005b63c47e300d6000511415610d0e57606060046101403760506004356004016101a03760306004356004013511156104b757600080fd5b60406024356004016102203760206024356004013511156104d757600080fd5b60806044356004016102803760606044356004013511156104f757600080fd5b63ffffffff6001541061050957600080fd5b633b9aca00610340526103405161051f57600080fd5b61034051340461032052633b9aca0061032051101561053d57600080fd5b60306101a0511461054d57600080fd5b6020610220511461055d57600080fd5b6060610280511461056d57600080fd5b6060610440602463806732896103c052610320516103e0526103dc6000305af161059657600080fd5b610460805160200180610360828460006004600a8704601201f16105b957600080fd5b505060006101a060308060208461056001018260208501600060046016f150508051820191505060006010602082066104e001602082840111156105fc57600080fd5b602080610500826104a0600060046015f150508181528090509050905060108060208461056001018260208501600060046013f150508051820191505080610560526105609050602060c0825160208401600060025af161065c57600080fd5b60c05190506104c052600060006040602082066106000161028051828401111561068557600080fd5b606080610620826020602088068803016102800160006004601bf1505081815280905090509050602060c0825160208401600060025af16106c557600080fd5b60c0519050602082610800010152602081019050600060406020602082066106c0016102805182840111156106f957600080fd5b6060806106e0826020602088068803016102800160006004601bf150508181528090509050905060208060208461078001018260208501600060046015f15050805182019150506104a05160208261078001015260208101905080610780526107809050602060c0825160208401600060025af161077657600080fd5b60c051905060208261080001015260208101905080610800526108009050602060c0825160208401600060025af16107ad57600080fd5b60c05190506105e052600060006104c0516020826108a00101526020810190506102206020806020846108a001018260208501600060046015f1505080518201915050806108a0526108a09050602060c0825160208401600060025af161081357600080fd5b60c0519050602082610a2001015260208101905060006103606008806020846109a001018260208501600060046012f15050805182019150506000601860208206610920016020828401111561086857600080fd5b602080610940826104a0600060046015f15050818152809050905090506018806020846109a001018260208501600060046014f15050805182019150506105e0516020826109a0010152602081019050806109a0526109a09050602060c0825160208401600060025af16108db57600080fd5b60c0519050602082610a2001015260208101905080610a2052610a209050602060c0825160208401600060025af161091257600080fd5b60c051905061088052600180546001825401101561092f57600080fd5b6001815401815550600154610aa052610ac060006020818352015b60016001610aa05116141561097f5761088051610ac0516020811061096e57600080fd5b600060c052602060c0200155610a13565b6000610ac0516020811061099257600080fd5b600060c052602060c0200154602082610ae001015260208101905061088051602082610ae001015260208101905080610ae052610ae09050602060c0825160208401600060025af16109e357600080fd5b60c051905061088052610aa060026109fa57600080fd5b60028151048152505b815160010180835281141561094a575b50506080610b8052610b8051610bc0526101a0805160200180610b8051610bc001828460006004600a8704601201f1610a4b57600080fd5b5050610b8051610bc0015160206001820306601f8201039050610b8051610bc001610b6081516040818352015b83610b6051101515610a8957610aa6565b6000610b60516020850101535b8151600101808352811415610a78575b505050506020610b8051610bc0015160206001820306601f8201039050610b80510101610b8052610b8051610be052610220805160200180610b8051610bc001828460006004600a8704601201f1610afd57600080fd5b5050610b8051610bc0015160206001820306601f8201039050610b8051610bc001610b6081516020818352015b83610b6051101515610b3b57610b58565b6000610b60516020850101535b8151600101808352811415610b2a575b505050506020610b8051610bc0015160206001820306601f8201039050610b80510101610b8052610b8051610c0052610360805160200180610b8051610bc001828460006004600a8704601201f1610baf57600080fd5b5050610b8051610bc0015160206001820306601f8201039050610b8051610bc001610b6081516020818352015b83610b6051101515610bed57610c0a565b6000610b60516020850101535b8151600101808352811415610bdc575b505050506020610b8051610bc0015160206001820306601f8201039050610b80510101610b8052610b8051610c2052610280805160200180610b8051610bc001828460006004600a8704601201f1610c6157600080fd5b5050610b8051610bc0015160206001820306601f8201039050610b8051610bc001610b6081516060818352015b83610b6051101515610c9f57610cbc565b6000610b60516020850101535b8151600101808352811415610c8e575b505050506020610b8051610bc0015160206001820306601f8201039050610b80510101610b80527f9d0a206c338cfcaf9198c04fe61b39a988e26b623ef97cb2f72bafcfbf8bb93e610b8051610bc0a1005b60006000fd5b610185610e9903610185600039610185610e99036000f3"} \ No newline at end of file diff --git a/deposit_contract/contracts/validator_registration.v.py b/deposit_contract/contracts/validator_registration.v.py index 6c4bd7dc7..b99a30784 100644 --- a/deposit_contract/contracts/validator_registration.v.py +++ b/deposit_contract/contracts/validator_registration.v.py @@ -72,11 +72,8 @@ def deposit(pubkey: bytes[PUBKEY_LENGTH], assert len(withdrawal_credentials) == WITHDRAWAL_CREDENTIALS_LENGTH assert len(signature) == SIGNATURE_LENGTH - # Emit `Deposit` log - amount: bytes[8] = self.to_little_endian_64(deposit_amount) - log.Deposit(pubkey, withdrawal_credentials, amount, signature) - # Compute `DepositData` root + amount: bytes[8] = self.to_little_endian_64(deposit_amount) zero_bytes32: bytes32 pubkey_root: bytes32 = sha256(concat(pubkey, slice(zero_bytes32, start=0, len=64 - PUBKEY_LENGTH))) signature_root: bytes32 = sha256(concat( @@ -97,3 +94,6 @@ def deposit(pubkey: bytes[PUBKEY_LENGTH], break node = sha256(concat(self.branch[height], node)) size /= 2 + + # Emit `Deposit` log + log.Deposit(pubkey, withdrawal_credentials, amount, signature) diff --git a/deposit_contract/tests/contracts/test_deposit.py b/deposit_contract/tests/contracts/test_deposit.py index c1c07aac9..12f3e7f8b 100644 --- a/deposit_contract/tests/contracts/test_deposit.py +++ b/deposit_contract/tests/contracts/test_deposit.py @@ -56,7 +56,7 @@ def deposit_input(): (10, True), (55555, True), (2**64 - 1, True), - (2**64, True), # Note that all calls to `to_little_endian_64` have an input less than 2**64 + # (2**64, True), # Note that all calls to `to_little_endian_64` have an input less than 2**64 ] ) def test_to_little_endian_64(registration_contract, value, success, assert_tx_failed): From 9bb0f25f18198a5e02b3290f5d5eee025d8c68a1 Mon Sep 17 00:00:00 2001 From: Justin Date: Mon, 10 Jun 2019 13:41:28 +0100 Subject: [PATCH 05/10] Update specs/core/0_beacon-chain.md Co-Authored-By: NIC Lin --- specs/core/0_beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 8cacde746..543f20d59 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1166,7 +1166,7 @@ Whenever the deposit contract emits a `Deposit` log call the function `is_genesi When `is_genesis_trigger(deposits, timestamp) is True` for the first time let: * `genesis_deposits = deposits` -* `genesis_time = timestamp % SECONDS_PER_DAY + 2 * SECONDS_PER_DAY` where `SECONDS_PER_DAY = 86400` +* `genesis_time = timestamp - timestamp % SECONDS_PER_DAY + 2 * SECONDS_PER_DAY` where `SECONDS_PER_DAY = 86400` * `genesis_eth1_data` be the object of type `Eth1Data` where: * `genesis_eth1_data.block_hash` is the block hash for the last deposit in `deposits` * `genesis_eth1_data.deposit_root` is the deposit root for the last deposit in `deposits` From 4d6a25f16101782ff41ac4dbf62c8c321e5d8dbe Mon Sep 17 00:00:00 2001 From: Justin Date: Mon, 10 Jun 2019 13:43:00 +0100 Subject: [PATCH 06/10] Update conftest.py --- deposit_contract/tests/contracts/conftest.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/deposit_contract/tests/contracts/conftest.py b/deposit_contract/tests/contracts/conftest.py index b8b488abe..d4c7da9aa 100644 --- a/deposit_contract/tests/contracts/conftest.py +++ b/deposit_contract/tests/contracts/conftest.py @@ -62,26 +62,6 @@ def registration_contract(w3, tester): return registration_deployed -@pytest.fixture(params=[0, 1, 2]) -def modified_registration_contract( - request, - w3, - tester): - registration_code = get_deposit_contract_code() - contract_bytecode = compiler.compile_code(registration_code)['bytecode'] - contract_abi = compiler.mk_full_signature(registration_code) - registration = w3.eth.contract( - abi=contract_abi, - bytecode=contract_bytecode) - tx_hash = registration.constructor().transact() - tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash) - registration_deployed = w3.eth.contract( - address=tx_receipt.contractAddress, - abi=contract_abi - ) - return registration_deployed - - @pytest.fixture def assert_tx_failed(tester): def assert_tx_failed(function_to_test, exception=eth_tester.exceptions.TransactionFailed): From ef91ee5698ce5a82fa47c62efa29cb8890df0216 Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Mon, 10 Jun 2019 15:55:08 +0100 Subject: [PATCH 07/10] Address Danny's comments --- deposit_contract/contracts/validator_registration.v.py | 8 +++++--- specs/core/0_beacon-chain.md | 4 ++-- specs/core/0_deposit-contract.md | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/deposit_contract/contracts/validator_registration.v.py b/deposit_contract/contracts/validator_registration.v.py index b99a30784..8510380ee 100644 --- a/deposit_contract/contracts/validator_registration.v.py +++ b/deposit_contract/contracts/validator_registration.v.py @@ -1,5 +1,6 @@ MIN_DEPOSIT_AMOUNT: constant(uint256) = 1000000000 # Gwei DEPOSIT_CONTRACT_TREE_DEPTH: constant(uint256) = 32 +MAX_DEPOSIT_COUNT: constant(uint256) = 4294967295 # 2**DEPOSIT_CONTRACT_TREE_DEPTH - 1 PUBKEY_LENGTH: constant(uint256) = 48 # bytes WITHDRAWAL_CREDENTIALS_LENGTH: constant(uint256) = 32 # bytes AMOUNT_LENGTH: constant(uint256) = 8 # bytes @@ -27,7 +28,8 @@ def __init__(): @constant def to_little_endian_64(value: uint256) -> bytes[8]: # Reversing bytes using bitwise uint256 manipulations - # (array accesses of bytes[] are not currently supported in Vyper) + # Note: array accesses of bytes[] are not currently supported in Vyper + # Note: this function is only called when `value < 2**64` y: uint256 = 0 x: uint256 = value for _ in range(8): @@ -62,8 +64,8 @@ def get_deposit_count() -> bytes[8]: def deposit(pubkey: bytes[PUBKEY_LENGTH], withdrawal_credentials: bytes[WITHDRAWAL_CREDENTIALS_LENGTH], signature: bytes[SIGNATURE_LENGTH]): - # Avoid overflowing the Merkle tree - assert self.deposit_count < 2**DEPOSIT_CONTRACT_TREE_DEPTH - 1 + # Avoid overflowing the Merkle tree (and prevent edge case in computing `self.branch`) + assert self.deposit_count < MAX_DEPOSIT_COUNT # Validate deposit data deposit_amount: uint256 = msg.value / as_wei_value(1, "gwei") diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 8cacde746..fa15bc5dc 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1158,7 +1158,7 @@ def slash_validator(state: BeaconState, ### Genesis trigger -Whenever the deposit contract emits a `Deposit` log call the function `is_genesis_trigger(deposits: List[Deposit], timestamp: uint64) -> bool` where: +Before genesis has been triggered and whenever the deposit contract emits a `Deposit`, log call the function `is_genesis_trigger(deposits: List[Deposit], timestamp: uint64) -> bool` where: * `deposits` is the list of all deposits, ordered chronologically, up to and including the deposit triggering the latest `Deposit` log * `timestamp` is the Unix timestamp in the Ethereum 1.0 block that emitted the latest `Deposit` log @@ -1168,7 +1168,7 @@ When `is_genesis_trigger(deposits, timestamp) is True` for the first time let: * `genesis_deposits = deposits` * `genesis_time = timestamp % SECONDS_PER_DAY + 2 * SECONDS_PER_DAY` where `SECONDS_PER_DAY = 86400` * `genesis_eth1_data` be the object of type `Eth1Data` where: - * `genesis_eth1_data.block_hash` is the block hash for the last deposit in `deposits` + * `genesis_eth1_data.block_hash` is the Ethereum 1.0 block hash that emitted to log for the last deposit in `deposits` * `genesis_eth1_data.deposit_root` is the deposit root for the last deposit in `deposits` * `genesis_eth1_data.deposit_count = len(genesis_deposits)` diff --git a/specs/core/0_deposit-contract.md b/specs/core/0_deposit-contract.md index 50f52fd37..338ece487 100644 --- a/specs/core/0_deposit-contract.md +++ b/specs/core/0_deposit-contract.md @@ -42,7 +42,7 @@ The deposit contract has a public `deposit` function to make deposits. It takes #### Deposit amount -The ETH sent to the deposit contract, i.e. the deposit amount, is burnt on Ethereum 1.0. The minimum deposit amount is `MIN_DEPOSIT_AMOUNT` Gwei. +The amount of ETH (rounded down to the closest Gwei) sent to the deposit contract is the deposit amount, which must be of size at least `MIN_DEPOSIT_AMOUNT` Gwei. Note that ETH consumed by the deposit contract is no longer usable on Ethereum 1.0. #### Withdrawal credentials From abe48cc98857c3350d45656d3d4a6f2e6af2784d Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Tue, 11 Jun 2019 15:25:25 +0100 Subject: [PATCH 08/10] Address final comments by HW and Danny --- .../contracts/validator_registration.json | 2 +- .../contracts/validator_registration.v.py | 8 +++--- .../tests/contracts/test_deposit.py | 26 +++---------------- 3 files changed, 9 insertions(+), 27 deletions(-) diff --git a/deposit_contract/contracts/validator_registration.json b/deposit_contract/contracts/validator_registration.json index 676bf470a..1779423d2 100644 --- a/deposit_contract/contracts/validator_registration.json +++ b/deposit_contract/contracts/validator_registration.json @@ -1 +1 @@ -{"abi": [{"name": "Deposit", "inputs": [{"type": "bytes", "name": "pubkey", "indexed": false}, {"type": "bytes", "name": "withdrawal_credentials", "indexed": false}, {"type": "bytes", "name": "amount", "indexed": false}, {"type": "bytes", "name": "signature", "indexed": false}], "anonymous": false, "type": "event"}, {"outputs": [], "inputs": [], "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": 6973}, {"name": "get_deposit_root", "outputs": [{"type": "bytes32", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 79221}, {"name": "get_deposit_count", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 10922}, {"name": "deposit", "outputs": [], "inputs": [{"type": "bytes", "name": "pubkey"}, {"type": "bytes", "name": "withdrawal_credentials"}, {"type": "bytes", "name": "signature"}], "constant": false, "payable": true, "type": "function", "gas": 1318334}], "bytecode": "0x600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009e57600080fd5b6101406000601f818352015b600061014051602081106100bd57600080fd5b600260c052602060c020015460208261016001015260208101905061014051602081106100e957600080fd5b600260c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012757600080fd5b60c0519050606051600161014051018060405190131561014657600080fd5b809190121561015457600080fd5b6020811061016157600080fd5b600260c052602060c02001555b81516001018083528114156100aa575b5050610e9956600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a0526380673289600051141561025357602060046101403734156100b457600080fd5b60006101605261014051610180526101a060006008818352015b61016051600860008112156100eb578060000360020a82046100f2565b8060020a82025b905090506101605260ff61018051166101c052610160516101c0516101605101101561011d57600080fd5b6101c051610160510161016052610180517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff86000811215610166578060000360020a820461016d565b8060020a82025b90509050610180525b81516001018083528114156100ce575b505060186008602082066101e001602082840111156101a457600080fd5b60208061020082610160600060046015f15050818152809050905090508051602001806102a0828460006004600a8704601201f16101e157600080fd5b50506102a05160206001820306601f82010390506103006102a0516008818352015b826103005111156102135761022f565b6000610300516102c001535b8151600101808352811415610203575b50505060206102805260406102a0510160206001820306601f8201039050610280f3005b63c5f2892f60005114156103ab57341561026c57600080fd5b6000610140526001546101605261018060006020818352015b600160016101605116141561030657600061018051602081106102a757600080fd5b600060c052602060c02001546020826102200101526020810190506101405160208261022001015260208101905080610220526102209050602060c0825160208401600060025af16102f857600080fd5b60c051905061014052610374565b6000610140516020826101a0010152602081019050610180516020811061032c57600080fd5b600260c052602060c02001546020826101a0010152602081019050806101a0526101a09050602060c0825160208401600060025af161036a57600080fd5b60c0519050610140525b610160600261038257600080fd5b60028151048152505b8151600101808352811415610285575b50506101405160005260206000f3005b63621fd13060005114156104815734156103c457600080fd5b60606101c060246380673289610140526001546101605261015c6000305af16103ec57600080fd5b6101e0805160200180610260828460006004600a8704601201f161040f57600080fd5b50506102605160206001820306601f82010390506102c0610260516008818352015b826102c05111156104415761045d565b60006102c05161028001535b8151600101808352811415610431575b5050506020610240526040610260510160206001820306601f8201039050610240f3005b63c47e300d6000511415610d0e57606060046101403760506004356004016101a03760306004356004013511156104b757600080fd5b60406024356004016102203760206024356004013511156104d757600080fd5b60806044356004016102803760606044356004013511156104f757600080fd5b63ffffffff6001541061050957600080fd5b633b9aca00610340526103405161051f57600080fd5b61034051340461032052633b9aca0061032051101561053d57600080fd5b60306101a0511461054d57600080fd5b6020610220511461055d57600080fd5b6060610280511461056d57600080fd5b6060610440602463806732896103c052610320516103e0526103dc6000305af161059657600080fd5b610460805160200180610360828460006004600a8704601201f16105b957600080fd5b505060006101a060308060208461056001018260208501600060046016f150508051820191505060006010602082066104e001602082840111156105fc57600080fd5b602080610500826104a0600060046015f150508181528090509050905060108060208461056001018260208501600060046013f150508051820191505080610560526105609050602060c0825160208401600060025af161065c57600080fd5b60c05190506104c052600060006040602082066106000161028051828401111561068557600080fd5b606080610620826020602088068803016102800160006004601bf1505081815280905090509050602060c0825160208401600060025af16106c557600080fd5b60c0519050602082610800010152602081019050600060406020602082066106c0016102805182840111156106f957600080fd5b6060806106e0826020602088068803016102800160006004601bf150508181528090509050905060208060208461078001018260208501600060046015f15050805182019150506104a05160208261078001015260208101905080610780526107809050602060c0825160208401600060025af161077657600080fd5b60c051905060208261080001015260208101905080610800526108009050602060c0825160208401600060025af16107ad57600080fd5b60c05190506105e052600060006104c0516020826108a00101526020810190506102206020806020846108a001018260208501600060046015f1505080518201915050806108a0526108a09050602060c0825160208401600060025af161081357600080fd5b60c0519050602082610a2001015260208101905060006103606008806020846109a001018260208501600060046012f15050805182019150506000601860208206610920016020828401111561086857600080fd5b602080610940826104a0600060046015f15050818152809050905090506018806020846109a001018260208501600060046014f15050805182019150506105e0516020826109a0010152602081019050806109a0526109a09050602060c0825160208401600060025af16108db57600080fd5b60c0519050602082610a2001015260208101905080610a2052610a209050602060c0825160208401600060025af161091257600080fd5b60c051905061088052600180546001825401101561092f57600080fd5b6001815401815550600154610aa052610ac060006020818352015b60016001610aa05116141561097f5761088051610ac0516020811061096e57600080fd5b600060c052602060c0200155610a13565b6000610ac0516020811061099257600080fd5b600060c052602060c0200154602082610ae001015260208101905061088051602082610ae001015260208101905080610ae052610ae09050602060c0825160208401600060025af16109e357600080fd5b60c051905061088052610aa060026109fa57600080fd5b60028151048152505b815160010180835281141561094a575b50506080610b8052610b8051610bc0526101a0805160200180610b8051610bc001828460006004600a8704601201f1610a4b57600080fd5b5050610b8051610bc0015160206001820306601f8201039050610b8051610bc001610b6081516040818352015b83610b6051101515610a8957610aa6565b6000610b60516020850101535b8151600101808352811415610a78575b505050506020610b8051610bc0015160206001820306601f8201039050610b80510101610b8052610b8051610be052610220805160200180610b8051610bc001828460006004600a8704601201f1610afd57600080fd5b5050610b8051610bc0015160206001820306601f8201039050610b8051610bc001610b6081516020818352015b83610b6051101515610b3b57610b58565b6000610b60516020850101535b8151600101808352811415610b2a575b505050506020610b8051610bc0015160206001820306601f8201039050610b80510101610b8052610b8051610c0052610360805160200180610b8051610bc001828460006004600a8704601201f1610baf57600080fd5b5050610b8051610bc0015160206001820306601f8201039050610b8051610bc001610b6081516020818352015b83610b6051101515610bed57610c0a565b6000610b60516020850101535b8151600101808352811415610bdc575b505050506020610b8051610bc0015160206001820306601f8201039050610b80510101610b8052610b8051610c2052610280805160200180610b8051610bc001828460006004600a8704601201f1610c6157600080fd5b5050610b8051610bc0015160206001820306601f8201039050610b8051610bc001610b6081516060818352015b83610b6051101515610c9f57610cbc565b6000610b60516020850101535b8151600101808352811415610c8e575b505050506020610b8051610bc0015160206001820306601f8201039050610b80510101610b80527f9d0a206c338cfcaf9198c04fe61b39a988e26b623ef97cb2f72bafcfbf8bb93e610b8051610bc0a1005b60006000fd5b610185610e9903610185600039610185610e99036000f3"} \ No newline at end of file +{"abi": [{"name": "Deposit", "inputs": [{"type": "bytes", "name": "pubkey", "indexed": false}, {"type": "bytes", "name": "withdrawal_credentials", "indexed": false}, {"type": "bytes", "name": "amount", "indexed": false}, {"type": "bytes", "name": "signature", "indexed": false}, {"type": "bytes", "name": "index", "indexed": false}], "anonymous": false, "type": "event"}, {"outputs": [], "inputs": [], "constant": false, "payable": false, "type": "constructor"}, {"name": "get_deposit_root", "outputs": [{"type": "bytes32", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 79221}, {"name": "get_deposit_count", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 10433}, {"name": "deposit", "outputs": [], "inputs": [{"type": "bytes", "name": "pubkey"}, {"type": "bytes", "name": "withdrawal_credentials"}, {"type": "bytes", "name": "signature"}], "constant": false, "payable": true, "type": "function", "gas": 1334984}], "bytecode": "0x600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009e57600080fd5b6101406000601f818352015b600061014051602081106100bd57600080fd5b600260c052602060c020015460208261016001015260208101905061014051602081106100e957600080fd5b600260c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012757600080fd5b60c0519050606051600161014051018060405190131561014657600080fd5b809190121561015457600080fd5b6020811061016157600080fd5b600260c052602060c02001555b81516001018083528114156100aa575b505061134056600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052600015610277575b6101605261014052600061018052610140516101a0526101c060006008818352015b61018051600860008112156100da578060000360020a82046100e1565b8060020a82025b905090506101805260ff6101a051166101e052610180516101e0516101805101101561010c57600080fd5b6101e0516101805101610180526101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff86000811215610155578060000360020a820461015c565b8060020a82025b905090506101a0525b81516001018083528114156100bd575b50506018600860208206610200016020828401111561019357600080fd5b60208061022082610180600060046015f15050818152809050905090508051602001806102c0828460006004600a8704601201f16101d057600080fd5b50506102c05160206001820306601f82010390506103206102c0516008818352015b826103205111156102025761021e565b6000610320516102e001535b81516001018083528114156101f2575b50505060206102a05260406102c0510160206001820306601f8201039050610280525b6000610280511115156102535761026f565b602061028051036102a001516020610280510361028052610241565b610160515650005b63c5f2892f60005114156103cf57341561029057600080fd5b6000610140526001546101605261018060006020818352015b600160016101605116141561032a57600061018051602081106102cb57600080fd5b600060c052602060c02001546020826102200101526020810190506101405160208261022001015260208101905080610220526102209050602060c0825160208401600060025af161031c57600080fd5b60c051905061014052610398565b6000610140516020826101a0010152602081019050610180516020811061035057600080fd5b600260c052602060c02001546020826101a0010152602081019050806101a0526101a09050602060c0825160208401600060025af161038e57600080fd5b60c0519050610140525b61016060026103a657600080fd5b60028151048152505b81516001018083528114156102a9575b50506101405160005260206000f3005b63621fd13060005114156104e15734156103e857600080fd5b63806732896101405260015461016052610160516006580161009b565b506101c0526000610220525b6101c05160206001820306601f8201039050610220511015156104335761044c565b610220516101e001526102205160200161022052610411565b6101c0805160200180610280828460006004600a8704601201f161046f57600080fd5b50506102805160206001820306601f82010390506102e0610280516008818352015b826102e05111156104a1576104bd565b60006102e0516102a001535b8151600101808352811415610491575b5050506020610260526040610280510160206001820306601f8201039050610260f3005b63c47e300d60005114156111b557606060046101403760506004356004016101a037603060043560040135111561051757600080fd5b604060243560040161022037602060243560040135111561053757600080fd5b608060443560040161028037606060443560040135111561055757600080fd5b63ffffffff6001541061056957600080fd5b633b9aca00610340526103405161057f57600080fd5b61034051340461032052633b9aca0061032051101561059d57600080fd5b60306101a051146105ad57600080fd5b602061022051146105bd57600080fd5b606061028051146105cd57600080fd5b6101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a05163806732896103c052610320516103e0526103e0516006580161009b565b506104405260006104a0525b6104405160206001820306601f82010390506104a05110151561065d57610676565b6104a05161046001526104a0516020016104a05261063b565b6103a05261038052610360526103405261032052610300526102e0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a052610440805160200180610360828460006004600a8704601201f16106dd57600080fd5b505060006101a060308060208461058001018260208501600060046016f15050805182019150506000601060208206610500016020828401111561072057600080fd5b602080610520826104c0600060046015f150508181528090509050905060108060208461058001018260208501600060046013f150508051820191505080610580526105809050602060c0825160208401600060025af161078057600080fd5b60c05190506104e05260006000604060208206610620016102805182840111156107a957600080fd5b606080610640826020602088068803016102800160006004601bf1505081815280905090509050602060c0825160208401600060025af16107e957600080fd5b60c0519050602082610820010152602081019050600060406020602082066106e00161028051828401111561081d57600080fd5b606080610700826020602088068803016102800160006004601bf15050818152809050905090506020806020846107a001018260208501600060046015f15050805182019150506104c0516020826107a0010152602081019050806107a0526107a09050602060c0825160208401600060025af161089a57600080fd5b60c051905060208261082001015260208101905080610820526108209050602060c0825160208401600060025af16108d157600080fd5b60c051905061060052600060006104e0516020826108c00101526020810190506102206020806020846108c001018260208501600060046015f1505080518201915050806108c0526108c09050602060c0825160208401600060025af161093757600080fd5b60c0519050602082610a4001015260208101905060006103606008806020846109c001018260208501600060046012f15050805182019150506000601860208206610940016020828401111561098c57600080fd5b602080610960826104c0600060046015f15050818152809050905090506018806020846109c001018260208501600060046014f1505080518201915050610600516020826109c0010152602081019050806109c0526109c09050602060c0825160208401600060025af16109ff57600080fd5b60c0519050602082610a4001015260208101905080610a4052610a409050602060c0825160208401600060025af1610a3657600080fd5b60c05190506108a0526101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a0516103c0516103e05161040051610420516104405161046051610480516104a0516104c0516104e05161050051610520516105405161056051610580516105a0516105c0516105e05161060051610620516106405161066051610680516106a0516106c0516106e05161070051610720516107405161076051610780516107a0516107c0516107e05161080051610820516108405161086051610880516108a0516108c0516108e05161090051610920516109405161096051610980516109a0516109c0516109e051610a0051610a2051610a4051610a6051610a8051610aa0516380673289610ac052600154610ae052610ae0516006580161009b565b50610b40526000610ba0525b610b405160206001820306601f8201039050610ba051101515610bae57610bc7565b610ba051610b600152610ba051602001610ba052610b8c565b610aa052610a8052610a6052610a4052610a2052610a00526109e0526109c0526109a05261098052610960526109405261092052610900526108e0526108c0526108a05261088052610860526108405261082052610800526107e0526107c0526107a05261078052610760526107405261072052610700526106e0526106c0526106a05261068052610660526106405261062052610600526105e0526105c0526105a05261058052610560526105405261052052610500526104e0526104c0526104a05261048052610460526104405261042052610400526103e0526103c0526103a05261038052610360526103405261032052610300526102e0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a052610b40805160200180610bc0828460006004600a8704601201f1610d0e57600080fd5b505060a0610c4052610c4051610c80526101a0805160200180610c4051610c8001828460006004600a8704601201f1610d4657600080fd5b5050610c4051610c80015160206001820306601f8201039050610c4051610c8001610c2081516040818352015b83610c2051101515610d8457610da1565b6000610c20516020850101535b8151600101808352811415610d73575b505050506020610c4051610c80015160206001820306601f8201039050610c40510101610c4052610c4051610ca052610220805160200180610c4051610c8001828460006004600a8704601201f1610df857600080fd5b5050610c4051610c80015160206001820306601f8201039050610c4051610c8001610c2081516020818352015b83610c2051101515610e3657610e53565b6000610c20516020850101535b8151600101808352811415610e25575b505050506020610c4051610c80015160206001820306601f8201039050610c40510101610c4052610c4051610cc052610360805160200180610c4051610c8001828460006004600a8704601201f1610eaa57600080fd5b5050610c4051610c80015160206001820306601f8201039050610c4051610c8001610c2081516020818352015b83610c2051101515610ee857610f05565b6000610c20516020850101535b8151600101808352811415610ed7575b505050506020610c4051610c80015160206001820306601f8201039050610c40510101610c4052610c4051610ce052610280805160200180610c4051610c8001828460006004600a8704601201f1610f5c57600080fd5b5050610c4051610c80015160206001820306601f8201039050610c4051610c8001610c2081516060818352015b83610c2051101515610f9a57610fb7565b6000610c20516020850101535b8151600101808352811415610f89575b505050506020610c4051610c80015160206001820306601f8201039050610c40510101610c4052610c4051610d0052610bc0805160200180610c4051610c8001828460006004600a8704601201f161100e57600080fd5b5050610c4051610c80015160206001820306601f8201039050610c4051610c8001610c2081516020818352015b83610c205110151561104c57611069565b6000610c20516020850101535b815160010180835281141561103b575b505050506020610c4051610c80015160206001820306601f8201039050610c40510101610c40527fdc5fc95703516abd38fa03c3737ff3b52dc52347055c8028460fdf5bbe2f12ce610c4051610c80a160018054600182540110156110cd57600080fd5b6001815401815550600154610d2052610d4060006020818352015b60016001610d205116141561111d576108a051610d40516020811061110c57600080fd5b600060c052602060c02001556111b1565b6000610d40516020811061113057600080fd5b600060c052602060c0200154602082610d600101526020810190506108a051602082610d6001015260208101905080610d6052610d609050602060c0825160208401600060025af161118157600080fd5b60c05190506108a052610d20600261119857600080fd5b60028151048152505b81516001018083528114156110e8575b5050005b60006000fd5b61018561134003610185600039610185611340036000f3"} \ No newline at end of file diff --git a/deposit_contract/contracts/validator_registration.v.py b/deposit_contract/contracts/validator_registration.v.py index 8510380ee..10daf42b9 100644 --- a/deposit_contract/contracts/validator_registration.v.py +++ b/deposit_contract/contracts/validator_registration.v.py @@ -11,6 +11,7 @@ Deposit: event({ withdrawal_credentials: bytes[32], amount: bytes[8], signature: bytes[96], + index: bytes[8], }) branch: bytes32[DEPOSIT_CONTRACT_TREE_DEPTH] @@ -24,7 +25,7 @@ def __init__(): self.zero_hashes[i + 1] = sha256(concat(self.zero_hashes[i], self.zero_hashes[i])) -@public +@private @constant def to_little_endian_64(value: uint256) -> bytes[8]: # Reversing bytes using bitwise uint256 manipulations @@ -87,6 +88,9 @@ def deposit(pubkey: bytes[PUBKEY_LENGTH], sha256(concat(amount, slice(zero_bytes32, start=0, len=32 - AMOUNT_LENGTH), signature_root)), )) + # Emit `Deposit` log + log.Deposit(pubkey, withdrawal_credentials, amount, signature, self.to_little_endian_64(self.deposit_count)) + # Add `DepositData` root to Merkle tree (update a single `branch` node) self.deposit_count += 1 size: uint256 = self.deposit_count @@ -97,5 +101,3 @@ def deposit(pubkey: bytes[PUBKEY_LENGTH], node = sha256(concat(self.branch[height], node)) size /= 2 - # Emit `Deposit` log - log.Deposit(pubkey, withdrawal_credentials, amount, signature) diff --git a/deposit_contract/tests/contracts/test_deposit.py b/deposit_contract/tests/contracts/test_deposit.py index 12f3e7f8b..783af3356 100644 --- a/deposit_contract/tests/contracts/test_deposit.py +++ b/deposit_contract/tests/contracts/test_deposit.py @@ -49,28 +49,6 @@ def deposit_input(): ) -@pytest.mark.parametrize( - 'value,success', - [ - (0, True), - (10, True), - (55555, True), - (2**64 - 1, True), - # (2**64, True), # Note that all calls to `to_little_endian_64` have an input less than 2**64 - ] -) -def test_to_little_endian_64(registration_contract, value, success, assert_tx_failed): - call = registration_contract.functions.to_little_endian_64(value) - - if success: - little_endian_64 = call.call() - assert little_endian_64 == (value).to_bytes(8, 'little') - else: - assert_tx_failed( - lambda: call.call() - ) - - @pytest.mark.parametrize( 'success,deposit_amount', [ @@ -151,7 +129,7 @@ def test_deposit_log(registration_contract, a0, w3, deposit_input): assert log['withdrawal_credentials'] == deposit_input[1] assert log['amount'] == deposit_amount_list[i].to_bytes(8, 'little') assert log['signature'] == deposit_input[2] - + assert log['index'] == i.to_bytes(8, 'little') def test_deposit_tree(registration_contract, w3, assert_tx_failed, deposit_input): log_filter = registration_contract.events.Deposit.createFilter( @@ -171,6 +149,8 @@ def test_deposit_tree(registration_contract, w3, assert_tx_failed, deposit_input assert len(logs) == 1 log = logs[0]['args'] + assert log["index"] == i.to_bytes(8, 'little') + deposit_data = DepositData( pubkey=deposit_input[0], withdrawal_credentials=deposit_input[1], From 6a83205420cde658f9ac1a0f9e324313d3dacb2f Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Tue, 11 Jun 2019 15:29:34 +0100 Subject: [PATCH 09/10] Minor copy edit --- specs/core/0_beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 61729e8d9..c25d43d96 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1168,7 +1168,7 @@ When `is_genesis_trigger(deposits, timestamp) is True` for the first time let: * `genesis_deposits = deposits` * `genesis_time = timestamp - timestamp % SECONDS_PER_DAY + 2 * SECONDS_PER_DAY` where `SECONDS_PER_DAY = 86400` * `genesis_eth1_data` be the object of type `Eth1Data` where: - * `genesis_eth1_data.block_hash` is the Ethereum 1.0 block hash that emitted to log for the last deposit in `deposits` + * `genesis_eth1_data.block_hash` is the Ethereum 1.0 block hash that emitted the log for the last deposit in `deposits` * `genesis_eth1_data.deposit_root` is the deposit root for the last deposit in `deposits` * `genesis_eth1_data.deposit_count = len(genesis_deposits)` From 193b628fb4fb7c3ef08cf160a9bbafade61a839e Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Tue, 11 Jun 2019 19:03:26 +0100 Subject: [PATCH 10/10] Bypass Vyper compiler bug --- deposit_contract/contracts/validator_registration.json | 2 +- deposit_contract/contracts/validator_registration.v.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/deposit_contract/contracts/validator_registration.json b/deposit_contract/contracts/validator_registration.json index 1779423d2..1988b28c0 100644 --- a/deposit_contract/contracts/validator_registration.json +++ b/deposit_contract/contracts/validator_registration.json @@ -1 +1 @@ -{"abi": [{"name": "Deposit", "inputs": [{"type": "bytes", "name": "pubkey", "indexed": false}, {"type": "bytes", "name": "withdrawal_credentials", "indexed": false}, {"type": "bytes", "name": "amount", "indexed": false}, {"type": "bytes", "name": "signature", "indexed": false}, {"type": "bytes", "name": "index", "indexed": false}], "anonymous": false, "type": "event"}, {"outputs": [], "inputs": [], "constant": false, "payable": false, "type": "constructor"}, {"name": "get_deposit_root", "outputs": [{"type": "bytes32", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 79221}, {"name": "get_deposit_count", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 10433}, {"name": "deposit", "outputs": [], "inputs": [{"type": "bytes", "name": "pubkey"}, {"type": "bytes", "name": "withdrawal_credentials"}, {"type": "bytes", "name": "signature"}], "constant": false, "payable": true, "type": "function", "gas": 1334984}], "bytecode": "0x600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009e57600080fd5b6101406000601f818352015b600061014051602081106100bd57600080fd5b600260c052602060c020015460208261016001015260208101905061014051602081106100e957600080fd5b600260c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012757600080fd5b60c0519050606051600161014051018060405190131561014657600080fd5b809190121561015457600080fd5b6020811061016157600080fd5b600260c052602060c02001555b81516001018083528114156100aa575b505061134056600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052600015610277575b6101605261014052600061018052610140516101a0526101c060006008818352015b61018051600860008112156100da578060000360020a82046100e1565b8060020a82025b905090506101805260ff6101a051166101e052610180516101e0516101805101101561010c57600080fd5b6101e0516101805101610180526101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff86000811215610155578060000360020a820461015c565b8060020a82025b905090506101a0525b81516001018083528114156100bd575b50506018600860208206610200016020828401111561019357600080fd5b60208061022082610180600060046015f15050818152809050905090508051602001806102c0828460006004600a8704601201f16101d057600080fd5b50506102c05160206001820306601f82010390506103206102c0516008818352015b826103205111156102025761021e565b6000610320516102e001535b81516001018083528114156101f2575b50505060206102a05260406102c0510160206001820306601f8201039050610280525b6000610280511115156102535761026f565b602061028051036102a001516020610280510361028052610241565b610160515650005b63c5f2892f60005114156103cf57341561029057600080fd5b6000610140526001546101605261018060006020818352015b600160016101605116141561032a57600061018051602081106102cb57600080fd5b600060c052602060c02001546020826102200101526020810190506101405160208261022001015260208101905080610220526102209050602060c0825160208401600060025af161031c57600080fd5b60c051905061014052610398565b6000610140516020826101a0010152602081019050610180516020811061035057600080fd5b600260c052602060c02001546020826101a0010152602081019050806101a0526101a09050602060c0825160208401600060025af161038e57600080fd5b60c0519050610140525b61016060026103a657600080fd5b60028151048152505b81516001018083528114156102a9575b50506101405160005260206000f3005b63621fd13060005114156104e15734156103e857600080fd5b63806732896101405260015461016052610160516006580161009b565b506101c0526000610220525b6101c05160206001820306601f8201039050610220511015156104335761044c565b610220516101e001526102205160200161022052610411565b6101c0805160200180610280828460006004600a8704601201f161046f57600080fd5b50506102805160206001820306601f82010390506102e0610280516008818352015b826102e05111156104a1576104bd565b60006102e0516102a001535b8151600101808352811415610491575b5050506020610260526040610280510160206001820306601f8201039050610260f3005b63c47e300d60005114156111b557606060046101403760506004356004016101a037603060043560040135111561051757600080fd5b604060243560040161022037602060243560040135111561053757600080fd5b608060443560040161028037606060443560040135111561055757600080fd5b63ffffffff6001541061056957600080fd5b633b9aca00610340526103405161057f57600080fd5b61034051340461032052633b9aca0061032051101561059d57600080fd5b60306101a051146105ad57600080fd5b602061022051146105bd57600080fd5b606061028051146105cd57600080fd5b6101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a05163806732896103c052610320516103e0526103e0516006580161009b565b506104405260006104a0525b6104405160206001820306601f82010390506104a05110151561065d57610676565b6104a05161046001526104a0516020016104a05261063b565b6103a05261038052610360526103405261032052610300526102e0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a052610440805160200180610360828460006004600a8704601201f16106dd57600080fd5b505060006101a060308060208461058001018260208501600060046016f15050805182019150506000601060208206610500016020828401111561072057600080fd5b602080610520826104c0600060046015f150508181528090509050905060108060208461058001018260208501600060046013f150508051820191505080610580526105809050602060c0825160208401600060025af161078057600080fd5b60c05190506104e05260006000604060208206610620016102805182840111156107a957600080fd5b606080610640826020602088068803016102800160006004601bf1505081815280905090509050602060c0825160208401600060025af16107e957600080fd5b60c0519050602082610820010152602081019050600060406020602082066106e00161028051828401111561081d57600080fd5b606080610700826020602088068803016102800160006004601bf15050818152809050905090506020806020846107a001018260208501600060046015f15050805182019150506104c0516020826107a0010152602081019050806107a0526107a09050602060c0825160208401600060025af161089a57600080fd5b60c051905060208261082001015260208101905080610820526108209050602060c0825160208401600060025af16108d157600080fd5b60c051905061060052600060006104e0516020826108c00101526020810190506102206020806020846108c001018260208501600060046015f1505080518201915050806108c0526108c09050602060c0825160208401600060025af161093757600080fd5b60c0519050602082610a4001015260208101905060006103606008806020846109c001018260208501600060046012f15050805182019150506000601860208206610940016020828401111561098c57600080fd5b602080610960826104c0600060046015f15050818152809050905090506018806020846109c001018260208501600060046014f1505080518201915050610600516020826109c0010152602081019050806109c0526109c09050602060c0825160208401600060025af16109ff57600080fd5b60c0519050602082610a4001015260208101905080610a4052610a409050602060c0825160208401600060025af1610a3657600080fd5b60c05190506108a0526101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a0516103c0516103e05161040051610420516104405161046051610480516104a0516104c0516104e05161050051610520516105405161056051610580516105a0516105c0516105e05161060051610620516106405161066051610680516106a0516106c0516106e05161070051610720516107405161076051610780516107a0516107c0516107e05161080051610820516108405161086051610880516108a0516108c0516108e05161090051610920516109405161096051610980516109a0516109c0516109e051610a0051610a2051610a4051610a6051610a8051610aa0516380673289610ac052600154610ae052610ae0516006580161009b565b50610b40526000610ba0525b610b405160206001820306601f8201039050610ba051101515610bae57610bc7565b610ba051610b600152610ba051602001610ba052610b8c565b610aa052610a8052610a6052610a4052610a2052610a00526109e0526109c0526109a05261098052610960526109405261092052610900526108e0526108c0526108a05261088052610860526108405261082052610800526107e0526107c0526107a05261078052610760526107405261072052610700526106e0526106c0526106a05261068052610660526106405261062052610600526105e0526105c0526105a05261058052610560526105405261052052610500526104e0526104c0526104a05261048052610460526104405261042052610400526103e0526103c0526103a05261038052610360526103405261032052610300526102e0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a052610b40805160200180610bc0828460006004600a8704601201f1610d0e57600080fd5b505060a0610c4052610c4051610c80526101a0805160200180610c4051610c8001828460006004600a8704601201f1610d4657600080fd5b5050610c4051610c80015160206001820306601f8201039050610c4051610c8001610c2081516040818352015b83610c2051101515610d8457610da1565b6000610c20516020850101535b8151600101808352811415610d73575b505050506020610c4051610c80015160206001820306601f8201039050610c40510101610c4052610c4051610ca052610220805160200180610c4051610c8001828460006004600a8704601201f1610df857600080fd5b5050610c4051610c80015160206001820306601f8201039050610c4051610c8001610c2081516020818352015b83610c2051101515610e3657610e53565b6000610c20516020850101535b8151600101808352811415610e25575b505050506020610c4051610c80015160206001820306601f8201039050610c40510101610c4052610c4051610cc052610360805160200180610c4051610c8001828460006004600a8704601201f1610eaa57600080fd5b5050610c4051610c80015160206001820306601f8201039050610c4051610c8001610c2081516020818352015b83610c2051101515610ee857610f05565b6000610c20516020850101535b8151600101808352811415610ed7575b505050506020610c4051610c80015160206001820306601f8201039050610c40510101610c4052610c4051610ce052610280805160200180610c4051610c8001828460006004600a8704601201f1610f5c57600080fd5b5050610c4051610c80015160206001820306601f8201039050610c4051610c8001610c2081516060818352015b83610c2051101515610f9a57610fb7565b6000610c20516020850101535b8151600101808352811415610f89575b505050506020610c4051610c80015160206001820306601f8201039050610c40510101610c4052610c4051610d0052610bc0805160200180610c4051610c8001828460006004600a8704601201f161100e57600080fd5b5050610c4051610c80015160206001820306601f8201039050610c4051610c8001610c2081516020818352015b83610c205110151561104c57611069565b6000610c20516020850101535b815160010180835281141561103b575b505050506020610c4051610c80015160206001820306601f8201039050610c40510101610c40527fdc5fc95703516abd38fa03c3737ff3b52dc52347055c8028460fdf5bbe2f12ce610c4051610c80a160018054600182540110156110cd57600080fd5b6001815401815550600154610d2052610d4060006020818352015b60016001610d205116141561111d576108a051610d40516020811061110c57600080fd5b600060c052602060c02001556111b1565b6000610d40516020811061113057600080fd5b600060c052602060c0200154602082610d600101526020810190506108a051602082610d6001015260208101905080610d6052610d609050602060c0825160208401600060025af161118157600080fd5b60c05190506108a052610d20600261119857600080fd5b60028151048152505b81516001018083528114156110e8575b5050005b60006000fd5b61018561134003610185600039610185611340036000f3"} \ No newline at end of file +{"abi": [{"name": "Deposit", "inputs": [{"type": "bytes", "name": "pubkey", "indexed": false}, {"type": "bytes", "name": "withdrawal_credentials", "indexed": false}, {"type": "bytes", "name": "amount", "indexed": false}, {"type": "bytes", "name": "signature", "indexed": false}, {"type": "bytes", "name": "index", "indexed": false}], "anonymous": false, "type": "event"}, {"outputs": [], "inputs": [], "constant": false, "payable": false, "type": "constructor"}, {"name": "get_deposit_root", "outputs": [{"type": "bytes32", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 79221}, {"name": "get_deposit_count", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 10433}, {"name": "deposit", "outputs": [], "inputs": [{"type": "bytes", "name": "pubkey"}, {"type": "bytes", "name": "withdrawal_credentials"}, {"type": "bytes", "name": "signature"}], "constant": false, "payable": true, "type": "function", "gas": 1334417}], "bytecode": "0x600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009e57600080fd5b6101406000601f818352015b600061014051602081106100bd57600080fd5b600260c052602060c020015460208261016001015260208101905061014051602081106100e957600080fd5b600260c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012757600080fd5b60c0519050606051600161014051018060405190131561014657600080fd5b809190121561015457600080fd5b6020811061016157600080fd5b600260c052602060c02001555b81516001018083528114156100aa575b50506111c656600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052600015610277575b6101605261014052600061018052610140516101a0526101c060006008818352015b61018051600860008112156100da578060000360020a82046100e1565b8060020a82025b905090506101805260ff6101a051166101e052610180516101e0516101805101101561010c57600080fd5b6101e0516101805101610180526101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff86000811215610155578060000360020a820461015c565b8060020a82025b905090506101a0525b81516001018083528114156100bd575b50506018600860208206610200016020828401111561019357600080fd5b60208061022082610180600060046015f15050818152809050905090508051602001806102c0828460006004600a8704601201f16101d057600080fd5b50506102c05160206001820306601f82010390506103206102c0516008818352015b826103205111156102025761021e565b6000610320516102e001535b81516001018083528114156101f2575b50505060206102a05260406102c0510160206001820306601f8201039050610280525b6000610280511115156102535761026f565b602061028051036102a001516020610280510361028052610241565b610160515650005b63c5f2892f60005114156103cf57341561029057600080fd5b6000610140526001546101605261018060006020818352015b600160016101605116141561032a57600061018051602081106102cb57600080fd5b600060c052602060c02001546020826102200101526020810190506101405160208261022001015260208101905080610220526102209050602060c0825160208401600060025af161031c57600080fd5b60c051905061014052610398565b6000610140516020826101a0010152602081019050610180516020811061035057600080fd5b600260c052602060c02001546020826101a0010152602081019050806101a0526101a09050602060c0825160208401600060025af161038e57600080fd5b60c0519050610140525b61016060026103a657600080fd5b60028151048152505b81516001018083528114156102a9575b50506101405160005260206000f3005b63621fd13060005114156104e15734156103e857600080fd5b63806732896101405260015461016052610160516006580161009b565b506101c0526000610220525b6101c05160206001820306601f8201039050610220511015156104335761044c565b610220516101e001526102205160200161022052610411565b6101c0805160200180610280828460006004600a8704601201f161046f57600080fd5b50506102805160206001820306601f82010390506102e0610280516008818352015b826102e05111156104a1576104bd565b60006102e0516102a001535b8151600101808352811415610491575b5050506020610260526040610280510160206001820306601f8201039050610260f3005b63c47e300d600051141561103b57606060046101403760506004356004016101a037603060043560040135111561051757600080fd5b604060243560040161022037602060243560040135111561053757600080fd5b608060443560040161028037606060443560040135111561055757600080fd5b63ffffffff6001541061056957600080fd5b633b9aca00610340526103405161057f57600080fd5b61034051340461032052633b9aca0061032051101561059d57600080fd5b60306101a051146105ad57600080fd5b602061022051146105bd57600080fd5b606061028051146105cd57600080fd5b6101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a05163806732896103c052610320516103e0526103e0516006580161009b565b506104405260006104a0525b6104405160206001820306601f82010390506104a05110151561065d57610676565b6104a05161046001526104a0516020016104a05261063b565b6103a05261038052610360526103405261032052610300526102e0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a052610440805160200180610360828460006004600a8704601201f16106dd57600080fd5b50506101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a0516103c0516103e05161040051610420516104405161046051610480516104a05163806732896104c0526001546104e0526104e0516006580161009b565b506105405260006105a0525b6105405160206001820306601f82010390506105a05110151561078e576107a7565b6105a05161056001526105a0516020016105a05261076c565b6104a05261048052610460526104405261042052610400526103e0526103c0526103a05261038052610360526103405261032052610300526102e0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a0526105408051602001806105c0828460006004600a8704601201f161082e57600080fd5b505060a06106405261064051610680526101a08051602001806106405161068001828460006004600a8704601201f161086657600080fd5b505061064051610680015160206001820306601f8201039050610640516106800161062081516040818352015b83610620511015156108a4576108c1565b6000610620516020850101535b8151600101808352811415610893575b50505050602061064051610680015160206001820306601f820103905061064051010161064052610640516106a0526102208051602001806106405161068001828460006004600a8704601201f161091857600080fd5b505061064051610680015160206001820306601f8201039050610640516106800161062081516020818352015b836106205110151561095657610973565b6000610620516020850101535b8151600101808352811415610945575b50505050602061064051610680015160206001820306601f820103905061064051010161064052610640516106c0526103608051602001806106405161068001828460006004600a8704601201f16109ca57600080fd5b505061064051610680015160206001820306601f8201039050610640516106800161062081516020818352015b8361062051101515610a0857610a25565b6000610620516020850101535b81516001018083528114156109f7575b50505050602061064051610680015160206001820306601f820103905061064051010161064052610640516106e0526102808051602001806106405161068001828460006004600a8704601201f1610a7c57600080fd5b505061064051610680015160206001820306601f8201039050610640516106800161062081516060818352015b8361062051101515610aba57610ad7565b6000610620516020850101535b8151600101808352811415610aa9575b50505050602061064051610680015160206001820306601f82010390506106405101016106405261064051610700526105c08051602001806106405161068001828460006004600a8704601201f1610b2e57600080fd5b505061064051610680015160206001820306601f8201039050610640516106800161062081516020818352015b8361062051101515610b6c57610b89565b6000610620516020850101535b8151600101808352811415610b5b575b50505050602061064051610680015160206001820306601f8201039050610640510101610640527fdc5fc95703516abd38fa03c3737ff3b52dc52347055c8028460fdf5bbe2f12ce61064051610680a160006107205260006101a06030806020846107e001018260208501600060046016f150508051820191505060006010602082066107600160208284011115610c2057600080fd5b60208061078082610720600060046015f15050818152809050905090506010806020846107e001018260208501600060046013f1505080518201915050806107e0526107e09050602060c0825160208401600060025af1610c8057600080fd5b60c0519050610740526000600060406020820661088001610280518284011115610ca957600080fd5b6060806108a0826020602088068803016102800160006004601bf1505081815280905090509050602060c0825160208401600060025af1610ce957600080fd5b60c0519050602082610a800101526020810190506000604060206020820661094001610280518284011115610d1d57600080fd5b606080610960826020602088068803016102800160006004601bf1505081815280905090509050602080602084610a0001018260208501600060046015f150508051820191505061072051602082610a0001015260208101905080610a0052610a009050602060c0825160208401600060025af1610d9a57600080fd5b60c0519050602082610a8001015260208101905080610a8052610a809050602060c0825160208401600060025af1610dd157600080fd5b60c0519050610860526000600061074051602082610b20010152602081019050610220602080602084610b2001018260208501600060046015f150508051820191505080610b2052610b209050602060c0825160208401600060025af1610e3757600080fd5b60c0519050602082610ca00101526020810190506000610360600880602084610c2001018260208501600060046012f15050805182019150506000601860208206610ba00160208284011115610e8c57600080fd5b602080610bc082610720600060046015f1505081815280905090509050601880602084610c2001018260208501600060046014f150508051820191505061086051602082610c2001015260208101905080610c2052610c209050602060c0825160208401600060025af1610eff57600080fd5b60c0519050602082610ca001015260208101905080610ca052610ca09050602060c0825160208401600060025af1610f3657600080fd5b60c0519050610b00526001805460018254011015610f5357600080fd5b6001815401815550600154610d2052610d4060006020818352015b60016001610d2051161415610fa357610b0051610d405160208110610f9257600080fd5b600060c052602060c0200155611037565b6000610d405160208110610fb657600080fd5b600060c052602060c0200154602082610d60010152602081019050610b0051602082610d6001015260208101905080610d6052610d609050602060c0825160208401600060025af161100757600080fd5b60c0519050610b0052610d20600261101e57600080fd5b60028151048152505b8151600101808352811415610f6e575b5050005b60006000fd5b6101856111c6036101856000396101856111c6036000f3"} \ No newline at end of file diff --git a/deposit_contract/contracts/validator_registration.v.py b/deposit_contract/contracts/validator_registration.v.py index 10daf42b9..14f100520 100644 --- a/deposit_contract/contracts/validator_registration.v.py +++ b/deposit_contract/contracts/validator_registration.v.py @@ -75,9 +75,12 @@ def deposit(pubkey: bytes[PUBKEY_LENGTH], assert len(withdrawal_credentials) == WITHDRAWAL_CREDENTIALS_LENGTH assert len(signature) == SIGNATURE_LENGTH - # Compute `DepositData` root + # Emit `Deposit` log amount: bytes[8] = self.to_little_endian_64(deposit_amount) - zero_bytes32: bytes32 + log.Deposit(pubkey, withdrawal_credentials, amount, signature, self.to_little_endian_64(self.deposit_count)) + + # Compute `DepositData` root + zero_bytes32: bytes32 = 0x0000000000000000000000000000000000000000000000000000000000000000 pubkey_root: bytes32 = sha256(concat(pubkey, slice(zero_bytes32, start=0, len=64 - PUBKEY_LENGTH))) signature_root: bytes32 = sha256(concat( sha256(slice(signature, start=0, len=64)), @@ -88,9 +91,6 @@ def deposit(pubkey: bytes[PUBKEY_LENGTH], sha256(concat(amount, slice(zero_bytes32, start=0, len=32 - AMOUNT_LENGTH), signature_root)), )) - # Emit `Deposit` log - log.Deposit(pubkey, withdrawal_credentials, amount, signature, self.to_little_endian_64(self.deposit_count)) - # Add `DepositData` root to Merkle tree (update a single `branch` node) self.deposit_count += 1 size: uint256 = self.deposit_count