From 39278b3128b2797f8cc2d705a0ba168bb490440a Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Thu, 15 Aug 2019 01:55:46 +0200 Subject: [PATCH 01/10] Deposit contract fixes --- deposit_contract/contracts/validator_registration.json | 2 +- deposit_contract/contracts/validator_registration.v.py | 9 ++++++--- deposit_contract/tests/contracts/test_deposit.py | 2 +- specs/validator/0_beacon-chain-validator.md | 2 +- test_libs/pyspec/eth2spec/fuzzing/test_decoder.py | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/deposit_contract/contracts/validator_registration.json b/deposit_contract/contracts/validator_registration.json index 3a6bfb2d86..d9996a85fa 100644 --- a/deposit_contract/contracts/validator_registration.json +++ b/deposit_contract/contracts/validator_registration.json @@ -1 +1 @@ -{"abi": [{"name": "DepositEvent", "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_hash_tree_root", "outputs": [{"type": "bytes32", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 91674}, {"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": "0x740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009857600080fd5b6101406000601f818352015b600061014051602081106100b757600080fd5b600260c052602060c020015460208261016001015260208101905061014051602081106100e357600080fd5b600260c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012157600080fd5b60c0519050606051600161014051018060405190131561014057600080fd5b809190121561014e57600080fd5b6020811061015b57600080fd5b600260c052602060c02001555b81516001018083528114156100a4575b50506112f956600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052600015610277575b6101605261014052600061018052610140516101a0526101c060006008818352015b61018051600860008112156100da578060000360020a82046100e1565b8060020a82025b905090506101805260ff6101a051166101e052610180516101e0516101805101101561010c57600080fd5b6101e0516101805101610180526101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff86000811215610155578060000360020a820461015c565b8060020a82025b905090506101a0525b81516001018083528114156100bd575b50506018600860208206610200016020828401111561019357600080fd5b60208061022082610180600060046015f15050818152809050905090508051602001806102c0828460006004600a8704601201f16101d057600080fd5b50506102c05160206001820306601f82010390506103206102c0516008818352015b826103205111156102025761021e565b6000610320516102e001535b81516001018083528114156101f2575b50505060206102a05260406102c0510160206001820306601f8201039050610280525b6000610280511115156102535761026f565b602061028051036102a001516020610280510361028052610241565b610160515650005b63863a311b600051141561050857341561029057600080fd5b6000610140526101405161016052600154610180526101a060006020818352015b60016001610180511614156103325760006101a051602081106102d357600080fd5b600060c052602060c02001546020826102400101526020810190506101605160208261024001015260208101905080610240526102409050602060c0825160208401600060025af161032457600080fd5b60c0519050610160526103a0565b6000610160516020826101c00101526020810190506101a0516020811061035857600080fd5b600260c052602060c02001546020826101c0010152602081019050806101c0526101c09050602060c0825160208401600060025af161039657600080fd5b60c0519050610160525b61018060026103ae57600080fd5b60028151048152505b81516001018083528114156102b1575b505060006101605160208261044001015260208101905061014051610160516101805163806732896102c0526001546102e0526102e0516006580161009b565b506103405260006103a0525b6103405160206001820306601f82010390506103a0511015156104355761044e565b6103a05161036001526103a0516020016103a052610413565b61018052610160526101405261034060088060208461044001018260208501600060046012f150508051820191505060006018602082066103c0016020828401111561049957600080fd5b6020806103e082610140600060046015f150508181528090509050905060188060208461044001018260208501600060046014f150508051820191505080610440526104409050602060c0825160208401600060025af16104f957600080fd5b60c051905060005260206000f3005b63621fd130600051141561061a57341561052157600080fd5b63806732896101405260015461016052610160516006580161009b565b506101c0526000610220525b6101c05160206001820306601f82010390506102205110151561056c57610585565b610220516101e00152610220516020016102205261054a565b6101c0805160200180610280828460006004600a8704601201f16105a857600080fd5b50506102805160206001820306601f82010390506102e0610280516008818352015b826102e05111156105da576105f6565b60006102e0516102a001535b81516001018083528114156105ca575b5050506020610260526040610280510160206001820306601f8201039050610260f3005b63c47e300d600051141561117457606060046101403760506004356004016101a037603060043560040135111561065057600080fd5b604060243560040161022037602060243560040135111561067057600080fd5b608060443560040161028037606060443560040135111561069057600080fd5b63ffffffff600154106106a257600080fd5b633b9aca0061034052610340516106b857600080fd5b61034051340461032052633b9aca006103205110156106d657600080fd5b60306101a051146106e657600080fd5b602061022051146106f657600080fd5b6060610280511461070657600080fd5b6101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a05163806732896103c052610320516103e0526103e0516006580161009b565b506104405260006104a0525b6104405160206001820306601f82010390506104a051101515610796576107af565b6104a05161046001526104a0516020016104a052610774565b6103a05261038052610360526103405261032052610300526102e0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a052610440805160200180610360828460006004600a8704601201f161081657600080fd5b50506101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a0516103c0516103e05161040051610420516104405161046051610480516104a05163806732896104c0526001546104e0526104e0516006580161009b565b506105405260006105a0525b6105405160206001820306601f82010390506105a0511015156108c7576108e0565b6105a05161056001526105a0516020016105a0526108a5565b6104a05261048052610460526104405261042052610400526103e0526103c0526103a05261038052610360526103405261032052610300526102e0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a0526105408051602001806105c0828460006004600a8704601201f161096757600080fd5b505060a06106405261064051610680526101a08051602001806106405161068001828460006004600a8704601201f161099f57600080fd5b505061064051610680015160206001820306601f8201039050610640516106800161062081516040818352015b83610620511015156109dd576109fa565b6000610620516020850101535b81516001018083528114156109cc575b50505050602061064051610680015160206001820306601f820103905061064051010161064052610640516106a0526102208051602001806106405161068001828460006004600a8704601201f1610a5157600080fd5b505061064051610680015160206001820306601f8201039050610640516106800161062081516020818352015b8361062051101515610a8f57610aac565b6000610620516020850101535b8151600101808352811415610a7e575b50505050602061064051610680015160206001820306601f820103905061064051010161064052610640516106c0526103608051602001806106405161068001828460006004600a8704601201f1610b0357600080fd5b505061064051610680015160206001820306601f8201039050610640516106800161062081516020818352015b8361062051101515610b4157610b5e565b6000610620516020850101535b8151600101808352811415610b30575b50505050602061064051610680015160206001820306601f820103905061064051010161064052610640516106e0526102808051602001806106405161068001828460006004600a8704601201f1610bb557600080fd5b505061064051610680015160206001820306601f8201039050610640516106800161062081516060818352015b8361062051101515610bf357610c10565b6000610620516020850101535b8151600101808352811415610be2575b50505050602061064051610680015160206001820306601f82010390506106405101016106405261064051610700526105c08051602001806106405161068001828460006004600a8704601201f1610c6757600080fd5b505061064051610680015160206001820306601f8201039050610640516106800161062081516020818352015b8361062051101515610ca557610cc2565b6000610620516020850101535b8151600101808352811415610c94575b50505050602061064051610680015160206001820306601f8201039050610640510101610640527f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c561064051610680a160006107205260006101a06030806020846107e001018260208501600060046016f150508051820191505060006010602082066107600160208284011115610d5957600080fd5b60208061078082610720600060046015f15050818152809050905090506010806020846107e001018260208501600060046013f1505080518201915050806107e0526107e09050602060c0825160208401600060025af1610db957600080fd5b60c0519050610740526000600060406020820661088001610280518284011115610de257600080fd5b6060806108a0826020602088068803016102800160006004601bf1505081815280905090509050602060c0825160208401600060025af1610e2257600080fd5b60c0519050602082610a800101526020810190506000604060206020820661094001610280518284011115610e5657600080fd5b606080610960826020602088068803016102800160006004601bf1505081815280905090509050602080602084610a0001018260208501600060046015f150508051820191505061072051602082610a0001015260208101905080610a0052610a009050602060c0825160208401600060025af1610ed357600080fd5b60c0519050602082610a8001015260208101905080610a8052610a809050602060c0825160208401600060025af1610f0a57600080fd5b60c0519050610860526000600061074051602082610b20010152602081019050610220602080602084610b2001018260208501600060046015f150508051820191505080610b2052610b209050602060c0825160208401600060025af1610f7057600080fd5b60c0519050602082610ca00101526020810190506000610360600880602084610c2001018260208501600060046012f15050805182019150506000601860208206610ba00160208284011115610fc557600080fd5b602080610bc082610720600060046015f1505081815280905090509050601880602084610c2001018260208501600060046014f150508051820191505061086051602082610c2001015260208101905080610c2052610c209050602060c0825160208401600060025af161103857600080fd5b60c0519050602082610ca001015260208101905080610ca052610ca09050602060c0825160208401600060025af161106f57600080fd5b60c0519050610b0052600180546001825401101561108c57600080fd5b6001815401815550600154610d2052610d4060006020818352015b60016001610d20511614156110dc57610b0051610d4051602081106110cb57600080fd5b600060c052602060c0200155611170565b6000610d4051602081106110ef57600080fd5b600060c052602060c0200154602082610d60010152602081019050610b0051602082610d6001015260208101905080610d6052610d609050602060c0825160208401600060025af161114057600080fd5b60c0519050610b0052610d20600261115757600080fd5b60028151048152505b81516001018083528114156110a7575b5050005b60006000fd5b61017f6112f90361017f60003961017f6112f9036000f3"} \ No newline at end of file +{"abi": [{"name": "DepositEvent", "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": 91674}, {"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"}, {"type": "bytes32", "name": "deposit_data_root"}], "constant": false, "payable": true, "type": "function", "gas": 1334547}], "bytecode": "0x740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009857600080fd5b6101406000601f818352015b600061014051602081106100b757600080fd5b600260c052602060c020015460208261016001015260208101905061014051602081106100e357600080fd5b600260c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012157600080fd5b60c0519050606051600161014051018060405190131561014057600080fd5b809190121561014e57600080fd5b6020811061015b57600080fd5b600260c052602060c02001555b81516001018083528114156100a4575b505061131b56600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052600015610277575b6101605261014052600061018052610140516101a0526101c060006008818352015b61018051600860008112156100da578060000360020a82046100e1565b8060020a82025b905090506101805260ff6101a051166101e052610180516101e0516101805101101561010c57600080fd5b6101e0516101805101610180526101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff86000811215610155578060000360020a820461015c565b8060020a82025b905090506101a0525b81516001018083528114156100bd575b50506018600860208206610200016020828401111561019357600080fd5b60208061022082610180600060046015f15050818152809050905090508051602001806102c0828460006004600a8704601201f16101d057600080fd5b50506102c05160206001820306601f82010390506103206102c0516008818352015b826103205111156102025761021e565b6000610320516102e001535b81516001018083528114156101f2575b50505060206102a05260406102c0510160206001820306601f8201039050610280525b6000610280511115156102535761026f565b602061028051036102a001516020610280510361028052610241565b610160515650005b63c5f2892f600051141561050857341561029057600080fd5b6000610140526101405161016052600154610180526101a060006020818352015b60016001610180511614156103325760006101a051602081106102d357600080fd5b600060c052602060c02001546020826102400101526020810190506101605160208261024001015260208101905080610240526102409050602060c0825160208401600060025af161032457600080fd5b60c0519050610160526103a0565b6000610160516020826101c00101526020810190506101a0516020811061035857600080fd5b600260c052602060c02001546020826101c0010152602081019050806101c0526101c09050602060c0825160208401600060025af161039657600080fd5b60c0519050610160525b61018060026103ae57600080fd5b60028151048152505b81516001018083528114156102b1575b505060006101605160208261044001015260208101905061014051610160516101805163806732896102c0526001546102e0526102e0516006580161009b565b506103405260006103a0525b6103405160206001820306601f82010390506103a0511015156104355761044e565b6103a05161036001526103a0516020016103a052610413565b61018052610160526101405261034060088060208461044001018260208501600060046012f150508051820191505060006018602082066103c0016020828401111561049957600080fd5b6020806103e082610140600060046015f150508181528090509050905060188060208461044001018260208501600060046014f150508051820191505080610440526104409050602060c0825160208401600060025af16104f957600080fd5b60c051905060005260206000f3005b63621fd130600051141561061a57341561052157600080fd5b63806732896101405260015461016052610160516006580161009b565b506101c0526000610220525b6101c05160206001820306601f82010390506102205110151561056c57610585565b610220516101e00152610220516020016102205261054a565b6101c0805160200180610280828460006004600a8704601201f16105a857600080fd5b50506102805160206001820306601f82010390506102e0610280516008818352015b826102e05111156105da576105f6565b60006102e0516102a001535b81516001018083528114156105ca575b5050506020610260526040610280510160206001820306601f8201039050610260f3005b6322895118600051141561119657608060046101403760506004356004016101c037603060043560040135111561065057600080fd5b604060243560040161024037602060243560040135111561067057600080fd5b60806044356004016102a037606060443560040135111561069057600080fd5b63ffffffff600154106106a257600080fd5b633b9aca0061036052610360516106b857600080fd5b61036051340461034052633b9aca006103405110156106d657600080fd5b60306101c051146106e657600080fd5b602061024051146106f657600080fd5b60606102a0511461070657600080fd5b6101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a0516103c05163806732896103e0526103405161040052610400516006580161009b565b506104605260006104c0525b6104605160206001820306601f82010390506104c05110151561079a576107b3565b6104c05161048001526104c0516020016104c052610778565b6103c0526103a05261038052610360526103405261032052610300526102e0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a052610460805160200180610380828460006004600a8704601201f161081e57600080fd5b50506101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a0516103c0516103e05161040051610420516104405161046051610480516104a0516104c05163806732896104e05260015461050052610500516006580161009b565b506105605260006105c0525b6105605160206001820306601f82010390506105c0511015156108d3576108ec565b6105c05161058001526105c0516020016105c0526108b1565b6104c0526104a05261048052610460526104405261042052610400526103e0526103c0526103a05261038052610360526103405261032052610300526102e0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a0526105608051602001806105e0828460006004600a8704601201f161097757600080fd5b505060a061066052610660516106a0526101c0805160200180610660516106a001828460006004600a8704601201f16109af57600080fd5b5050610660516106a0015160206001820306601f8201039050610660516106a00161064081516040818352015b83610640511015156109ed57610a0a565b6000610640516020850101535b81516001018083528114156109dc575b505050506020610660516106a0015160206001820306601f820103905061066051010161066052610660516106c052610240805160200180610660516106a001828460006004600a8704601201f1610a6157600080fd5b5050610660516106a0015160206001820306601f8201039050610660516106a00161064081516020818352015b8361064051101515610a9f57610abc565b6000610640516020850101535b8151600101808352811415610a8e575b505050506020610660516106a0015160206001820306601f820103905061066051010161066052610660516106e052610380805160200180610660516106a001828460006004600a8704601201f1610b1357600080fd5b5050610660516106a0015160206001820306601f8201039050610660516106a00161064081516020818352015b8361064051101515610b5157610b6e565b6000610640516020850101535b8151600101808352811415610b40575b505050506020610660516106a0015160206001820306601f82010390506106605101016106605261066051610700526102a0805160200180610660516106a001828460006004600a8704601201f1610bc557600080fd5b5050610660516106a0015160206001820306601f8201039050610660516106a00161064081516060818352015b8361064051101515610c0357610c20565b6000610640516020850101535b8151600101808352811415610bf2575b505050506020610660516106a0015160206001820306601f82010390506106605101016106605261066051610720526105e0805160200180610660516106a001828460006004600a8704601201f1610c7757600080fd5b5050610660516106a0015160206001820306601f8201039050610660516106a00161064081516020818352015b8361064051101515610cb557610cd2565b6000610640516020850101535b8151600101808352811415610ca4575b505050506020610660516106a0015160206001820306601f8201039050610660510101610660527f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5610660516106a0a160006107405260006101c060308060208461080001018260208501600060046016f150508051820191505060006010602082066107800160208284011115610d6957600080fd5b6020806107a082610740600060046015f150508181528090509050905060108060208461080001018260208501600060046013f150508051820191505080610800526108009050602060c0825160208401600060025af1610dc957600080fd5b60c051905061076052600060006040602082066108a0016102a0518284011115610df257600080fd5b6060806108c0826020602088068803016102a00160006004601bf1505081815280905090509050602060c0825160208401600060025af1610e3257600080fd5b60c0519050602082610aa001015260208101905060006040602060208206610960016102a0518284011115610e6657600080fd5b606080610980826020602088068803016102a00160006004601bf1505081815280905090509050602080602084610a2001018260208501600060046015f150508051820191505061074051602082610a2001015260208101905080610a2052610a209050602060c0825160208401600060025af1610ee357600080fd5b60c0519050602082610aa001015260208101905080610aa052610aa09050602060c0825160208401600060025af1610f1a57600080fd5b60c0519050610880526000600061076051602082610b40010152602081019050610240602080602084610b4001018260208501600060046015f150508051820191505080610b4052610b409050602060c0825160208401600060025af1610f8057600080fd5b60c0519050602082610cc00101526020810190506000610380600880602084610c4001018260208501600060046012f15050805182019150506000601860208206610bc00160208284011115610fd557600080fd5b602080610be082610740600060046015f1505081815280905090509050601880602084610c4001018260208501600060046014f150508051820191505061088051602082610c4001015260208101905080610c4052610c409050602060c0825160208401600060025af161104857600080fd5b60c0519050602082610cc001015260208101905080610cc052610cc09050602060c0825160208401600060025af161107f57600080fd5b60c0519050610b20526101a051610b20511461109a57600080fd5b60018054600182540110156110ae57600080fd5b6001815401815550600154610d4052610d6060006020818352015b60016001610d40511614156110fe57610b2051610d6051602081106110ed57600080fd5b600060c052602060c0200155611192565b6000610d60516020811061111157600080fd5b600060c052602060c0200154602082610d80010152602081019050610b2051602082610d8001015260208101905080610d8052610d809050602060c0825160208401600060025af161116257600080fd5b60c0519050610b2052610d40600261117957600080fd5b60028151048152505b81516001018083528114156110c9575b5050005b60006000fd5b61017f61131b0361017f60003961017f61131b036000f3"} \ 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 bad619b076..2abb66386e 100644 --- a/deposit_contract/contracts/validator_registration.v.py +++ b/deposit_contract/contracts/validator_registration.v.py @@ -3,8 +3,8 @@ 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 SIGNATURE_LENGTH: constant(uint256) = 96 # bytes +AMOUNT_LENGTH: constant(uint256) = 8 # bytes DepositEvent: event({ pubkey: bytes[48], @@ -42,7 +42,7 @@ def to_little_endian_64(value: uint256) -> bytes[8]: @public @constant -def get_hash_tree_root() -> bytes32: +def get_deposit_root() -> bytes32: zero_bytes32: bytes32 = 0x0000000000000000000000000000000000000000000000000000000000000000 node: bytes32 = zero_bytes32 size: uint256 = self.deposit_count @@ -65,7 +65,8 @@ def get_deposit_count() -> bytes[8]: @public def deposit(pubkey: bytes[PUBKEY_LENGTH], withdrawal_credentials: bytes[WITHDRAWAL_CREDENTIALS_LENGTH], - signature: bytes[SIGNATURE_LENGTH]): + signature: bytes[SIGNATURE_LENGTH], + deposit_data_root: bytes32): # Avoid overflowing the Merkle tree (and prevent edge case in computing `self.branch`) assert self.deposit_count < MAX_DEPOSIT_COUNT @@ -91,6 +92,8 @@ def deposit(pubkey: bytes[PUBKEY_LENGTH], sha256(concat(pubkey_root, withdrawal_credentials)), sha256(concat(amount, slice(zero_bytes32, start=0, len=32 - AMOUNT_LENGTH), signature_root)), )) + # Verify calculated and expected deposit data roots match + assert node == deposit_data_root # Add `DepositData` hash tree root to Merkle tree (update a single `branch` node) self.deposit_count += 1 diff --git a/deposit_contract/tests/contracts/test_deposit.py b/deposit_contract/tests/contracts/test_deposit.py index 1c96d074ec..7d8d2e9966 100644 --- a/deposit_contract/tests/contracts/test_deposit.py +++ b/deposit_contract/tests/contracts/test_deposit.py @@ -146,4 +146,4 @@ def test_deposit_tree(registration_contract, w3, assert_tx_failed, deposit_input )) root = hash_tree_root(List[DepositData, 2**32](*deposit_data_list)) - assert root == registration_contract.functions.get_hash_tree_root().call() + assert root == registration_contract.functions.get_deposit_root().call() diff --git a/specs/validator/0_beacon-chain-validator.md b/specs/validator/0_beacon-chain-validator.md index 188a6a2911..077c79beec 100644 --- a/specs/validator/0_beacon-chain-validator.md +++ b/specs/validator/0_beacon-chain-validator.md @@ -218,7 +218,7 @@ def get_epoch_signature(state: BeaconState, block: BeaconBlock, privkey: int) -> ##### Eth1 Data -The `block.eth1_data` field is for block proposers to vote on recent Eth 1.0 data. This recent data contains an Eth 1.0 block hash as well as the associated deposit root (as calculated by the `get_hash_tree_root()` method of the deposit contract) and deposit count after execution of the corresponding Eth 1.0 block. If over half of the block proposers in the current Eth 1.0 voting period vote for the same `eth1_data` then `state.eth1_data` updates at the end of the voting period. Each deposit in `block.body.deposits` must verify against `state.eth1_data.eth1_deposit_root`. +The `block.eth1_data` field is for block proposers to vote on recent Eth 1.0 data. This recent data contains an Eth 1.0 block hash as well as the associated deposit root (as calculated by the `get_deposit_root()` method of the deposit contract) and deposit count after execution of the corresponding Eth 1.0 block. If over half of the block proposers in the current Eth 1.0 voting period vote for the same `eth1_data` then `state.eth1_data` updates at the end of the voting period. Each deposit in `block.body.deposits` must verify against `state.eth1_data.eth1_deposit_root`. Let `get_eth1_data(distance: uint64) -> Eth1Data` be the (subjective) function that returns the Eth 1.0 data at distance `distance` relative to the Eth 1.0 head at the start of the current Eth 1.0 voting period. Let `previous_eth1_distance` be the distance relative to the Eth 1.0 block corresponding to `state.eth1_data.block_hash` at the start of the current Eth 1.0 voting period. An honest block proposer sets `block.eth1_data = get_eth1_vote(state, previous_eth1_distance)` where: diff --git a/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py b/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py index 77b52e7a21..60f53f3836 100644 --- a/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py +++ b/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py @@ -32,4 +32,4 @@ def test_decoder(): # and see if the hash-tree-root of the original matches the hash-tree-root of the decoded & translated value. original_hash_tree_root = spec_ssz_impl.hash_tree_root(original) assert original_hash_tree_root == spec_ssz_impl.hash_tree_root(block) - assert original_hash_tree_root == block_sedes.get_hash_tree_root(raw_value) + assert original_hash_tree_root == block_sedes.get_deposit_root(raw_value) From 891524f3fa109f6e22ca074edd73aa5f2b559c5f Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 15 Aug 2019 11:11:20 +0800 Subject: [PATCH 02/10] Fix tests --- .../tests/contracts/test_deposit.py | 107 +++++++++++++----- 1 file changed, 78 insertions(+), 29 deletions(-) diff --git a/deposit_contract/tests/contracts/test_deposit.py b/deposit_contract/tests/contracts/test_deposit.py index 7d8d2e9966..d7c84b0169 100644 --- a/deposit_contract/tests/contracts/test_deposit.py +++ b/deposit_contract/tests/contracts/test_deposit.py @@ -6,7 +6,6 @@ import eth_utils from tests.contracts.conftest import ( - DEPOSIT_CONTRACT_TREE_DEPTH, FULL_DEPOSIT_AMOUNT, MIN_DEPOSIT_AMOUNT, ) @@ -14,29 +13,42 @@ from eth2spec.phase0.spec import ( DepositData, ) -from eth2spec.utils.hash_function import hash from eth2spec.utils.ssz.ssz_typing import List from eth2spec.utils.ssz.ssz_impl import ( hash_tree_root, ) +SAMPLE_PUBKEY = b'\x11' * 48 +SAMPLE_WITHDRAWAL_CREDENTIALS = b'\x22' * 32 +SAMPLE_VALID_SIGNATURE = b'\x33' * 96 + + @pytest.fixture -def deposit_input(): +def deposit_input(amount): """ pubkey: bytes[48] withdrawal_credentials: bytes[32] signature: bytes[96] + deposit_data_root: bytes[32] """ return ( - b'\x11' * 48, - b'\x22' * 32, - b'\x33' * 96, + SAMPLE_PUBKEY, + SAMPLE_WITHDRAWAL_CREDENTIALS, + SAMPLE_VALID_SIGNATURE, + hash_tree_root( + DepositData( + pubkey=SAMPLE_PUBKEY, + withdrawal_credentials=SAMPLE_WITHDRAWAL_CREDENTIALS, + amount=amount, + signature=SAMPLE_VALID_SIGNATURE, + ), + ) ) @pytest.mark.parametrize( - 'success,deposit_amount', + ('success', 'amount'), [ (True, FULL_DEPOSIT_AMOUNT), (True, MIN_DEPOSIT_AMOUNT), @@ -47,18 +59,24 @@ def deposit_input(): def test_deposit_amount(registration_contract, w3, success, - deposit_amount, + amount, assert_tx_failed, deposit_input): call = registration_contract.functions.deposit(*deposit_input) if success: - assert call.transact({"value": deposit_amount * eth_utils.denoms.gwei}) + assert call.transact({"value": amount * eth_utils.denoms.gwei}) else: assert_tx_failed( - lambda: call.transact({"value": deposit_amount * eth_utils.denoms.gwei}) + lambda: call.transact({"value": amount * eth_utils.denoms.gwei}) ) +@pytest.mark.parametrize( + 'amount', + [ + (FULL_DEPOSIT_AMOUNT) + ] +) @pytest.mark.parametrize( 'invalid_pubkey,invalid_withdrawal_credentials,invalid_signature,success', [ @@ -71,38 +89,62 @@ def test_deposit_amount(registration_contract, def test_deposit_inputs(registration_contract, w3, assert_tx_failed, - deposit_input, + amount, invalid_pubkey, invalid_withdrawal_credentials, invalid_signature, success): - pubkey = deposit_input[0][2:] if invalid_pubkey else deposit_input[0] - if invalid_withdrawal_credentials: # this one is different to satisfy linter - withdrawal_credentials = deposit_input[1][2:] - else: - withdrawal_credentials = deposit_input[1] - signature = deposit_input[2][2:] if invalid_signature else deposit_input[2] + pubkey = SAMPLE_PUBKEY[2:] if invalid_pubkey else SAMPLE_PUBKEY + withdrawal_credentials = ( + SAMPLE_WITHDRAWAL_CREDENTIALS[2:] if invalid_withdrawal_credentials + else SAMPLE_WITHDRAWAL_CREDENTIALS + ) + signature = SAMPLE_VALID_SIGNATURE[2:] if invalid_signature else SAMPLE_VALID_SIGNATURE call = registration_contract.functions.deposit( pubkey, withdrawal_credentials, signature, + hash_tree_root( + DepositData( + pubkey=SAMPLE_PUBKEY if invalid_pubkey else pubkey, + withdrawal_credentials=( + SAMPLE_WITHDRAWAL_CREDENTIALS if invalid_withdrawal_credentials + else withdrawal_credentials + ), + amount=amount, + signature=SAMPLE_VALID_SIGNATURE if invalid_signature else signature, + ), + ) ) if success: - assert call.transact({"value": FULL_DEPOSIT_AMOUNT * eth_utils.denoms.gwei}) + assert call.transact({"value": amount * eth_utils.denoms.gwei}) else: assert_tx_failed( - lambda: call.transact({"value": FULL_DEPOSIT_AMOUNT * eth_utils.denoms.gwei}) + lambda: call.transact({"value": amount * eth_utils.denoms.gwei}) ) -def test_deposit_event_log(registration_contract, a0, w3, deposit_input): +def test_deposit_event_log(registration_contract, a0, w3): log_filter = registration_contract.events.DepositEvent.createFilter( fromBlock='latest', ) - deposit_amount_list = [randint(MIN_DEPOSIT_AMOUNT, FULL_DEPOSIT_AMOUNT * 2) for _ in range(3)] + for i in range(3): + deposit_input = ( + SAMPLE_PUBKEY, + SAMPLE_WITHDRAWAL_CREDENTIALS, + SAMPLE_VALID_SIGNATURE, + hash_tree_root( + DepositData( + pubkey=SAMPLE_PUBKEY, + withdrawal_credentials=SAMPLE_WITHDRAWAL_CREDENTIALS, + amount=deposit_amount_list[i], + signature=SAMPLE_VALID_SIGNATURE, + ), + ) + ) registration_contract.functions.deposit( *deposit_input, ).transact({"value": deposit_amount_list[i] * eth_utils.denoms.gwei}) @@ -118,7 +160,7 @@ def test_deposit_event_log(registration_contract, a0, w3, deposit_input): assert log['index'] == i.to_bytes(8, 'little') -def test_deposit_tree(registration_contract, w3, assert_tx_failed, deposit_input): +def test_deposit_tree(registration_contract, w3, assert_tx_failed): log_filter = registration_contract.events.DepositEvent.createFilter( fromBlock='latest', ) @@ -126,6 +168,20 @@ def test_deposit_tree(registration_contract, w3, assert_tx_failed, deposit_input deposit_amount_list = [randint(MIN_DEPOSIT_AMOUNT, FULL_DEPOSIT_AMOUNT * 2) for _ in range(10)] deposit_data_list = [] for i in range(0, 10): + deposit_data = DepositData( + pubkey=SAMPLE_PUBKEY, + withdrawal_credentials=SAMPLE_WITHDRAWAL_CREDENTIALS, + amount=deposit_amount_list[i], + signature=SAMPLE_VALID_SIGNATURE, + ) + deposit_input = ( + SAMPLE_PUBKEY, + SAMPLE_WITHDRAWAL_CREDENTIALS, + SAMPLE_VALID_SIGNATURE, + hash_tree_root(deposit_data), + ) + deposit_data_list.append(deposit_data) + tx_hash = registration_contract.functions.deposit( *deposit_input, ).transact({"value": deposit_amount_list[i] * eth_utils.denoms.gwei}) @@ -138,12 +194,5 @@ def test_deposit_tree(registration_contract, w3, assert_tx_failed, deposit_input assert log["index"] == i.to_bytes(8, 'little') - deposit_data_list.append(DepositData( - pubkey=deposit_input[0], - withdrawal_credentials=deposit_input[1], - amount=deposit_amount_list[i], - signature=deposit_input[2], - )) - root = hash_tree_root(List[DepositData, 2**32](*deposit_data_list)) assert root == registration_contract.functions.get_deposit_root().call() From f6ec2786890d2aa272919c9c86f3e6a8f9c02973 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 15 Aug 2019 11:17:12 +0800 Subject: [PATCH 03/10] This `BeaconBlock.get_hash_tree_root(block)` API is from py-ssz --- test_libs/pyspec/eth2spec/fuzzing/test_decoder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py b/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py index 60f53f3836..77b52e7a21 100644 --- a/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py +++ b/test_libs/pyspec/eth2spec/fuzzing/test_decoder.py @@ -32,4 +32,4 @@ def test_decoder(): # and see if the hash-tree-root of the original matches the hash-tree-root of the decoded & translated value. original_hash_tree_root = spec_ssz_impl.hash_tree_root(original) assert original_hash_tree_root == spec_ssz_impl.hash_tree_root(block) - assert original_hash_tree_root == block_sedes.get_deposit_root(raw_value) + assert original_hash_tree_root == block_sedes.get_hash_tree_root(raw_value) From 08d32a8b880864ceeac26299032583a2af45b49d Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 15 Aug 2019 12:30:06 +0200 Subject: [PATCH 04/10] Update validator_registration.v.py --- deposit_contract/contracts/validator_registration.v.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/deposit_contract/contracts/validator_registration.v.py b/deposit_contract/contracts/validator_registration.v.py index 2abb66386e..be10ed478c 100644 --- a/deposit_contract/contracts/validator_registration.v.py +++ b/deposit_contract/contracts/validator_registration.v.py @@ -70,18 +70,15 @@ def deposit(pubkey: bytes[PUBKEY_LENGTH], # Avoid overflowing the Merkle tree (and prevent edge case in computing `self.branch`) assert self.deposit_count < MAX_DEPOSIT_COUNT - # Validate deposit data + # Check deposit amount 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 # Emit `DepositEvent` log amount: bytes[8] = self.to_little_endian_64(deposit_amount) log.DepositEvent(pubkey, withdrawal_credentials, amount, signature, self.to_little_endian_64(self.deposit_count)) - # Compute `DepositData` hash tree root + # Compute deposit data root (`DepositData` hash tree 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( @@ -95,7 +92,7 @@ def deposit(pubkey: bytes[PUBKEY_LENGTH], # Verify calculated and expected deposit data roots match assert node == deposit_data_root - # Add `DepositData` hash tree root to Merkle tree (update a single `branch` node) + # Add deposit data root to Merkle tree (update a single `branch` node) self.deposit_count += 1 size: uint256 = self.deposit_count for height in range(DEPOSIT_CONTRACT_TREE_DEPTH): From 7950ef05f0eaf0aba6d60a031eb216f14f332a0d Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 15 Aug 2019 12:31:20 +0200 Subject: [PATCH 05/10] Update validator_registration.v.py --- deposit_contract/contracts/validator_registration.v.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deposit_contract/contracts/validator_registration.v.py b/deposit_contract/contracts/validator_registration.v.py index be10ed478c..1c1eb5fc7e 100644 --- a/deposit_contract/contracts/validator_registration.v.py +++ b/deposit_contract/contracts/validator_registration.v.py @@ -89,7 +89,7 @@ def deposit(pubkey: bytes[PUBKEY_LENGTH], sha256(concat(pubkey_root, withdrawal_credentials)), sha256(concat(amount, slice(zero_bytes32, start=0, len=32 - AMOUNT_LENGTH), signature_root)), )) - # Verify calculated and expected deposit data roots match + # Verify computed and expected deposit data roots match assert node == deposit_data_root # Add deposit data root to Merkle tree (update a single `branch` node) From 162c30dddfc5bb54422469eb07413b6755caf014 Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Thu, 15 Aug 2019 12:34:54 +0200 Subject: [PATCH 06/10] Recompile contract --- deposit_contract/contracts/validator_registration.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deposit_contract/contracts/validator_registration.json b/deposit_contract/contracts/validator_registration.json index d9996a85fa..d9a8892caf 100644 --- a/deposit_contract/contracts/validator_registration.json +++ b/deposit_contract/contracts/validator_registration.json @@ -1 +1 @@ -{"abi": [{"name": "DepositEvent", "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": 91674}, {"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"}, {"type": "bytes32", "name": "deposit_data_root"}], "constant": false, "payable": true, "type": "function", "gas": 1334547}], "bytecode": "0x740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009857600080fd5b6101406000601f818352015b600061014051602081106100b757600080fd5b600260c052602060c020015460208261016001015260208101905061014051602081106100e357600080fd5b600260c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012157600080fd5b60c0519050606051600161014051018060405190131561014057600080fd5b809190121561014e57600080fd5b6020811061015b57600080fd5b600260c052602060c02001555b81516001018083528114156100a4575b505061131b56600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052600015610277575b6101605261014052600061018052610140516101a0526101c060006008818352015b61018051600860008112156100da578060000360020a82046100e1565b8060020a82025b905090506101805260ff6101a051166101e052610180516101e0516101805101101561010c57600080fd5b6101e0516101805101610180526101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff86000811215610155578060000360020a820461015c565b8060020a82025b905090506101a0525b81516001018083528114156100bd575b50506018600860208206610200016020828401111561019357600080fd5b60208061022082610180600060046015f15050818152809050905090508051602001806102c0828460006004600a8704601201f16101d057600080fd5b50506102c05160206001820306601f82010390506103206102c0516008818352015b826103205111156102025761021e565b6000610320516102e001535b81516001018083528114156101f2575b50505060206102a05260406102c0510160206001820306601f8201039050610280525b6000610280511115156102535761026f565b602061028051036102a001516020610280510361028052610241565b610160515650005b63c5f2892f600051141561050857341561029057600080fd5b6000610140526101405161016052600154610180526101a060006020818352015b60016001610180511614156103325760006101a051602081106102d357600080fd5b600060c052602060c02001546020826102400101526020810190506101605160208261024001015260208101905080610240526102409050602060c0825160208401600060025af161032457600080fd5b60c0519050610160526103a0565b6000610160516020826101c00101526020810190506101a0516020811061035857600080fd5b600260c052602060c02001546020826101c0010152602081019050806101c0526101c09050602060c0825160208401600060025af161039657600080fd5b60c0519050610160525b61018060026103ae57600080fd5b60028151048152505b81516001018083528114156102b1575b505060006101605160208261044001015260208101905061014051610160516101805163806732896102c0526001546102e0526102e0516006580161009b565b506103405260006103a0525b6103405160206001820306601f82010390506103a0511015156104355761044e565b6103a05161036001526103a0516020016103a052610413565b61018052610160526101405261034060088060208461044001018260208501600060046012f150508051820191505060006018602082066103c0016020828401111561049957600080fd5b6020806103e082610140600060046015f150508181528090509050905060188060208461044001018260208501600060046014f150508051820191505080610440526104409050602060c0825160208401600060025af16104f957600080fd5b60c051905060005260206000f3005b63621fd130600051141561061a57341561052157600080fd5b63806732896101405260015461016052610160516006580161009b565b506101c0526000610220525b6101c05160206001820306601f82010390506102205110151561056c57610585565b610220516101e00152610220516020016102205261054a565b6101c0805160200180610280828460006004600a8704601201f16105a857600080fd5b50506102805160206001820306601f82010390506102e0610280516008818352015b826102e05111156105da576105f6565b60006102e0516102a001535b81516001018083528114156105ca575b5050506020610260526040610280510160206001820306601f8201039050610260f3005b6322895118600051141561119657608060046101403760506004356004016101c037603060043560040135111561065057600080fd5b604060243560040161024037602060243560040135111561067057600080fd5b60806044356004016102a037606060443560040135111561069057600080fd5b63ffffffff600154106106a257600080fd5b633b9aca0061036052610360516106b857600080fd5b61036051340461034052633b9aca006103405110156106d657600080fd5b60306101c051146106e657600080fd5b602061024051146106f657600080fd5b60606102a0511461070657600080fd5b6101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a0516103c05163806732896103e0526103405161040052610400516006580161009b565b506104605260006104c0525b6104605160206001820306601f82010390506104c05110151561079a576107b3565b6104c05161048001526104c0516020016104c052610778565b6103c0526103a05261038052610360526103405261032052610300526102e0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a052610460805160200180610380828460006004600a8704601201f161081e57600080fd5b50506101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a0516103c0516103e05161040051610420516104405161046051610480516104a0516104c05163806732896104e05260015461050052610500516006580161009b565b506105605260006105c0525b6105605160206001820306601f82010390506105c0511015156108d3576108ec565b6105c05161058001526105c0516020016105c0526108b1565b6104c0526104a05261048052610460526104405261042052610400526103e0526103c0526103a05261038052610360526103405261032052610300526102e0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a0526105608051602001806105e0828460006004600a8704601201f161097757600080fd5b505060a061066052610660516106a0526101c0805160200180610660516106a001828460006004600a8704601201f16109af57600080fd5b5050610660516106a0015160206001820306601f8201039050610660516106a00161064081516040818352015b83610640511015156109ed57610a0a565b6000610640516020850101535b81516001018083528114156109dc575b505050506020610660516106a0015160206001820306601f820103905061066051010161066052610660516106c052610240805160200180610660516106a001828460006004600a8704601201f1610a6157600080fd5b5050610660516106a0015160206001820306601f8201039050610660516106a00161064081516020818352015b8361064051101515610a9f57610abc565b6000610640516020850101535b8151600101808352811415610a8e575b505050506020610660516106a0015160206001820306601f820103905061066051010161066052610660516106e052610380805160200180610660516106a001828460006004600a8704601201f1610b1357600080fd5b5050610660516106a0015160206001820306601f8201039050610660516106a00161064081516020818352015b8361064051101515610b5157610b6e565b6000610640516020850101535b8151600101808352811415610b40575b505050506020610660516106a0015160206001820306601f82010390506106605101016106605261066051610700526102a0805160200180610660516106a001828460006004600a8704601201f1610bc557600080fd5b5050610660516106a0015160206001820306601f8201039050610660516106a00161064081516060818352015b8361064051101515610c0357610c20565b6000610640516020850101535b8151600101808352811415610bf2575b505050506020610660516106a0015160206001820306601f82010390506106605101016106605261066051610720526105e0805160200180610660516106a001828460006004600a8704601201f1610c7757600080fd5b5050610660516106a0015160206001820306601f8201039050610660516106a00161064081516020818352015b8361064051101515610cb557610cd2565b6000610640516020850101535b8151600101808352811415610ca4575b505050506020610660516106a0015160206001820306601f8201039050610660510101610660527f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5610660516106a0a160006107405260006101c060308060208461080001018260208501600060046016f150508051820191505060006010602082066107800160208284011115610d6957600080fd5b6020806107a082610740600060046015f150508181528090509050905060108060208461080001018260208501600060046013f150508051820191505080610800526108009050602060c0825160208401600060025af1610dc957600080fd5b60c051905061076052600060006040602082066108a0016102a0518284011115610df257600080fd5b6060806108c0826020602088068803016102a00160006004601bf1505081815280905090509050602060c0825160208401600060025af1610e3257600080fd5b60c0519050602082610aa001015260208101905060006040602060208206610960016102a0518284011115610e6657600080fd5b606080610980826020602088068803016102a00160006004601bf1505081815280905090509050602080602084610a2001018260208501600060046015f150508051820191505061074051602082610a2001015260208101905080610a2052610a209050602060c0825160208401600060025af1610ee357600080fd5b60c0519050602082610aa001015260208101905080610aa052610aa09050602060c0825160208401600060025af1610f1a57600080fd5b60c0519050610880526000600061076051602082610b40010152602081019050610240602080602084610b4001018260208501600060046015f150508051820191505080610b4052610b409050602060c0825160208401600060025af1610f8057600080fd5b60c0519050602082610cc00101526020810190506000610380600880602084610c4001018260208501600060046012f15050805182019150506000601860208206610bc00160208284011115610fd557600080fd5b602080610be082610740600060046015f1505081815280905090509050601880602084610c4001018260208501600060046014f150508051820191505061088051602082610c4001015260208101905080610c4052610c409050602060c0825160208401600060025af161104857600080fd5b60c0519050602082610cc001015260208101905080610cc052610cc09050602060c0825160208401600060025af161107f57600080fd5b60c0519050610b20526101a051610b20511461109a57600080fd5b60018054600182540110156110ae57600080fd5b6001815401815550600154610d4052610d6060006020818352015b60016001610d40511614156110fe57610b2051610d6051602081106110ed57600080fd5b600060c052602060c0200155611192565b6000610d60516020811061111157600080fd5b600060c052602060c0200154602082610d80010152602081019050610b2051602082610d8001015260208101905080610d8052610d809050602060c0825160208401600060025af161116257600080fd5b60c0519050610b2052610d40600261117957600080fd5b60028151048152505b81516001018083528114156110c9575b5050005b60006000fd5b61017f61131b0361017f60003961017f61131b036000f3"} \ No newline at end of file +{"abi": [{"name": "DepositEvent", "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": 91674}, {"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"}, {"type": "bytes32", "name": "deposit_data_root"}], "constant": false, "payable": true, "type": "function", "gas": 1334256}], "bytecode": "0x740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009857600080fd5b6101406000601f818352015b600061014051602081106100b757600080fd5b600260c052602060c020015460208261016001015260208101905061014051602081106100e357600080fd5b600260c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012157600080fd5b60c0519050606051600161014051018060405190131561014057600080fd5b809190121561014e57600080fd5b6020811061015b57600080fd5b600260c052602060c02001555b81516001018083528114156100a4575b50506112eb56600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052600015610277575b6101605261014052600061018052610140516101a0526101c060006008818352015b61018051600860008112156100da578060000360020a82046100e1565b8060020a82025b905090506101805260ff6101a051166101e052610180516101e0516101805101101561010c57600080fd5b6101e0516101805101610180526101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff86000811215610155578060000360020a820461015c565b8060020a82025b905090506101a0525b81516001018083528114156100bd575b50506018600860208206610200016020828401111561019357600080fd5b60208061022082610180600060046015f15050818152809050905090508051602001806102c0828460006004600a8704601201f16101d057600080fd5b50506102c05160206001820306601f82010390506103206102c0516008818352015b826103205111156102025761021e565b6000610320516102e001535b81516001018083528114156101f2575b50505060206102a05260406102c0510160206001820306601f8201039050610280525b6000610280511115156102535761026f565b602061028051036102a001516020610280510361028052610241565b610160515650005b63c5f2892f600051141561050857341561029057600080fd5b6000610140526101405161016052600154610180526101a060006020818352015b60016001610180511614156103325760006101a051602081106102d357600080fd5b600060c052602060c02001546020826102400101526020810190506101605160208261024001015260208101905080610240526102409050602060c0825160208401600060025af161032457600080fd5b60c0519050610160526103a0565b6000610160516020826101c00101526020810190506101a0516020811061035857600080fd5b600260c052602060c02001546020826101c0010152602081019050806101c0526101c09050602060c0825160208401600060025af161039657600080fd5b60c0519050610160525b61018060026103ae57600080fd5b60028151048152505b81516001018083528114156102b1575b505060006101605160208261044001015260208101905061014051610160516101805163806732896102c0526001546102e0526102e0516006580161009b565b506103405260006103a0525b6103405160206001820306601f82010390506103a0511015156104355761044e565b6103a05161036001526103a0516020016103a052610413565b61018052610160526101405261034060088060208461044001018260208501600060046012f150508051820191505060006018602082066103c0016020828401111561049957600080fd5b6020806103e082610140600060046015f150508181528090509050905060188060208461044001018260208501600060046014f150508051820191505080610440526104409050602060c0825160208401600060025af16104f957600080fd5b60c051905060005260206000f3005b63621fd130600051141561061a57341561052157600080fd5b63806732896101405260015461016052610160516006580161009b565b506101c0526000610220525b6101c05160206001820306601f82010390506102205110151561056c57610585565b610220516101e00152610220516020016102205261054a565b6101c0805160200180610280828460006004600a8704601201f16105a857600080fd5b50506102805160206001820306601f82010390506102e0610280516008818352015b826102e05111156105da576105f6565b60006102e0516102a001535b81516001018083528114156105ca575b5050506020610260526040610280510160206001820306601f8201039050610260f3005b6322895118600051141561116657608060046101403760506004356004016101c037603060043560040135111561065057600080fd5b604060243560040161024037602060243560040135111561067057600080fd5b60806044356004016102a037606060443560040135111561069057600080fd5b63ffffffff600154106106a257600080fd5b633b9aca0061036052610360516106b857600080fd5b61036051340461034052633b9aca006103405110156106d657600080fd5b6101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a0516103c05163806732896103e0526103405161040052610400516006580161009b565b506104605260006104c0525b6104605160206001820306601f82010390506104c05110151561076a57610783565b6104c05161048001526104c0516020016104c052610748565b6103c0526103a05261038052610360526103405261032052610300526102e0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a052610460805160200180610380828460006004600a8704601201f16107ee57600080fd5b50506101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a0516103c0516103e05161040051610420516104405161046051610480516104a0516104c05163806732896104e05260015461050052610500516006580161009b565b506105605260006105c0525b6105605160206001820306601f82010390506105c0511015156108a3576108bc565b6105c05161058001526105c0516020016105c052610881565b6104c0526104a05261048052610460526104405261042052610400526103e0526103c0526103a05261038052610360526103405261032052610300526102e0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a0526105608051602001806105e0828460006004600a8704601201f161094757600080fd5b505060a061066052610660516106a0526101c0805160200180610660516106a001828460006004600a8704601201f161097f57600080fd5b5050610660516106a0015160206001820306601f8201039050610660516106a00161064081516040818352015b83610640511015156109bd576109da565b6000610640516020850101535b81516001018083528114156109ac575b505050506020610660516106a0015160206001820306601f820103905061066051010161066052610660516106c052610240805160200180610660516106a001828460006004600a8704601201f1610a3157600080fd5b5050610660516106a0015160206001820306601f8201039050610660516106a00161064081516020818352015b8361064051101515610a6f57610a8c565b6000610640516020850101535b8151600101808352811415610a5e575b505050506020610660516106a0015160206001820306601f820103905061066051010161066052610660516106e052610380805160200180610660516106a001828460006004600a8704601201f1610ae357600080fd5b5050610660516106a0015160206001820306601f8201039050610660516106a00161064081516020818352015b8361064051101515610b2157610b3e565b6000610640516020850101535b8151600101808352811415610b10575b505050506020610660516106a0015160206001820306601f82010390506106605101016106605261066051610700526102a0805160200180610660516106a001828460006004600a8704601201f1610b9557600080fd5b5050610660516106a0015160206001820306601f8201039050610660516106a00161064081516060818352015b8361064051101515610bd357610bf0565b6000610640516020850101535b8151600101808352811415610bc2575b505050506020610660516106a0015160206001820306601f82010390506106605101016106605261066051610720526105e0805160200180610660516106a001828460006004600a8704601201f1610c4757600080fd5b5050610660516106a0015160206001820306601f8201039050610660516106a00161064081516020818352015b8361064051101515610c8557610ca2565b6000610640516020850101535b8151600101808352811415610c74575b505050506020610660516106a0015160206001820306601f8201039050610660510101610660527f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5610660516106a0a160006107405260006101c060308060208461080001018260208501600060046016f150508051820191505060006010602082066107800160208284011115610d3957600080fd5b6020806107a082610740600060046015f150508181528090509050905060108060208461080001018260208501600060046013f150508051820191505080610800526108009050602060c0825160208401600060025af1610d9957600080fd5b60c051905061076052600060006040602082066108a0016102a0518284011115610dc257600080fd5b6060806108c0826020602088068803016102a00160006004601bf1505081815280905090509050602060c0825160208401600060025af1610e0257600080fd5b60c0519050602082610aa001015260208101905060006040602060208206610960016102a0518284011115610e3657600080fd5b606080610980826020602088068803016102a00160006004601bf1505081815280905090509050602080602084610a2001018260208501600060046015f150508051820191505061074051602082610a2001015260208101905080610a2052610a209050602060c0825160208401600060025af1610eb357600080fd5b60c0519050602082610aa001015260208101905080610aa052610aa09050602060c0825160208401600060025af1610eea57600080fd5b60c0519050610880526000600061076051602082610b40010152602081019050610240602080602084610b4001018260208501600060046015f150508051820191505080610b4052610b409050602060c0825160208401600060025af1610f5057600080fd5b60c0519050602082610cc00101526020810190506000610380600880602084610c4001018260208501600060046012f15050805182019150506000601860208206610bc00160208284011115610fa557600080fd5b602080610be082610740600060046015f1505081815280905090509050601880602084610c4001018260208501600060046014f150508051820191505061088051602082610c4001015260208101905080610c4052610c409050602060c0825160208401600060025af161101857600080fd5b60c0519050602082610cc001015260208101905080610cc052610cc09050602060c0825160208401600060025af161104f57600080fd5b60c0519050610b20526101a051610b20511461106a57600080fd5b600180546001825401101561107e57600080fd5b6001815401815550600154610d4052610d6060006020818352015b60016001610d40511614156110ce57610b2051610d6051602081106110bd57600080fd5b600060c052602060c0200155611162565b6000610d6051602081106110e157600080fd5b600060c052602060c0200154602082610d80010152602081019050610b2051602082610d8001015260208101905080610d8052610d809050602060c0825160208401600060025af161113257600080fd5b60c0519050610b2052610d40600261114957600080fd5b60028151048152505b8151600101808352811415611099575b5050005b60006000fd5b61017f6112eb0361017f60003961017f6112eb036000f3"} \ No newline at end of file From caa566fe68d45bb42de0969a73880f9dd3b8ee46 Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Fri, 16 Aug 2019 11:59:55 +0200 Subject: [PATCH 07/10] Edit 0_deposit-contract.md --- specs/core/0_deposit-contract.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/core/0_deposit-contract.md b/specs/core/0_deposit-contract.md index ade1006a0e..06962594ed 100644 --- a/specs/core/0_deposit-contract.md +++ b/specs/core/0_deposit-contract.md @@ -34,11 +34,11 @@ This document represents the specification for the beacon chain deposit contract ## Ethereum 1.0 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). +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. ### `deposit` function -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`](./0_beacon-chain.md#depositdata) object. +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], deposit_data_root: bytes32`. The first three arguments populate a [`DepositData`](./0_beacon-chain.md#depositdata) object, and `deposit_data_root` is the expected `DepositData` root as a protection against malformatted calldata. #### Deposit amount From 17740c3e3e67b4cffc93ae7cc293a0ae459f4b94 Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Sun, 1 Sep 2019 11:35:04 +0100 Subject: [PATCH 08/10] New Vyper version --- deposit_contract/contracts/validator_registration.json | 2 +- deposit_contract/contracts/validator_registration.v.py | 1 + deposit_contract/requirements-testing.txt | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/deposit_contract/contracts/validator_registration.json b/deposit_contract/contracts/validator_registration.json index d9a8892caf..0b44392a42 100644 --- a/deposit_contract/contracts/validator_registration.json +++ b/deposit_contract/contracts/validator_registration.json @@ -1 +1 @@ -{"abi": [{"name": "DepositEvent", "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": 91674}, {"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"}, {"type": "bytes32", "name": "deposit_data_root"}], "constant": false, "payable": true, "type": "function", "gas": 1334256}], "bytecode": "0x740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009857600080fd5b6101406000601f818352015b600061014051602081106100b757600080fd5b600260c052602060c020015460208261016001015260208101905061014051602081106100e357600080fd5b600260c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012157600080fd5b60c0519050606051600161014051018060405190131561014057600080fd5b809190121561014e57600080fd5b6020811061015b57600080fd5b600260c052602060c02001555b81516001018083528114156100a4575b50506112eb56600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052600015610277575b6101605261014052600061018052610140516101a0526101c060006008818352015b61018051600860008112156100da578060000360020a82046100e1565b8060020a82025b905090506101805260ff6101a051166101e052610180516101e0516101805101101561010c57600080fd5b6101e0516101805101610180526101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff86000811215610155578060000360020a820461015c565b8060020a82025b905090506101a0525b81516001018083528114156100bd575b50506018600860208206610200016020828401111561019357600080fd5b60208061022082610180600060046015f15050818152809050905090508051602001806102c0828460006004600a8704601201f16101d057600080fd5b50506102c05160206001820306601f82010390506103206102c0516008818352015b826103205111156102025761021e565b6000610320516102e001535b81516001018083528114156101f2575b50505060206102a05260406102c0510160206001820306601f8201039050610280525b6000610280511115156102535761026f565b602061028051036102a001516020610280510361028052610241565b610160515650005b63c5f2892f600051141561050857341561029057600080fd5b6000610140526101405161016052600154610180526101a060006020818352015b60016001610180511614156103325760006101a051602081106102d357600080fd5b600060c052602060c02001546020826102400101526020810190506101605160208261024001015260208101905080610240526102409050602060c0825160208401600060025af161032457600080fd5b60c0519050610160526103a0565b6000610160516020826101c00101526020810190506101a0516020811061035857600080fd5b600260c052602060c02001546020826101c0010152602081019050806101c0526101c09050602060c0825160208401600060025af161039657600080fd5b60c0519050610160525b61018060026103ae57600080fd5b60028151048152505b81516001018083528114156102b1575b505060006101605160208261044001015260208101905061014051610160516101805163806732896102c0526001546102e0526102e0516006580161009b565b506103405260006103a0525b6103405160206001820306601f82010390506103a0511015156104355761044e565b6103a05161036001526103a0516020016103a052610413565b61018052610160526101405261034060088060208461044001018260208501600060046012f150508051820191505060006018602082066103c0016020828401111561049957600080fd5b6020806103e082610140600060046015f150508181528090509050905060188060208461044001018260208501600060046014f150508051820191505080610440526104409050602060c0825160208401600060025af16104f957600080fd5b60c051905060005260206000f3005b63621fd130600051141561061a57341561052157600080fd5b63806732896101405260015461016052610160516006580161009b565b506101c0526000610220525b6101c05160206001820306601f82010390506102205110151561056c57610585565b610220516101e00152610220516020016102205261054a565b6101c0805160200180610280828460006004600a8704601201f16105a857600080fd5b50506102805160206001820306601f82010390506102e0610280516008818352015b826102e05111156105da576105f6565b60006102e0516102a001535b81516001018083528114156105ca575b5050506020610260526040610280510160206001820306601f8201039050610260f3005b6322895118600051141561116657608060046101403760506004356004016101c037603060043560040135111561065057600080fd5b604060243560040161024037602060243560040135111561067057600080fd5b60806044356004016102a037606060443560040135111561069057600080fd5b63ffffffff600154106106a257600080fd5b633b9aca0061036052610360516106b857600080fd5b61036051340461034052633b9aca006103405110156106d657600080fd5b6101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a0516103c05163806732896103e0526103405161040052610400516006580161009b565b506104605260006104c0525b6104605160206001820306601f82010390506104c05110151561076a57610783565b6104c05161048001526104c0516020016104c052610748565b6103c0526103a05261038052610360526103405261032052610300526102e0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a052610460805160200180610380828460006004600a8704601201f16107ee57600080fd5b50506101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a0516103c0516103e05161040051610420516104405161046051610480516104a0516104c05163806732896104e05260015461050052610500516006580161009b565b506105605260006105c0525b6105605160206001820306601f82010390506105c0511015156108a3576108bc565b6105c05161058001526105c0516020016105c052610881565b6104c0526104a05261048052610460526104405261042052610400526103e0526103c0526103a05261038052610360526103405261032052610300526102e0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a0526105608051602001806105e0828460006004600a8704601201f161094757600080fd5b505060a061066052610660516106a0526101c0805160200180610660516106a001828460006004600a8704601201f161097f57600080fd5b5050610660516106a0015160206001820306601f8201039050610660516106a00161064081516040818352015b83610640511015156109bd576109da565b6000610640516020850101535b81516001018083528114156109ac575b505050506020610660516106a0015160206001820306601f820103905061066051010161066052610660516106c052610240805160200180610660516106a001828460006004600a8704601201f1610a3157600080fd5b5050610660516106a0015160206001820306601f8201039050610660516106a00161064081516020818352015b8361064051101515610a6f57610a8c565b6000610640516020850101535b8151600101808352811415610a5e575b505050506020610660516106a0015160206001820306601f820103905061066051010161066052610660516106e052610380805160200180610660516106a001828460006004600a8704601201f1610ae357600080fd5b5050610660516106a0015160206001820306601f8201039050610660516106a00161064081516020818352015b8361064051101515610b2157610b3e565b6000610640516020850101535b8151600101808352811415610b10575b505050506020610660516106a0015160206001820306601f82010390506106605101016106605261066051610700526102a0805160200180610660516106a001828460006004600a8704601201f1610b9557600080fd5b5050610660516106a0015160206001820306601f8201039050610660516106a00161064081516060818352015b8361064051101515610bd357610bf0565b6000610640516020850101535b8151600101808352811415610bc2575b505050506020610660516106a0015160206001820306601f82010390506106605101016106605261066051610720526105e0805160200180610660516106a001828460006004600a8704601201f1610c4757600080fd5b5050610660516106a0015160206001820306601f8201039050610660516106a00161064081516020818352015b8361064051101515610c8557610ca2565b6000610640516020850101535b8151600101808352811415610c74575b505050506020610660516106a0015160206001820306601f8201039050610660510101610660527f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5610660516106a0a160006107405260006101c060308060208461080001018260208501600060046016f150508051820191505060006010602082066107800160208284011115610d3957600080fd5b6020806107a082610740600060046015f150508181528090509050905060108060208461080001018260208501600060046013f150508051820191505080610800526108009050602060c0825160208401600060025af1610d9957600080fd5b60c051905061076052600060006040602082066108a0016102a0518284011115610dc257600080fd5b6060806108c0826020602088068803016102a00160006004601bf1505081815280905090509050602060c0825160208401600060025af1610e0257600080fd5b60c0519050602082610aa001015260208101905060006040602060208206610960016102a0518284011115610e3657600080fd5b606080610980826020602088068803016102a00160006004601bf1505081815280905090509050602080602084610a2001018260208501600060046015f150508051820191505061074051602082610a2001015260208101905080610a2052610a209050602060c0825160208401600060025af1610eb357600080fd5b60c0519050602082610aa001015260208101905080610aa052610aa09050602060c0825160208401600060025af1610eea57600080fd5b60c0519050610880526000600061076051602082610b40010152602081019050610240602080602084610b4001018260208501600060046015f150508051820191505080610b4052610b409050602060c0825160208401600060025af1610f5057600080fd5b60c0519050602082610cc00101526020810190506000610380600880602084610c4001018260208501600060046012f15050805182019150506000601860208206610bc00160208284011115610fa557600080fd5b602080610be082610740600060046015f1505081815280905090509050601880602084610c4001018260208501600060046014f150508051820191505061088051602082610c4001015260208101905080610c4052610c409050602060c0825160208401600060025af161101857600080fd5b60c0519050602082610cc001015260208101905080610cc052610cc09050602060c0825160208401600060025af161104f57600080fd5b60c0519050610b20526101a051610b20511461106a57600080fd5b600180546001825401101561107e57600080fd5b6001815401815550600154610d4052610d6060006020818352015b60016001610d40511614156110ce57610b2051610d6051602081106110bd57600080fd5b600060c052602060c0200155611162565b6000610d6051602081106110e157600080fd5b600060c052602060c0200154602082610d80010152602081019050610b2051602082610d8001015260208101905080610d8052610d809050602060c0825160208401600060025af161113257600080fd5b60c0519050610b2052610d40600261114957600080fd5b60028151048152505b8151600101808352811415611099575b5050005b60006000fd5b61017f6112eb0361017f60003961017f6112eb036000f3"} \ No newline at end of file +{"abi": [{"name": "DepositEvent", "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": 95389}, {"name": "get_deposit_count", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 17683}, {"name": "deposit", "outputs": [], "inputs": [{"type": "bytes", "name": "pubkey"}, {"type": "bytes", "name": "withdrawal_credentials"}, {"type": "bytes", "name": "signature"}, {"type": "bytes32", "name": "deposit_data_root"}], "constant": false, "payable": true, "type": "function", "gas": 1754316}], "bytecode": "0x740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009857600080fd5b6101406000601f818352015b600061014051602081106100b757600080fd5b600260c052602060c020015460208261016001015260208101905061014051602081106100e357600080fd5b600260c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012157600080fd5b60c0519050606051600161014051018060405190131561014057600080fd5b809190121561014e57600080fd5b6020811061015b57600080fd5b600260c052602060c02001555b81516001018083528114156100a4575b50506111a656600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052600015610265575b6101605261014052600061018052610140516101a0526101c060006008818352015b61018051600860008112156100da578060000360020a82046100e1565b8060020a82025b905090506101805260ff6101a051166101e052610180516101e0516101805101101561010c57600080fd5b6101e0516101805101610180526101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff86000811215610155578060000360020a820461015c565b8060020a82025b905090506101a0525b81516001018083528114156100bd575b50506018600860208206610200016020828401111561019357600080fd5b60208061022082610180600060046015f15050818152809050905090508051602001806102c0828460006004600a8704601201f16101d057600080fd5b50506103206102c0516020818352015b60206103205111156101f15761020d565b6000610320516102e001535b81516001018083528114156101e0575b505060206102a05260406102c0510160206001820306601f8201039050610280525b6000610280511115156102415761025d565b602061028051036102a00151602061028051036102805261022f565b610160515650005b63c5f2892f60005114156104f757341561027e57600080fd5b6000610140526101405161016052600154610180526101a060006020818352015b60016001610180511614156103205760006101a051602081106102c157600080fd5b600060c052602060c02001546020826102400101526020810190506101605160208261024001015260208101905080610240526102409050602060c0825160208401600060025af161031257600080fd5b60c05190506101605261038e565b6000610160516020826101c00101526020810190506101a0516020811061034657600080fd5b600260c052602060c02001546020826101c0010152602081019050806101c0526101c09050602060c0825160208401600060025af161038457600080fd5b60c0519050610160525b610180600261039c57600080fd5b60028151048152505b815160010180835281141561029f575b505060006101605160208261046001015260208101905061014051610160516101805163806732896102e05260015461030052610300516006580161009b565b506103605260006103c0525b6103605160206001820306601f82010390506103c0511015156104235761043c565b6103c05161038001526103c0516020016103c052610401565b61018052610160526101405261036060088060208461046001018260208501600060046012f150508051820191505060006018602082066103e0016020828401111561048757600080fd5b60208061040082610140600060046015f150508181528090509050905060188060208461046001018260208501600060046014f150508051820191505080610460526104609050602060c0825160208401600060025af16104e757600080fd5b60c051905060005260206000f350005b63621fd13060005114156105f857341561051057600080fd5b63806732896101405260015461016052610160516006580161009b565b506101c0526000610220525b6101c05160206001820306601f82010390506102205110151561055b57610574565b610220516101e001526102205160200161022052610539565b6101c0805160200180610280828460006004600a8704601201f161059757600080fd5b50506102e0610280516020818352015b60206102e05111156105b8576105d4565b60006102e0516102a001535b81516001018083528114156105a7575b50506020610260526040610280510160206001820306601f8201039050610260f350005b6322895118600051141561102157605060043560040161014037603060043560040135111561062657600080fd5b60406024356004016101c037602060243560040135111561064657600080fd5b608060443560040161022037606060443560040135111561066657600080fd5b63ffffffff6001541061067857600080fd5b633b9aca006102e0526102e05161068e57600080fd5b6102e05134046102c052633b9aca006102c05110156106ac57600080fd5b610140610360525b610360515160206103605101610360526103606103605110156106d6576106b4565b6380673289610380526102c0516103a0526103a0516006580161009b565b50610400526000610460525b6104005160206001820306601f8201039050610460511015156107225761073b565b6104605161042001526104605160200161046052610700565b610340610360525b610360515260206103605103610360526101406103605110151561076657610743565b610400805160200180610300828460006004600a8704601201f161078957600080fd5b5050610140610480525b610480515160206104805101610480526104806104805110156107b557610793565b63806732896104a0526001546104c0526104c0516006580161009b565b50610520526000610580525b6105205160206001820306601f82010390506105805110151561080057610819565b61058051610540015261058051602001610580526107de565b610460610480525b610480515260206104805103610480526101406104805110151561084457610821565b6105208051602001806105a0828460006004600a8704601201f161086757600080fd5b505060a06106205261062051610660526101408051602001806106205161066001828460006004600a8704601201f161089f57600080fd5b5050610600610620516106600151610240818352015b6102406106005111156108c7576108e8565b600061060051610620516106800101535b81516001018083528114156108b5575b5050602061062051610660015160206001820306601f82010390506106205101016106205261062051610680526101c08051602001806106205161066001828460006004600a8704601201f161093d57600080fd5b5050610600610620516106600151610240818352015b61024061060051111561096557610986565b600061060051610620516106800101535b8151600101808352811415610953575b5050602061062051610660015160206001820306601f820103905061062051010161062052610620516106a0526103008051602001806106205161066001828460006004600a8704601201f16109db57600080fd5b5050610600610620516106600151610240818352015b610240610600511115610a0357610a24565b600061060051610620516106800101535b81516001018083528114156109f1575b5050602061062051610660015160206001820306601f820103905061062051010161062052610620516106c0526102208051602001806106205161066001828460006004600a8704601201f1610a7957600080fd5b5050610600610620516106600151610240818352015b610240610600511115610aa157610ac2565b600061060051610620516106800101535b8151600101808352811415610a8f575b5050602061062051610660015160206001820306601f820103905061062051010161062052610620516106e0526105a08051602001806106205161066001828460006004600a8704601201f1610b1757600080fd5b5050610600610620516106600151610240818352015b610240610600511115610b3f57610b60565b600061060051610620516106800101535b8151600101808352811415610b2d575b5050602061062051610660015160206001820306601f8201039050610620510101610620527f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c561062051610660a160006107005260006101406030806020846107c001018260208501600060046016f150508051820191505060006010602082066107400160208284011115610bf557600080fd5b60208061076082610700600060046015f15050818152809050905090506010806020846107c001018260208501600060046013f1505080518201915050806107c0526107c09050602060c0825160208401600060025af1610c5557600080fd5b60c0519050610720526000600060406020820661086001610220518284011115610c7e57600080fd5b606080610880826020602088068803016102200160006004601bf1505081815280905090509050602060c0825160208401600060025af1610cbe57600080fd5b60c0519050602082610a600101526020810190506000604060206020820661092001610220518284011115610cf257600080fd5b606080610940826020602088068803016102200160006004601bf15050818152809050905090506020806020846109e001018260208501600060046015f1505080518201915050610700516020826109e0010152602081019050806109e0526109e09050602060c0825160208401600060025af1610d6f57600080fd5b60c0519050602082610a6001015260208101905080610a6052610a609050602060c0825160208401600060025af1610da657600080fd5b60c0519050610840526000600061072051602082610b000101526020810190506101c0602080602084610b0001018260208501600060046015f150508051820191505080610b0052610b009050602060c0825160208401600060025af1610e0c57600080fd5b60c0519050602082610c800101526020810190506000610300600880602084610c0001018260208501600060046012f15050805182019150506000601860208206610b800160208284011115610e6157600080fd5b602080610ba082610700600060046015f1505081815280905090509050601880602084610c0001018260208501600060046014f150508051820191505061084051602082610c0001015260208101905080610c0052610c009050602060c0825160208401600060025af1610ed457600080fd5b60c0519050602082610c8001015260208101905080610c8052610c809050602060c0825160208401600060025af1610f0b57600080fd5b60c0519050610ae052606435610ae05114610f2557600080fd5b6001805460018254011015610f3957600080fd5b6001815401815550600154610d0052610d2060006020818352015b60016001610d0051161415610f8957610ae051610d205160208110610f7857600080fd5b600060c052602060c020015561101d565b6000610d205160208110610f9c57600080fd5b600060c052602060c0200154602082610d40010152602081019050610ae051602082610d4001015260208101905080610d4052610d409050602060c0825160208401600060025af1610fed57600080fd5b60c0519050610ae052610d00600261100457600080fd5b60028151048152505b8151600101808352811415610f54575b5050005b60006000fd5b61017f6111a60361017f60003961017f6111a6036000f3"} \ 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 1c1eb5fc7e..a4c0aed262 100644 --- a/deposit_contract/contracts/validator_registration.v.py +++ b/deposit_contract/contracts/validator_registration.v.py @@ -1,3 +1,4 @@ +# Vyper target 0.1.0b12 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 diff --git a/deposit_contract/requirements-testing.txt b/deposit_contract/requirements-testing.txt index 280d7e5279..0b3d9d22c5 100644 --- a/deposit_contract/requirements-testing.txt +++ b/deposit_contract/requirements-testing.txt @@ -1,5 +1,5 @@ eth-tester[py-evm]==0.1.0b39 -vyper==0.1.0b10 +vyper==0.1.0b12 web3==5.0.0b2 pytest==3.6.1 ../test_libs/pyspec From 9cfde1215b8f0ea131ccc3f584e92272cc162c7a Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Tue, 3 Sep 2019 12:34:47 +0100 Subject: [PATCH 09/10] Add get_deposit_count().call() per Danny --- deposit_contract/tests/contracts/test_deposit.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/deposit_contract/tests/contracts/test_deposit.py b/deposit_contract/tests/contracts/test_deposit.py index d7c84b0169..01586d0708 100644 --- a/deposit_contract/tests/contracts/test_deposit.py +++ b/deposit_contract/tests/contracts/test_deposit.py @@ -194,5 +194,8 @@ def test_deposit_tree(registration_contract, w3, assert_tx_failed): assert log["index"] == i.to_bytes(8, 'little') + # Check deposit count and root + count = len(deposit_data_list).to_bytes(8, 'little') + assert count == registration_contract.functions.get_deposit_count().call() root = hash_tree_root(List[DepositData, 2**32](*deposit_data_list)) assert root == registration_contract.functions.get_deposit_root().call() From 62629c9360eed7e51927d116f3d8165e2fbe4c9d Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Tue, 3 Sep 2019 17:45:34 +0100 Subject: [PATCH 10/10] Readd length checks to facilitate formal verification --- deposit_contract/contracts/validator_registration.json | 2 +- deposit_contract/contracts/validator_registration.v.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/deposit_contract/contracts/validator_registration.json b/deposit_contract/contracts/validator_registration.json index 0b44392a42..fbf20e74c9 100644 --- a/deposit_contract/contracts/validator_registration.json +++ b/deposit_contract/contracts/validator_registration.json @@ -1 +1 @@ -{"abi": [{"name": "DepositEvent", "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": 95389}, {"name": "get_deposit_count", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 17683}, {"name": "deposit", "outputs": [], "inputs": [{"type": "bytes", "name": "pubkey"}, {"type": "bytes", "name": "withdrawal_credentials"}, {"type": "bytes", "name": "signature"}, {"type": "bytes32", "name": "deposit_data_root"}], "constant": false, "payable": true, "type": "function", "gas": 1754316}], "bytecode": "0x740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009857600080fd5b6101406000601f818352015b600061014051602081106100b757600080fd5b600260c052602060c020015460208261016001015260208101905061014051602081106100e357600080fd5b600260c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012157600080fd5b60c0519050606051600161014051018060405190131561014057600080fd5b809190121561014e57600080fd5b6020811061015b57600080fd5b600260c052602060c02001555b81516001018083528114156100a4575b50506111a656600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052600015610265575b6101605261014052600061018052610140516101a0526101c060006008818352015b61018051600860008112156100da578060000360020a82046100e1565b8060020a82025b905090506101805260ff6101a051166101e052610180516101e0516101805101101561010c57600080fd5b6101e0516101805101610180526101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff86000811215610155578060000360020a820461015c565b8060020a82025b905090506101a0525b81516001018083528114156100bd575b50506018600860208206610200016020828401111561019357600080fd5b60208061022082610180600060046015f15050818152809050905090508051602001806102c0828460006004600a8704601201f16101d057600080fd5b50506103206102c0516020818352015b60206103205111156101f15761020d565b6000610320516102e001535b81516001018083528114156101e0575b505060206102a05260406102c0510160206001820306601f8201039050610280525b6000610280511115156102415761025d565b602061028051036102a00151602061028051036102805261022f565b610160515650005b63c5f2892f60005114156104f757341561027e57600080fd5b6000610140526101405161016052600154610180526101a060006020818352015b60016001610180511614156103205760006101a051602081106102c157600080fd5b600060c052602060c02001546020826102400101526020810190506101605160208261024001015260208101905080610240526102409050602060c0825160208401600060025af161031257600080fd5b60c05190506101605261038e565b6000610160516020826101c00101526020810190506101a0516020811061034657600080fd5b600260c052602060c02001546020826101c0010152602081019050806101c0526101c09050602060c0825160208401600060025af161038457600080fd5b60c0519050610160525b610180600261039c57600080fd5b60028151048152505b815160010180835281141561029f575b505060006101605160208261046001015260208101905061014051610160516101805163806732896102e05260015461030052610300516006580161009b565b506103605260006103c0525b6103605160206001820306601f82010390506103c0511015156104235761043c565b6103c05161038001526103c0516020016103c052610401565b61018052610160526101405261036060088060208461046001018260208501600060046012f150508051820191505060006018602082066103e0016020828401111561048757600080fd5b60208061040082610140600060046015f150508181528090509050905060188060208461046001018260208501600060046014f150508051820191505080610460526104609050602060c0825160208401600060025af16104e757600080fd5b60c051905060005260206000f350005b63621fd13060005114156105f857341561051057600080fd5b63806732896101405260015461016052610160516006580161009b565b506101c0526000610220525b6101c05160206001820306601f82010390506102205110151561055b57610574565b610220516101e001526102205160200161022052610539565b6101c0805160200180610280828460006004600a8704601201f161059757600080fd5b50506102e0610280516020818352015b60206102e05111156105b8576105d4565b60006102e0516102a001535b81516001018083528114156105a7575b50506020610260526040610280510160206001820306601f8201039050610260f350005b6322895118600051141561102157605060043560040161014037603060043560040135111561062657600080fd5b60406024356004016101c037602060243560040135111561064657600080fd5b608060443560040161022037606060443560040135111561066657600080fd5b63ffffffff6001541061067857600080fd5b633b9aca006102e0526102e05161068e57600080fd5b6102e05134046102c052633b9aca006102c05110156106ac57600080fd5b610140610360525b610360515160206103605101610360526103606103605110156106d6576106b4565b6380673289610380526102c0516103a0526103a0516006580161009b565b50610400526000610460525b6104005160206001820306601f8201039050610460511015156107225761073b565b6104605161042001526104605160200161046052610700565b610340610360525b610360515260206103605103610360526101406103605110151561076657610743565b610400805160200180610300828460006004600a8704601201f161078957600080fd5b5050610140610480525b610480515160206104805101610480526104806104805110156107b557610793565b63806732896104a0526001546104c0526104c0516006580161009b565b50610520526000610580525b6105205160206001820306601f82010390506105805110151561080057610819565b61058051610540015261058051602001610580526107de565b610460610480525b610480515260206104805103610480526101406104805110151561084457610821565b6105208051602001806105a0828460006004600a8704601201f161086757600080fd5b505060a06106205261062051610660526101408051602001806106205161066001828460006004600a8704601201f161089f57600080fd5b5050610600610620516106600151610240818352015b6102406106005111156108c7576108e8565b600061060051610620516106800101535b81516001018083528114156108b5575b5050602061062051610660015160206001820306601f82010390506106205101016106205261062051610680526101c08051602001806106205161066001828460006004600a8704601201f161093d57600080fd5b5050610600610620516106600151610240818352015b61024061060051111561096557610986565b600061060051610620516106800101535b8151600101808352811415610953575b5050602061062051610660015160206001820306601f820103905061062051010161062052610620516106a0526103008051602001806106205161066001828460006004600a8704601201f16109db57600080fd5b5050610600610620516106600151610240818352015b610240610600511115610a0357610a24565b600061060051610620516106800101535b81516001018083528114156109f1575b5050602061062051610660015160206001820306601f820103905061062051010161062052610620516106c0526102208051602001806106205161066001828460006004600a8704601201f1610a7957600080fd5b5050610600610620516106600151610240818352015b610240610600511115610aa157610ac2565b600061060051610620516106800101535b8151600101808352811415610a8f575b5050602061062051610660015160206001820306601f820103905061062051010161062052610620516106e0526105a08051602001806106205161066001828460006004600a8704601201f1610b1757600080fd5b5050610600610620516106600151610240818352015b610240610600511115610b3f57610b60565b600061060051610620516106800101535b8151600101808352811415610b2d575b5050602061062051610660015160206001820306601f8201039050610620510101610620527f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c561062051610660a160006107005260006101406030806020846107c001018260208501600060046016f150508051820191505060006010602082066107400160208284011115610bf557600080fd5b60208061076082610700600060046015f15050818152809050905090506010806020846107c001018260208501600060046013f1505080518201915050806107c0526107c09050602060c0825160208401600060025af1610c5557600080fd5b60c0519050610720526000600060406020820661086001610220518284011115610c7e57600080fd5b606080610880826020602088068803016102200160006004601bf1505081815280905090509050602060c0825160208401600060025af1610cbe57600080fd5b60c0519050602082610a600101526020810190506000604060206020820661092001610220518284011115610cf257600080fd5b606080610940826020602088068803016102200160006004601bf15050818152809050905090506020806020846109e001018260208501600060046015f1505080518201915050610700516020826109e0010152602081019050806109e0526109e09050602060c0825160208401600060025af1610d6f57600080fd5b60c0519050602082610a6001015260208101905080610a6052610a609050602060c0825160208401600060025af1610da657600080fd5b60c0519050610840526000600061072051602082610b000101526020810190506101c0602080602084610b0001018260208501600060046015f150508051820191505080610b0052610b009050602060c0825160208401600060025af1610e0c57600080fd5b60c0519050602082610c800101526020810190506000610300600880602084610c0001018260208501600060046012f15050805182019150506000601860208206610b800160208284011115610e6157600080fd5b602080610ba082610700600060046015f1505081815280905090509050601880602084610c0001018260208501600060046014f150508051820191505061084051602082610c0001015260208101905080610c0052610c009050602060c0825160208401600060025af1610ed457600080fd5b60c0519050602082610c8001015260208101905080610c8052610c809050602060c0825160208401600060025af1610f0b57600080fd5b60c0519050610ae052606435610ae05114610f2557600080fd5b6001805460018254011015610f3957600080fd5b6001815401815550600154610d0052610d2060006020818352015b60016001610d0051161415610f8957610ae051610d205160208110610f7857600080fd5b600060c052602060c020015561101d565b6000610d205160208110610f9c57600080fd5b600060c052602060c0200154602082610d40010152602081019050610ae051602082610d4001015260208101905080610d4052610d409050602060c0825160208401600060025af1610fed57600080fd5b60c0519050610ae052610d00600261100457600080fd5b60028151048152505b8151600101808352811415610f54575b5050005b60006000fd5b61017f6111a60361017f60003961017f6111a6036000f3"} \ No newline at end of file +{"abi": [{"name": "DepositEvent", "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": 95389}, {"name": "get_deposit_count", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 17683}, {"name": "deposit", "outputs": [], "inputs": [{"type": "bytes", "name": "pubkey"}, {"type": "bytes", "name": "withdrawal_credentials"}, {"type": "bytes", "name": "signature"}, {"type": "bytes32", "name": "deposit_data_root"}], "constant": false, "payable": true, "type": "function", "gas": 1754607}], "bytecode": "0x740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009857600080fd5b6101406000601f818352015b600061014051602081106100b757600080fd5b600260c052602060c020015460208261016001015260208101905061014051602081106100e357600080fd5b600260c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012157600080fd5b60c0519050606051600161014051018060405190131561014057600080fd5b809190121561014e57600080fd5b6020811061015b57600080fd5b600260c052602060c02001555b81516001018083528114156100a4575b50506111d656600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052600015610265575b6101605261014052600061018052610140516101a0526101c060006008818352015b61018051600860008112156100da578060000360020a82046100e1565b8060020a82025b905090506101805260ff6101a051166101e052610180516101e0516101805101101561010c57600080fd5b6101e0516101805101610180526101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff86000811215610155578060000360020a820461015c565b8060020a82025b905090506101a0525b81516001018083528114156100bd575b50506018600860208206610200016020828401111561019357600080fd5b60208061022082610180600060046015f15050818152809050905090508051602001806102c0828460006004600a8704601201f16101d057600080fd5b50506103206102c0516020818352015b60206103205111156101f15761020d565b6000610320516102e001535b81516001018083528114156101e0575b505060206102a05260406102c0510160206001820306601f8201039050610280525b6000610280511115156102415761025d565b602061028051036102a00151602061028051036102805261022f565b610160515650005b63c5f2892f60005114156104f757341561027e57600080fd5b6000610140526101405161016052600154610180526101a060006020818352015b60016001610180511614156103205760006101a051602081106102c157600080fd5b600060c052602060c02001546020826102400101526020810190506101605160208261024001015260208101905080610240526102409050602060c0825160208401600060025af161031257600080fd5b60c05190506101605261038e565b6000610160516020826101c00101526020810190506101a0516020811061034657600080fd5b600260c052602060c02001546020826101c0010152602081019050806101c0526101c09050602060c0825160208401600060025af161038457600080fd5b60c0519050610160525b610180600261039c57600080fd5b60028151048152505b815160010180835281141561029f575b505060006101605160208261046001015260208101905061014051610160516101805163806732896102e05260015461030052610300516006580161009b565b506103605260006103c0525b6103605160206001820306601f82010390506103c0511015156104235761043c565b6103c05161038001526103c0516020016103c052610401565b61018052610160526101405261036060088060208461046001018260208501600060046012f150508051820191505060006018602082066103e0016020828401111561048757600080fd5b60208061040082610140600060046015f150508181528090509050905060188060208461046001018260208501600060046014f150508051820191505080610460526104609050602060c0825160208401600060025af16104e757600080fd5b60c051905060005260206000f350005b63621fd13060005114156105f857341561051057600080fd5b63806732896101405260015461016052610160516006580161009b565b506101c0526000610220525b6101c05160206001820306601f82010390506102205110151561055b57610574565b610220516101e001526102205160200161022052610539565b6101c0805160200180610280828460006004600a8704601201f161059757600080fd5b50506102e0610280516020818352015b60206102e05111156105b8576105d4565b60006102e0516102a001535b81516001018083528114156105a7575b50506020610260526040610280510160206001820306601f8201039050610260f350005b6322895118600051141561105157605060043560040161014037603060043560040135111561062657600080fd5b60406024356004016101c037602060243560040135111561064657600080fd5b608060443560040161022037606060443560040135111561066657600080fd5b63ffffffff6001541061067857600080fd5b633b9aca006102e0526102e05161068e57600080fd5b6102e05134046102c052633b9aca006102c05110156106ac57600080fd5b603061014051146106bc57600080fd5b60206101c051146106cc57600080fd5b606061022051146106dc57600080fd5b610140610360525b61036051516020610360510161036052610360610360511015610706576106e4565b6380673289610380526102c0516103a0526103a0516006580161009b565b50610400526000610460525b6104005160206001820306601f8201039050610460511015156107525761076b565b6104605161042001526104605160200161046052610730565b610340610360525b610360515260206103605103610360526101406103605110151561079657610773565b610400805160200180610300828460006004600a8704601201f16107b957600080fd5b5050610140610480525b610480515160206104805101610480526104806104805110156107e5576107c3565b63806732896104a0526001546104c0526104c0516006580161009b565b50610520526000610580525b6105205160206001820306601f82010390506105805110151561083057610849565b610580516105400152610580516020016105805261080e565b610460610480525b610480515260206104805103610480526101406104805110151561087457610851565b6105208051602001806105a0828460006004600a8704601201f161089757600080fd5b505060a06106205261062051610660526101408051602001806106205161066001828460006004600a8704601201f16108cf57600080fd5b5050610600610620516106600151610240818352015b6102406106005111156108f757610918565b600061060051610620516106800101535b81516001018083528114156108e5575b5050602061062051610660015160206001820306601f82010390506106205101016106205261062051610680526101c08051602001806106205161066001828460006004600a8704601201f161096d57600080fd5b5050610600610620516106600151610240818352015b610240610600511115610995576109b6565b600061060051610620516106800101535b8151600101808352811415610983575b5050602061062051610660015160206001820306601f820103905061062051010161062052610620516106a0526103008051602001806106205161066001828460006004600a8704601201f1610a0b57600080fd5b5050610600610620516106600151610240818352015b610240610600511115610a3357610a54565b600061060051610620516106800101535b8151600101808352811415610a21575b5050602061062051610660015160206001820306601f820103905061062051010161062052610620516106c0526102208051602001806106205161066001828460006004600a8704601201f1610aa957600080fd5b5050610600610620516106600151610240818352015b610240610600511115610ad157610af2565b600061060051610620516106800101535b8151600101808352811415610abf575b5050602061062051610660015160206001820306601f820103905061062051010161062052610620516106e0526105a08051602001806106205161066001828460006004600a8704601201f1610b4757600080fd5b5050610600610620516106600151610240818352015b610240610600511115610b6f57610b90565b600061060051610620516106800101535b8151600101808352811415610b5d575b5050602061062051610660015160206001820306601f8201039050610620510101610620527f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c561062051610660a160006107005260006101406030806020846107c001018260208501600060046016f150508051820191505060006010602082066107400160208284011115610c2557600080fd5b60208061076082610700600060046015f15050818152809050905090506010806020846107c001018260208501600060046013f1505080518201915050806107c0526107c09050602060c0825160208401600060025af1610c8557600080fd5b60c0519050610720526000600060406020820661086001610220518284011115610cae57600080fd5b606080610880826020602088068803016102200160006004601bf1505081815280905090509050602060c0825160208401600060025af1610cee57600080fd5b60c0519050602082610a600101526020810190506000604060206020820661092001610220518284011115610d2257600080fd5b606080610940826020602088068803016102200160006004601bf15050818152809050905090506020806020846109e001018260208501600060046015f1505080518201915050610700516020826109e0010152602081019050806109e0526109e09050602060c0825160208401600060025af1610d9f57600080fd5b60c0519050602082610a6001015260208101905080610a6052610a609050602060c0825160208401600060025af1610dd657600080fd5b60c0519050610840526000600061072051602082610b000101526020810190506101c0602080602084610b0001018260208501600060046015f150508051820191505080610b0052610b009050602060c0825160208401600060025af1610e3c57600080fd5b60c0519050602082610c800101526020810190506000610300600880602084610c0001018260208501600060046012f15050805182019150506000601860208206610b800160208284011115610e9157600080fd5b602080610ba082610700600060046015f1505081815280905090509050601880602084610c0001018260208501600060046014f150508051820191505061084051602082610c0001015260208101905080610c0052610c009050602060c0825160208401600060025af1610f0457600080fd5b60c0519050602082610c8001015260208101905080610c8052610c809050602060c0825160208401600060025af1610f3b57600080fd5b60c0519050610ae052606435610ae05114610f5557600080fd5b6001805460018254011015610f6957600080fd5b6001815401815550600154610d0052610d2060006020818352015b60016001610d0051161415610fb957610ae051610d205160208110610fa857600080fd5b600060c052602060c020015561104d565b6000610d205160208110610fcc57600080fd5b600060c052602060c0200154602082610d40010152602081019050610ae051602082610d4001015260208101905080610d4052610d409050602060c0825160208401600060025af161101d57600080fd5b60c0519050610ae052610d00600261103457600080fd5b60028151048152505b8151600101808352811415610f84575b5050005b60006000fd5b61017f6111d60361017f60003961017f6111d6036000f3"} \ 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 a4c0aed262..6ee27db7ac 100644 --- a/deposit_contract/contracts/validator_registration.v.py +++ b/deposit_contract/contracts/validator_registration.v.py @@ -75,6 +75,11 @@ def deposit(pubkey: bytes[PUBKEY_LENGTH], deposit_amount: uint256 = msg.value / as_wei_value(1, "gwei") assert deposit_amount >= MIN_DEPOSIT_AMOUNT + # Length checks to facilitate formal verification (see https://github.com/ethereum/eth2.0-specs/pull/1362/files#r320361859) + assert len(pubkey) == PUBKEY_LENGTH + assert len(withdrawal_credentials) == WITHDRAWAL_CREDENTIALS_LENGTH + assert len(signature) == SIGNATURE_LENGTH + # Emit `DepositEvent` log amount: bytes[8] = self.to_little_endian_64(deposit_amount) log.DepositEvent(pubkey, withdrawal_credentials, amount, signature, self.to_little_endian_64(self.deposit_count))