diff --git a/deposit_contract/contracts/validator_registration.json b/deposit_contract/contracts/validator_registration.json index 676bf470ab..1779423d2a 100644 --- a/deposit_contract/contracts/validator_registration.json +++ b/deposit_contract/contracts/validator_registration.json @@ -1 +1 @@ -{"abi": [{"name": "Deposit", "inputs": [{"type": "bytes", "name": "pubkey", "indexed": false}, {"type": "bytes", "name": "withdrawal_credentials", "indexed": false}, {"type": "bytes", "name": "amount", "indexed": false}, {"type": "bytes", "name": "signature", "indexed": false}], "anonymous": false, "type": "event"}, {"outputs": [], "inputs": [], "constant": false, "payable": false, "type": "constructor"}, {"name": "to_little_endian_64", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [{"type": "uint256", "name": "value"}], "constant": true, "payable": false, "type": "function", "gas": 6973}, {"name": "get_deposit_root", "outputs": [{"type": "bytes32", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 79221}, {"name": "get_deposit_count", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 10922}, {"name": "deposit", "outputs": [], "inputs": [{"type": "bytes", "name": "pubkey"}, {"type": "bytes", "name": "withdrawal_credentials"}, {"type": "bytes", "name": "signature"}], "constant": false, "payable": true, "type": "function", "gas": 1318334}], "bytecode": "0x600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009e57600080fd5b6101406000601f818352015b600061014051602081106100bd57600080fd5b600260c052602060c020015460208261016001015260208101905061014051602081106100e957600080fd5b600260c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012757600080fd5b60c0519050606051600161014051018060405190131561014657600080fd5b809190121561015457600080fd5b6020811061016157600080fd5b600260c052602060c02001555b81516001018083528114156100aa575b5050610e9956600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a0526380673289600051141561025357602060046101403734156100b457600080fd5b60006101605261014051610180526101a060006008818352015b61016051600860008112156100eb578060000360020a82046100f2565b8060020a82025b905090506101605260ff61018051166101c052610160516101c0516101605101101561011d57600080fd5b6101c051610160510161016052610180517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff86000811215610166578060000360020a820461016d565b8060020a82025b90509050610180525b81516001018083528114156100ce575b505060186008602082066101e001602082840111156101a457600080fd5b60208061020082610160600060046015f15050818152809050905090508051602001806102a0828460006004600a8704601201f16101e157600080fd5b50506102a05160206001820306601f82010390506103006102a0516008818352015b826103005111156102135761022f565b6000610300516102c001535b8151600101808352811415610203575b50505060206102805260406102a0510160206001820306601f8201039050610280f3005b63c5f2892f60005114156103ab57341561026c57600080fd5b6000610140526001546101605261018060006020818352015b600160016101605116141561030657600061018051602081106102a757600080fd5b600060c052602060c02001546020826102200101526020810190506101405160208261022001015260208101905080610220526102209050602060c0825160208401600060025af16102f857600080fd5b60c051905061014052610374565b6000610140516020826101a0010152602081019050610180516020811061032c57600080fd5b600260c052602060c02001546020826101a0010152602081019050806101a0526101a09050602060c0825160208401600060025af161036a57600080fd5b60c0519050610140525b610160600261038257600080fd5b60028151048152505b8151600101808352811415610285575b50506101405160005260206000f3005b63621fd13060005114156104815734156103c457600080fd5b60606101c060246380673289610140526001546101605261015c6000305af16103ec57600080fd5b6101e0805160200180610260828460006004600a8704601201f161040f57600080fd5b50506102605160206001820306601f82010390506102c0610260516008818352015b826102c05111156104415761045d565b60006102c05161028001535b8151600101808352811415610431575b5050506020610240526040610260510160206001820306601f8201039050610240f3005b63c47e300d6000511415610d0e57606060046101403760506004356004016101a03760306004356004013511156104b757600080fd5b60406024356004016102203760206024356004013511156104d757600080fd5b60806044356004016102803760606044356004013511156104f757600080fd5b63ffffffff6001541061050957600080fd5b633b9aca00610340526103405161051f57600080fd5b61034051340461032052633b9aca0061032051101561053d57600080fd5b60306101a0511461054d57600080fd5b6020610220511461055d57600080fd5b6060610280511461056d57600080fd5b6060610440602463806732896103c052610320516103e0526103dc6000305af161059657600080fd5b610460805160200180610360828460006004600a8704601201f16105b957600080fd5b505060006101a060308060208461056001018260208501600060046016f150508051820191505060006010602082066104e001602082840111156105fc57600080fd5b602080610500826104a0600060046015f150508181528090509050905060108060208461056001018260208501600060046013f150508051820191505080610560526105609050602060c0825160208401600060025af161065c57600080fd5b60c05190506104c052600060006040602082066106000161028051828401111561068557600080fd5b606080610620826020602088068803016102800160006004601bf1505081815280905090509050602060c0825160208401600060025af16106c557600080fd5b60c0519050602082610800010152602081019050600060406020602082066106c0016102805182840111156106f957600080fd5b6060806106e0826020602088068803016102800160006004601bf150508181528090509050905060208060208461078001018260208501600060046015f15050805182019150506104a05160208261078001015260208101905080610780526107809050602060c0825160208401600060025af161077657600080fd5b60c051905060208261080001015260208101905080610800526108009050602060c0825160208401600060025af16107ad57600080fd5b60c05190506105e052600060006104c0516020826108a00101526020810190506102206020806020846108a001018260208501600060046015f1505080518201915050806108a0526108a09050602060c0825160208401600060025af161081357600080fd5b60c0519050602082610a2001015260208101905060006103606008806020846109a001018260208501600060046012f15050805182019150506000601860208206610920016020828401111561086857600080fd5b602080610940826104a0600060046015f15050818152809050905090506018806020846109a001018260208501600060046014f15050805182019150506105e0516020826109a0010152602081019050806109a0526109a09050602060c0825160208401600060025af16108db57600080fd5b60c0519050602082610a2001015260208101905080610a2052610a209050602060c0825160208401600060025af161091257600080fd5b60c051905061088052600180546001825401101561092f57600080fd5b6001815401815550600154610aa052610ac060006020818352015b60016001610aa05116141561097f5761088051610ac0516020811061096e57600080fd5b600060c052602060c0200155610a13565b6000610ac0516020811061099257600080fd5b600060c052602060c0200154602082610ae001015260208101905061088051602082610ae001015260208101905080610ae052610ae09050602060c0825160208401600060025af16109e357600080fd5b60c051905061088052610aa060026109fa57600080fd5b60028151048152505b815160010180835281141561094a575b50506080610b8052610b8051610bc0526101a0805160200180610b8051610bc001828460006004600a8704601201f1610a4b57600080fd5b5050610b8051610bc0015160206001820306601f8201039050610b8051610bc001610b6081516040818352015b83610b6051101515610a8957610aa6565b6000610b60516020850101535b8151600101808352811415610a78575b505050506020610b8051610bc0015160206001820306601f8201039050610b80510101610b8052610b8051610be052610220805160200180610b8051610bc001828460006004600a8704601201f1610afd57600080fd5b5050610b8051610bc0015160206001820306601f8201039050610b8051610bc001610b6081516020818352015b83610b6051101515610b3b57610b58565b6000610b60516020850101535b8151600101808352811415610b2a575b505050506020610b8051610bc0015160206001820306601f8201039050610b80510101610b8052610b8051610c0052610360805160200180610b8051610bc001828460006004600a8704601201f1610baf57600080fd5b5050610b8051610bc0015160206001820306601f8201039050610b8051610bc001610b6081516020818352015b83610b6051101515610bed57610c0a565b6000610b60516020850101535b8151600101808352811415610bdc575b505050506020610b8051610bc0015160206001820306601f8201039050610b80510101610b8052610b8051610c2052610280805160200180610b8051610bc001828460006004600a8704601201f1610c6157600080fd5b5050610b8051610bc0015160206001820306601f8201039050610b8051610bc001610b6081516060818352015b83610b6051101515610c9f57610cbc565b6000610b60516020850101535b8151600101808352811415610c8e575b505050506020610b8051610bc0015160206001820306601f8201039050610b80510101610b80527f9d0a206c338cfcaf9198c04fe61b39a988e26b623ef97cb2f72bafcfbf8bb93e610b8051610bc0a1005b60006000fd5b610185610e9903610185600039610185610e99036000f3"} \ No newline at end of file +{"abi": [{"name": "Deposit", "inputs": [{"type": "bytes", "name": "pubkey", "indexed": false}, {"type": "bytes", "name": "withdrawal_credentials", "indexed": false}, {"type": "bytes", "name": "amount", "indexed": false}, {"type": "bytes", "name": "signature", "indexed": false}, {"type": "bytes", "name": "index", "indexed": false}], "anonymous": false, "type": "event"}, {"outputs": [], "inputs": [], "constant": false, "payable": false, "type": "constructor"}, {"name": "get_deposit_root", "outputs": [{"type": "bytes32", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 79221}, {"name": "get_deposit_count", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 10433}, {"name": "deposit", "outputs": [], "inputs": [{"type": "bytes", "name": "pubkey"}, {"type": "bytes", "name": "withdrawal_credentials"}, {"type": "bytes", "name": "signature"}], "constant": false, "payable": true, "type": "function", "gas": 1334984}], "bytecode": "0x600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009e57600080fd5b6101406000601f818352015b600061014051602081106100bd57600080fd5b600260c052602060c020015460208261016001015260208101905061014051602081106100e957600080fd5b600260c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012757600080fd5b60c0519050606051600161014051018060405190131561014657600080fd5b809190121561015457600080fd5b6020811061016157600080fd5b600260c052602060c02001555b81516001018083528114156100aa575b505061134056600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052600015610277575b6101605261014052600061018052610140516101a0526101c060006008818352015b61018051600860008112156100da578060000360020a82046100e1565b8060020a82025b905090506101805260ff6101a051166101e052610180516101e0516101805101101561010c57600080fd5b6101e0516101805101610180526101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff86000811215610155578060000360020a820461015c565b8060020a82025b905090506101a0525b81516001018083528114156100bd575b50506018600860208206610200016020828401111561019357600080fd5b60208061022082610180600060046015f15050818152809050905090508051602001806102c0828460006004600a8704601201f16101d057600080fd5b50506102c05160206001820306601f82010390506103206102c0516008818352015b826103205111156102025761021e565b6000610320516102e001535b81516001018083528114156101f2575b50505060206102a05260406102c0510160206001820306601f8201039050610280525b6000610280511115156102535761026f565b602061028051036102a001516020610280510361028052610241565b610160515650005b63c5f2892f60005114156103cf57341561029057600080fd5b6000610140526001546101605261018060006020818352015b600160016101605116141561032a57600061018051602081106102cb57600080fd5b600060c052602060c02001546020826102200101526020810190506101405160208261022001015260208101905080610220526102209050602060c0825160208401600060025af161031c57600080fd5b60c051905061014052610398565b6000610140516020826101a0010152602081019050610180516020811061035057600080fd5b600260c052602060c02001546020826101a0010152602081019050806101a0526101a09050602060c0825160208401600060025af161038e57600080fd5b60c0519050610140525b61016060026103a657600080fd5b60028151048152505b81516001018083528114156102a9575b50506101405160005260206000f3005b63621fd13060005114156104e15734156103e857600080fd5b63806732896101405260015461016052610160516006580161009b565b506101c0526000610220525b6101c05160206001820306601f8201039050610220511015156104335761044c565b610220516101e001526102205160200161022052610411565b6101c0805160200180610280828460006004600a8704601201f161046f57600080fd5b50506102805160206001820306601f82010390506102e0610280516008818352015b826102e05111156104a1576104bd565b60006102e0516102a001535b8151600101808352811415610491575b5050506020610260526040610280510160206001820306601f8201039050610260f3005b63c47e300d60005114156111b557606060046101403760506004356004016101a037603060043560040135111561051757600080fd5b604060243560040161022037602060243560040135111561053757600080fd5b608060443560040161028037606060443560040135111561055757600080fd5b63ffffffff6001541061056957600080fd5b633b9aca00610340526103405161057f57600080fd5b61034051340461032052633b9aca0061032051101561059d57600080fd5b60306101a051146105ad57600080fd5b602061022051146105bd57600080fd5b606061028051146105cd57600080fd5b6101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a05163806732896103c052610320516103e0526103e0516006580161009b565b506104405260006104a0525b6104405160206001820306601f82010390506104a05110151561065d57610676565b6104a05161046001526104a0516020016104a05261063b565b6103a05261038052610360526103405261032052610300526102e0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a052610440805160200180610360828460006004600a8704601201f16106dd57600080fd5b505060006101a060308060208461058001018260208501600060046016f15050805182019150506000601060208206610500016020828401111561072057600080fd5b602080610520826104c0600060046015f150508181528090509050905060108060208461058001018260208501600060046013f150508051820191505080610580526105809050602060c0825160208401600060025af161078057600080fd5b60c05190506104e05260006000604060208206610620016102805182840111156107a957600080fd5b606080610640826020602088068803016102800160006004601bf1505081815280905090509050602060c0825160208401600060025af16107e957600080fd5b60c0519050602082610820010152602081019050600060406020602082066106e00161028051828401111561081d57600080fd5b606080610700826020602088068803016102800160006004601bf15050818152809050905090506020806020846107a001018260208501600060046015f15050805182019150506104c0516020826107a0010152602081019050806107a0526107a09050602060c0825160208401600060025af161089a57600080fd5b60c051905060208261082001015260208101905080610820526108209050602060c0825160208401600060025af16108d157600080fd5b60c051905061060052600060006104e0516020826108c00101526020810190506102206020806020846108c001018260208501600060046015f1505080518201915050806108c0526108c09050602060c0825160208401600060025af161093757600080fd5b60c0519050602082610a4001015260208101905060006103606008806020846109c001018260208501600060046012f15050805182019150506000601860208206610940016020828401111561098c57600080fd5b602080610960826104c0600060046015f15050818152809050905090506018806020846109c001018260208501600060046014f1505080518201915050610600516020826109c0010152602081019050806109c0526109c09050602060c0825160208401600060025af16109ff57600080fd5b60c0519050602082610a4001015260208101905080610a4052610a409050602060c0825160208401600060025af1610a3657600080fd5b60c05190506108a0526101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a0516103c0516103e05161040051610420516104405161046051610480516104a0516104c0516104e05161050051610520516105405161056051610580516105a0516105c0516105e05161060051610620516106405161066051610680516106a0516106c0516106e05161070051610720516107405161076051610780516107a0516107c0516107e05161080051610820516108405161086051610880516108a0516108c0516108e05161090051610920516109405161096051610980516109a0516109c0516109e051610a0051610a2051610a4051610a6051610a8051610aa0516380673289610ac052600154610ae052610ae0516006580161009b565b50610b40526000610ba0525b610b405160206001820306601f8201039050610ba051101515610bae57610bc7565b610ba051610b600152610ba051602001610ba052610b8c565b610aa052610a8052610a6052610a4052610a2052610a00526109e0526109c0526109a05261098052610960526109405261092052610900526108e0526108c0526108a05261088052610860526108405261082052610800526107e0526107c0526107a05261078052610760526107405261072052610700526106e0526106c0526106a05261068052610660526106405261062052610600526105e0526105c0526105a05261058052610560526105405261052052610500526104e0526104c0526104a05261048052610460526104405261042052610400526103e0526103c0526103a05261038052610360526103405261032052610300526102e0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a052610b40805160200180610bc0828460006004600a8704601201f1610d0e57600080fd5b505060a0610c4052610c4051610c80526101a0805160200180610c4051610c8001828460006004600a8704601201f1610d4657600080fd5b5050610c4051610c80015160206001820306601f8201039050610c4051610c8001610c2081516040818352015b83610c2051101515610d8457610da1565b6000610c20516020850101535b8151600101808352811415610d73575b505050506020610c4051610c80015160206001820306601f8201039050610c40510101610c4052610c4051610ca052610220805160200180610c4051610c8001828460006004600a8704601201f1610df857600080fd5b5050610c4051610c80015160206001820306601f8201039050610c4051610c8001610c2081516020818352015b83610c2051101515610e3657610e53565b6000610c20516020850101535b8151600101808352811415610e25575b505050506020610c4051610c80015160206001820306601f8201039050610c40510101610c4052610c4051610cc052610360805160200180610c4051610c8001828460006004600a8704601201f1610eaa57600080fd5b5050610c4051610c80015160206001820306601f8201039050610c4051610c8001610c2081516020818352015b83610c2051101515610ee857610f05565b6000610c20516020850101535b8151600101808352811415610ed7575b505050506020610c4051610c80015160206001820306601f8201039050610c40510101610c4052610c4051610ce052610280805160200180610c4051610c8001828460006004600a8704601201f1610f5c57600080fd5b5050610c4051610c80015160206001820306601f8201039050610c4051610c8001610c2081516060818352015b83610c2051101515610f9a57610fb7565b6000610c20516020850101535b8151600101808352811415610f89575b505050506020610c4051610c80015160206001820306601f8201039050610c40510101610c4052610c4051610d0052610bc0805160200180610c4051610c8001828460006004600a8704601201f161100e57600080fd5b5050610c4051610c80015160206001820306601f8201039050610c4051610c8001610c2081516020818352015b83610c205110151561104c57611069565b6000610c20516020850101535b815160010180835281141561103b575b505050506020610c4051610c80015160206001820306601f8201039050610c40510101610c40527fdc5fc95703516abd38fa03c3737ff3b52dc52347055c8028460fdf5bbe2f12ce610c4051610c80a160018054600182540110156110cd57600080fd5b6001815401815550600154610d2052610d4060006020818352015b60016001610d205116141561111d576108a051610d40516020811061110c57600080fd5b600060c052602060c02001556111b1565b6000610d40516020811061113057600080fd5b600060c052602060c0200154602082610d600101526020810190506108a051602082610d6001015260208101905080610d6052610d609050602060c0825160208401600060025af161118157600080fd5b60c05190506108a052610d20600261119857600080fd5b60028151048152505b81516001018083528114156110e8575b5050005b60006000fd5b61018561134003610185600039610185611340036000f3"} \ No newline at end of file diff --git a/deposit_contract/contracts/validator_registration.v.py b/deposit_contract/contracts/validator_registration.v.py index 8510380ee2..10daf42b93 100644 --- a/deposit_contract/contracts/validator_registration.v.py +++ b/deposit_contract/contracts/validator_registration.v.py @@ -11,6 +11,7 @@ withdrawal_credentials: bytes[32], amount: bytes[8], signature: bytes[96], + index: bytes[8], }) branch: bytes32[DEPOSIT_CONTRACT_TREE_DEPTH] @@ -24,7 +25,7 @@ def __init__(): self.zero_hashes[i + 1] = sha256(concat(self.zero_hashes[i], self.zero_hashes[i])) -@public +@private @constant def to_little_endian_64(value: uint256) -> bytes[8]: # Reversing bytes using bitwise uint256 manipulations @@ -87,6 +88,9 @@ def deposit(pubkey: bytes[PUBKEY_LENGTH], sha256(concat(amount, slice(zero_bytes32, start=0, len=32 - AMOUNT_LENGTH), signature_root)), )) + # Emit `Deposit` log + log.Deposit(pubkey, withdrawal_credentials, amount, signature, self.to_little_endian_64(self.deposit_count)) + # Add `DepositData` root to Merkle tree (update a single `branch` node) self.deposit_count += 1 size: uint256 = self.deposit_count @@ -97,5 +101,3 @@ def deposit(pubkey: bytes[PUBKEY_LENGTH], node = sha256(concat(self.branch[height], node)) size /= 2 - # Emit `Deposit` log - log.Deposit(pubkey, withdrawal_credentials, amount, signature) diff --git a/deposit_contract/tests/contracts/test_deposit.py b/deposit_contract/tests/contracts/test_deposit.py index 12f3e7f8bb..783af33567 100644 --- a/deposit_contract/tests/contracts/test_deposit.py +++ b/deposit_contract/tests/contracts/test_deposit.py @@ -49,28 +49,6 @@ def deposit_input(): ) -@pytest.mark.parametrize( - 'value,success', - [ - (0, True), - (10, True), - (55555, True), - (2**64 - 1, True), - # (2**64, True), # Note that all calls to `to_little_endian_64` have an input less than 2**64 - ] -) -def test_to_little_endian_64(registration_contract, value, success, assert_tx_failed): - call = registration_contract.functions.to_little_endian_64(value) - - if success: - little_endian_64 = call.call() - assert little_endian_64 == (value).to_bytes(8, 'little') - else: - assert_tx_failed( - lambda: call.call() - ) - - @pytest.mark.parametrize( 'success,deposit_amount', [ @@ -151,7 +129,7 @@ def test_deposit_log(registration_contract, a0, w3, deposit_input): assert log['withdrawal_credentials'] == deposit_input[1] assert log['amount'] == deposit_amount_list[i].to_bytes(8, 'little') assert log['signature'] == deposit_input[2] - + assert log['index'] == i.to_bytes(8, 'little') def test_deposit_tree(registration_contract, w3, assert_tx_failed, deposit_input): log_filter = registration_contract.events.Deposit.createFilter( @@ -171,6 +149,8 @@ def test_deposit_tree(registration_contract, w3, assert_tx_failed, deposit_input assert len(logs) == 1 log = logs[0]['args'] + assert log["index"] == i.to_bytes(8, 'little') + deposit_data = DepositData( pubkey=deposit_input[0], withdrawal_credentials=deposit_input[1],