From f441301d168d601fd8e251bc65109bc143cd0300 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 14 Apr 2020 21:44:39 +0100 Subject: [PATCH 01/69] Genesis --- LICENSE | 202 +++++++++++++++++++++++++++++++++++++++++++ README.md | 7 ++ deposit_contract.sol | 19 ++++ 3 files changed, 228 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 deposit_contract.sol diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..d64569567 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 000000000..99a0f118c --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# eth2-deposit-contract + +This is a just for fun port of the [Vyper Eth 2.0 deposit contract](https://github.com/ethereum/eth2.0-specs/blob/dev/deposit_contract/contracts/validator_registration.vy) to Solidity. + +The motivation is to run the SMTChecker and the new Yul IR generator option (`--ir`) in the compiler. + +**THIS IS NOT THE OFFICIAL DEPOSIT CONTRACT. NOT SUITABLE FOR ANY USE** diff --git a/deposit_contract.sol b/deposit_contract.sol new file mode 100644 index 000000000..49ee94d53 --- /dev/null +++ b/deposit_contract.sol @@ -0,0 +1,19 @@ +pragma solidity ^0.6.0; + +// This interface is designed to be compatible with the Vyper version. +interface IDepositContract { + event DepositEvent( + bytes pubkey, + bytes withdrawal_credentials, + bytes amount, + bytes signature, + bytes index + ); + + function deposit( + bytes calldata pubkey, + bytes calldata withdrawal_credentials, + bytes calldata signature, + bytes32 deposit_data_root + ) external payable; +} From 65ce39b5004ea588ec7df8ec63d358bd78a94378 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 14 Apr 2020 21:57:58 +0100 Subject: [PATCH 02/69] First implementation of the deposit() function only --- deposit_contract.sol | 101 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/deposit_contract.sol b/deposit_contract.sol index 49ee94d53..ec7fa1c28 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -17,3 +17,104 @@ interface IDepositContract { bytes32 deposit_data_root ) external payable; } + +/* + * This is a rewrite of the Vyper Eth2.0 deposit contract in Solidity. + * It tries to stay as close as possible to the original source code and + * hence it may look a bit unintuitive to a reader well versed in Solidity. + */ +contract DepositContract is IDepositContract { + uint constant GWEI = 1e9; + + uint constant MIN_DEPOSIT_AMOUNT = 1000000000; // Gwei + uint constant DEPOSIT_CONTRACT_TREE_DEPTH = 32; + uint constant MAX_DEPOSIT_COUNT = 4294967295; // 2**DEPOSIT_CONTRACT_TREE_DEPTH - 1 + uint constant PUBKEY_LENGTH = 48; // bytes + uint constant WITHDRAWAL_CREDENTIALS_LENGTH = 32; // bytes + uint constant SIGNATURE_LENGTH = 96; // bytes + uint constant AMOUNT_LENGTH = 8; // bytes + + bytes32[DEPOSIT_CONTRACT_TREE_DEPTH] branch; + uint256 deposit_count; + + // TODO: add constructor + + // TODO: add get_deposit_root + + // TODO: add get_deposit_count + + function deposit( + bytes calldata pubkey, + bytes calldata withdrawal_credentials, + bytes calldata signature, + bytes32 deposit_data_root + ) override external payable { + // Avoid overflowing the Merkle tree (and prevent edge case in computing `self.branch`) + require(deposit_count < MAX_DEPOSIT_COUNT); + + // Check deposit amount + uint deposit_amount = msg.value / GWEI; + require(deposit_amount >= MIN_DEPOSIT_AMOUNT); + + // Length checks for safety + require(pubkey.length == PUBKEY_LENGTH); + require(withdrawal_credentials.length == WITHDRAWAL_CREDENTIALS_LENGTH); + require(signature.length == SIGNATURE_LENGTH); + + // FIXME: these are not the Vyper code, but should verify they are not needed + // assert(deposit_amount <= 2^64-1); + // assert(deposit_count <= 2^64-1); + + // Emit `DepositEvent` log + bytes memory amount = to_little_endian_64(uint64(deposit_amount)); + emit DepositEvent( + pubkey, + withdrawal_credentials, + amount, + signature, + to_little_endian_64(uint64(deposit_count)) + ); + + // Compute deposit data root (`DepositData` hash tree root) + // These are helpers and are implicitly initialised to zero. + bytes16 zero_bytes16; + bytes24 zero_bytes24; + bytes32 zero_bytes32; + bytes32 pubkey_root = sha256(abi.encodePacked(pubkey, zero_bytes16)); + bytes32 signature_root = sha256(abi.encodePacked( + sha256(abi.encodePacked(bytes(signature[:64]))), + sha256(abi.encodePacked(bytes(signature[64:]), zero_bytes32)) + )); + bytes32 node = sha256(abi.encodePacked( + sha256(abi.encodePacked(pubkey_root, withdrawal_credentials)), + sha256(abi.encodePacked(amount, zero_bytes24, signature_root)) + )); + // Verify computed and expected deposit data roots match + require(node == deposit_data_root); + + // Add deposit data root to Merkle tree (update a single `branch` node) + deposit_count += 1; + uint size = deposit_count; + for (uint height = 0; height < DEPOSIT_CONTRACT_TREE_DEPTH; height++) { + if ((size & 1) == 1) { + branch[height] = node; + break; + } + node = sha256(abi.encodePacked(branch[height], node)); + size /= 2; + } + } + + function to_little_endian_64(uint64 value) internal pure returns (bytes memory ret) { + // Unrolled the loop here. + ret = new bytes(8); + ret[0] = bytes1(uint8(value & 0xff)); + ret[1] = bytes1(uint8((value >> 8) & 0xff)); + ret[2] = bytes1(uint8((value >> 16) & 0xff)); + ret[3] = bytes1(uint8((value >> 24) & 0xff)); + ret[4] = bytes1(uint8((value >> 32) & 0xff)); + ret[5] = bytes1(uint8((value >> 40) & 0xff)); + ret[6] = bytes1(uint8((value >> 48) & 0xff)); + ret[7] = bytes1(uint8((value >> 56) & 0xff)); + } +} From b0c9d8c2fd6beaddee389f0af870509f6e585990 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 14 Apr 2020 22:46:45 +0100 Subject: [PATCH 03/69] Implement get_deposit_count() and get_deposit_root() --- deposit_contract.sol | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index ec7fa1c28..ee15ba7b7 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -37,11 +37,36 @@ contract DepositContract is IDepositContract { bytes32[DEPOSIT_CONTRACT_TREE_DEPTH] branch; uint256 deposit_count; - // TODO: add constructor + // TODO: use immutable for this + bytes32[DEPOSIT_CONTRACT_TREE_DEPTH] zero_hashes; - // TODO: add get_deposit_root + // Compute hashes in empty sparse Merkle tree + constructor() public { + for (uint height = 0; height < DEPOSIT_CONTRACT_TREE_DEPTH - 1; height++) + zero_hashes[height + 1] = sha256(abi.encodePacked(zero_hashes[height], zero_hashes[height])); + } - // TODO: add get_deposit_count + function get_deposit_root() external view returns (bytes32) { + bytes24 zero_bytes24; + bytes32 node; + uint size = deposit_count; + for (uint height = 0; height < DEPOSIT_CONTRACT_TREE_DEPTH; height++) { + if ((size & 1) == 1) + node = sha256(abi.encodePacked(branch[height], node)); + else + node = sha256(abi.encodePacked(node, zero_hashes[height])); + size /= 2; + } + return sha256(abi.encodePacked( + node, + to_little_endian_64(uint64(deposit_count)), + zero_bytes24 + )); + } + + function get_deposit_count() external view returns (bytes memory) { + return to_little_endian_64(uint64(deposit_count)); + } function deposit( bytes calldata pubkey, From faecab11003f884a6d36776aa261600c05f36b70 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 15 Apr 2020 12:03:19 +0100 Subject: [PATCH 04/69] Add Makefile and instructions for the tests in the README --- Makefile | 12 ++++++++++++ README.md | 10 ++++++++++ 2 files changed, 22 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..7564a587d --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +all: compile + +clean: + @rm -f DepositContract.abi DepositContract.bin IDepositContract.abi IDepositContract.bin deposit_contract.json + +compile: clean + @solc --bin --abi --overwrite -o . deposit_contract.sol + @/bin/echo -n '{"abi": ' > deposit_contract.json + @cat DepositContract.abi >> deposit_contract.json + @/bin/echo -n ', "bytecode": "0x' >> deposit_contract.json + @cat DepositContract.bin >> deposit_contract.json + @/bin/echo -n '"}' >> deposit_contract.json diff --git a/README.md b/README.md index 99a0f118c..f34864759 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,13 @@ This is a just for fun port of the [Vyper Eth 2.0 deposit contract](https://gith The motivation is to run the SMTChecker and the new Yul IR generator option (`--ir`) in the compiler. **THIS IS NOT THE OFFICIAL DEPOSIT CONTRACT. NOT SUITABLE FOR ANY USE** + +## Using this with the tests + +1. Create the `deposit_contract.json` with running `make` (this requires `solc` to be in the path) +2. Download [eth2.0-specs](https://github.com/ethereum/eth2.0-specs) +3. Replace `eth2.0-specs/deposit_contract/contracts/validator_registration.json` with `deposit_contract.json` +4. In the `eth2.0-specs` directory run `make install_deposit_contract_tester` to install the tools needed (make sure to have Python 3.7 and pip installed) +5. Finally in the `eth2.0-specs` directory run `make test_deposit_contract` to execute the tests + +The Makefile currently compiles the code without optimisations. To enable optimisations add `--optimize` to the `solc` line. From 304bdc9d4e3d3f7438ac3e93533c8cef9953ac97 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 15 Apr 2020 14:37:41 +0100 Subject: [PATCH 05/69] Add .gitattributes with Solidity --- .gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..52031de51 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.sol linguist-language=Solidity From 2000988671ca818f6aef8653ef73f0f23416d39c Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 16 Apr 2020 18:12:58 +0100 Subject: [PATCH 06/69] Fix a typo in the assertion (within the comments) --- deposit_contract.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index ee15ba7b7..d756c2524 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -87,8 +87,8 @@ contract DepositContract is IDepositContract { require(signature.length == SIGNATURE_LENGTH); // FIXME: these are not the Vyper code, but should verify they are not needed - // assert(deposit_amount <= 2^64-1); - // assert(deposit_count <= 2^64-1); + // assert(deposit_amount <= 2**64-1); + // assert(deposit_count <= 2**64-1); // Emit `DepositEvent` log bytes memory amount = to_little_endian_64(uint64(deposit_amount)); From 3aaf6f06ad970b62c305f162edc848725f3d3d9a Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 12 May 2020 01:06:31 +0100 Subject: [PATCH 07/69] Add license header and clarify comment --- deposit_contract.sol | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index d756c2524..013c133f8 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: Apache-2.0 + pragma solidity ^0.6.0; // This interface is designed to be compatible with the Vyper version. @@ -18,11 +20,8 @@ interface IDepositContract { ) external payable; } -/* - * This is a rewrite of the Vyper Eth2.0 deposit contract in Solidity. - * It tries to stay as close as possible to the original source code and - * hence it may look a bit unintuitive to a reader well versed in Solidity. - */ +// This is a rewrite of the Vyper Eth2.0 deposit contract in Solidity. +// It tries to stay as close as possible to the original source code. contract DepositContract is IDepositContract { uint constant GWEI = 1e9; From 99575407445fc793b475f7acd5a1acdd45e07785 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 12 May 2020 00:57:17 +0100 Subject: [PATCH 08/69] Consider get_deposit_count and get_deposit_root part of the external interface --- deposit_contract.sol | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index 013c133f8..5369024f2 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -18,6 +18,10 @@ interface IDepositContract { bytes calldata signature, bytes32 deposit_data_root ) external payable; + + function get_deposit_root() external view returns (bytes32); + + function get_deposit_count() external view returns (bytes memory); } // This is a rewrite of the Vyper Eth2.0 deposit contract in Solidity. @@ -45,7 +49,7 @@ contract DepositContract is IDepositContract { zero_hashes[height + 1] = sha256(abi.encodePacked(zero_hashes[height], zero_hashes[height])); } - function get_deposit_root() external view returns (bytes32) { + function get_deposit_root() override external view returns (bytes32) { bytes24 zero_bytes24; bytes32 node; uint size = deposit_count; @@ -63,7 +67,7 @@ contract DepositContract is IDepositContract { )); } - function get_deposit_count() external view returns (bytes memory) { + function get_deposit_count() override external view returns (bytes memory) { return to_little_endian_64(uint64(deposit_count)); } From cd323c75db63906ed691941c302a19a45280c54f Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 12 May 2020 18:59:15 +0100 Subject: [PATCH 09/69] Drop masking because of explicit uint8 conversion (#5) --- deposit_contract.sol | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index 5369024f2..003e9afdf 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -136,13 +136,13 @@ contract DepositContract is IDepositContract { function to_little_endian_64(uint64 value) internal pure returns (bytes memory ret) { // Unrolled the loop here. ret = new bytes(8); - ret[0] = bytes1(uint8(value & 0xff)); - ret[1] = bytes1(uint8((value >> 8) & 0xff)); - ret[2] = bytes1(uint8((value >> 16) & 0xff)); - ret[3] = bytes1(uint8((value >> 24) & 0xff)); - ret[4] = bytes1(uint8((value >> 32) & 0xff)); - ret[5] = bytes1(uint8((value >> 40) & 0xff)); - ret[6] = bytes1(uint8((value >> 48) & 0xff)); - ret[7] = bytes1(uint8((value >> 56) & 0xff)); + ret[0] = bytes1(uint8(value)); + ret[1] = bytes1(uint8(value >> 8)); + ret[2] = bytes1(uint8(value >> 16)); + ret[3] = bytes1(uint8(value >> 24)); + ret[4] = bytes1(uint8(value >> 32)); + ret[5] = bytes1(uint8(value >> 40)); + ret[6] = bytes1(uint8(value >> 48)); + ret[7] = bytes1(uint8(value >> 56)); } } From acb658fbdab718e5018ee7fe11884e07b2c42532 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 12 May 2020 20:01:27 +0200 Subject: [PATCH 10/69] Make use of constants. (#7) --- deposit_contract.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index 003e9afdf..c68538974 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -31,7 +31,7 @@ contract DepositContract is IDepositContract { uint constant MIN_DEPOSIT_AMOUNT = 1000000000; // Gwei uint constant DEPOSIT_CONTRACT_TREE_DEPTH = 32; - uint constant MAX_DEPOSIT_COUNT = 4294967295; // 2**DEPOSIT_CONTRACT_TREE_DEPTH - 1 + uint constant MAX_DEPOSIT_COUNT = 2**DEPOSIT_CONTRACT_TREE_DEPTH - 1; uint constant PUBKEY_LENGTH = 48; // bytes uint constant WITHDRAWAL_CREDENTIALS_LENGTH = 32; // bytes uint constant SIGNATURE_LENGTH = 96; // bytes From a8ed83e08784d195980c5b517bf51ede3bb7e71c Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 12 May 2020 19:04:18 +0100 Subject: [PATCH 11/69] Inline bytesN(0) instead of custom zero_bytesN vars (#8) Co-authored-by: Martin Lundfall --- deposit_contract.sol | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index c68538974..0f751969e 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -50,7 +50,6 @@ contract DepositContract is IDepositContract { } function get_deposit_root() override external view returns (bytes32) { - bytes24 zero_bytes24; bytes32 node; uint size = deposit_count; for (uint height = 0; height < DEPOSIT_CONTRACT_TREE_DEPTH; height++) { @@ -63,7 +62,7 @@ contract DepositContract is IDepositContract { return sha256(abi.encodePacked( node, to_little_endian_64(uint64(deposit_count)), - zero_bytes24 + bytes24(0) )); } @@ -104,18 +103,14 @@ contract DepositContract is IDepositContract { ); // Compute deposit data root (`DepositData` hash tree root) - // These are helpers and are implicitly initialised to zero. - bytes16 zero_bytes16; - bytes24 zero_bytes24; - bytes32 zero_bytes32; - bytes32 pubkey_root = sha256(abi.encodePacked(pubkey, zero_bytes16)); + bytes32 pubkey_root = sha256(abi.encodePacked(pubkey, bytes16(0))); bytes32 signature_root = sha256(abi.encodePacked( sha256(abi.encodePacked(bytes(signature[:64]))), - sha256(abi.encodePacked(bytes(signature[64:]), zero_bytes32)) + sha256(abi.encodePacked(bytes(signature[64:]), bytes32(0))) )); bytes32 node = sha256(abi.encodePacked( sha256(abi.encodePacked(pubkey_root, withdrawal_credentials)), - sha256(abi.encodePacked(amount, zero_bytes24, signature_root)) + sha256(abi.encodePacked(amount, bytes24(0), signature_root)) )); // Verify computed and expected deposit data roots match require(node == deposit_data_root); From df7c2c538a3bf76c82150a3a395f3145d8d487af Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 13 May 2020 14:41:37 +0100 Subject: [PATCH 12/69] Require deposit amount to fit into uint64 (#9) Ref https://github.com/ethereum/eth2.0-specs/issues/1726 --- deposit_contract.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index 0f751969e..81c33a288 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -82,6 +82,7 @@ contract DepositContract is IDepositContract { // Check deposit amount uint deposit_amount = msg.value / GWEI; require(deposit_amount >= MIN_DEPOSIT_AMOUNT); + require(deposit_amount < 2**64); // Length checks for safety require(pubkey.length == PUBKEY_LENGTH); @@ -89,7 +90,6 @@ contract DepositContract is IDepositContract { require(signature.length == SIGNATURE_LENGTH); // FIXME: these are not the Vyper code, but should verify they are not needed - // assert(deposit_amount <= 2**64-1); // assert(deposit_count <= 2**64-1); // Emit `DepositEvent` log From b236ce7a9a5a409d91cb8f647b836062184e81f0 Mon Sep 17 00:00:00 2001 From: MrChico Date: Wed, 13 May 2020 15:46:58 +0200 Subject: [PATCH 13/69] Defensive handling of dead path (#13) --- deposit_contract.sol | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index 81c33a288..a94e8fbf0 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -121,11 +121,14 @@ contract DepositContract is IDepositContract { for (uint height = 0; height < DEPOSIT_CONTRACT_TREE_DEPTH; height++) { if ((size & 1) == 1) { branch[height] = node; - break; + return; } node = sha256(abi.encodePacked(branch[height], node)); size /= 2; } + // As the loop should always end prematurely with the `return` statement, + // this code should be unreachable. We assert `false` just to be safe. + assert(false); } function to_little_endian_64(uint64 value) internal pure returns (bytes memory ret) { From 9cdf14da990a3c31e10fb2e1ae2dc38a15579221 Mon Sep 17 00:00:00 2001 From: MrChico Date: Wed, 13 May 2020 15:47:49 +0200 Subject: [PATCH 14/69] Remove unused variable (#15) --- deposit_contract.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index a94e8fbf0..51d88d41e 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -35,7 +35,6 @@ contract DepositContract is IDepositContract { uint constant PUBKEY_LENGTH = 48; // bytes uint constant WITHDRAWAL_CREDENTIALS_LENGTH = 32; // bytes uint constant SIGNATURE_LENGTH = 96; // bytes - uint constant AMOUNT_LENGTH = 8; // bytes bytes32[DEPOSIT_CONTRACT_TREE_DEPTH] branch; uint256 deposit_count; From c24305d5d2e86f269a10181028bbd923a559ca25 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 13 May 2020 15:56:36 +0100 Subject: [PATCH 15/69] Clarify/remove some comments (#16) * Remove assert(deposit_count <= 2**64-1) comment * Remove the outdated TODO comment * Rephrase some comments Co-authored-by: MrChico --- deposit_contract.sol | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index 51d88d41e..9c4c89eff 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -31,6 +31,7 @@ contract DepositContract is IDepositContract { uint constant MIN_DEPOSIT_AMOUNT = 1000000000; // Gwei uint constant DEPOSIT_CONTRACT_TREE_DEPTH = 32; + // NOTE: this also ensures `deposit_count` will fit into 64-bits uint constant MAX_DEPOSIT_COUNT = 2**DEPOSIT_CONTRACT_TREE_DEPTH - 1; uint constant PUBKEY_LENGTH = 48; // bytes uint constant WITHDRAWAL_CREDENTIALS_LENGTH = 32; // bytes @@ -39,11 +40,10 @@ contract DepositContract is IDepositContract { bytes32[DEPOSIT_CONTRACT_TREE_DEPTH] branch; uint256 deposit_count; - // TODO: use immutable for this bytes32[DEPOSIT_CONTRACT_TREE_DEPTH] zero_hashes; - // Compute hashes in empty sparse Merkle tree constructor() public { + // Compute hashes in empty sparse Merkle tree for (uint height = 0; height < DEPOSIT_CONTRACT_TREE_DEPTH - 1; height++) zero_hashes[height + 1] = sha256(abi.encodePacked(zero_hashes[height], zero_hashes[height])); } @@ -75,7 +75,7 @@ contract DepositContract is IDepositContract { bytes calldata signature, bytes32 deposit_data_root ) override external payable { - // Avoid overflowing the Merkle tree (and prevent edge case in computing `self.branch`) + // Avoid overflowing the Merkle tree (and prevent edge case in computing `branch`) require(deposit_count < MAX_DEPOSIT_COUNT); // Check deposit amount @@ -88,9 +88,6 @@ contract DepositContract is IDepositContract { require(withdrawal_credentials.length == WITHDRAWAL_CREDENTIALS_LENGTH); require(signature.length == SIGNATURE_LENGTH); - // FIXME: these are not the Vyper code, but should verify they are not needed - // assert(deposit_count <= 2**64-1); - // Emit `DepositEvent` log bytes memory amount = to_little_endian_64(uint64(deposit_amount)); emit DepositEvent( From 4d493e70af7065d103545ff8d39ed0a868b78bbd Mon Sep 17 00:00:00 2001 From: MrChico Date: Wed, 13 May 2020 17:45:05 +0200 Subject: [PATCH 16/69] Require deposit to be divisible by GWEI (#14) --- deposit_contract.sol | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index 9c4c89eff..93242c726 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -29,7 +29,7 @@ interface IDepositContract { contract DepositContract is IDepositContract { uint constant GWEI = 1e9; - uint constant MIN_DEPOSIT_AMOUNT = 1000000000; // Gwei + uint constant MIN_DEPOSIT_AMOUNT = 1 ether; uint constant DEPOSIT_CONTRACT_TREE_DEPTH = 32; // NOTE: this also ensures `deposit_count` will fit into 64-bits uint constant MAX_DEPOSIT_COUNT = 2**DEPOSIT_CONTRACT_TREE_DEPTH - 1; @@ -79,8 +79,9 @@ contract DepositContract is IDepositContract { require(deposit_count < MAX_DEPOSIT_COUNT); // Check deposit amount + require(msg.value >= MIN_DEPOSIT_AMOUNT); + require(msg.value % GWEI == 0); uint deposit_amount = msg.value / GWEI; - require(deposit_amount >= MIN_DEPOSIT_AMOUNT); require(deposit_amount < 2**64); // Length checks for safety From d18c12b7767099cd1fb6ea6ff639c72cff7d05b2 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 13 May 2020 16:49:07 +0100 Subject: [PATCH 17/69] Move ABI checks to be first in the code (#10) --- deposit_contract.sol | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index 93242c726..f4e36b225 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -75,6 +75,11 @@ contract DepositContract is IDepositContract { bytes calldata signature, bytes32 deposit_data_root ) override external payable { + // Extended ABI length checks since dynamic types are used. + require(pubkey.length == PUBKEY_LENGTH); + require(withdrawal_credentials.length == WITHDRAWAL_CREDENTIALS_LENGTH); + require(signature.length == SIGNATURE_LENGTH); + // Avoid overflowing the Merkle tree (and prevent edge case in computing `branch`) require(deposit_count < MAX_DEPOSIT_COUNT); @@ -84,11 +89,6 @@ contract DepositContract is IDepositContract { uint deposit_amount = msg.value / GWEI; require(deposit_amount < 2**64); - // Length checks for safety - require(pubkey.length == PUBKEY_LENGTH); - require(withdrawal_credentials.length == WITHDRAWAL_CREDENTIALS_LENGTH); - require(signature.length == SIGNATURE_LENGTH); - // Emit `DepositEvent` log bytes memory amount = to_little_endian_64(uint64(deposit_amount)); emit DepositEvent( From 823e8a5c685cd2e9a7c166c50df3175ad283d453 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 13 May 2020 23:03:42 +0100 Subject: [PATCH 18/69] Add CircleCI configuration (#18) * Simplify Makefile * Add CircleCI configuration --- Makefile | 6 +++--- circle.yml | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 circle.yml diff --git a/Makefile b/Makefile index 7564a587d..af166fe4d 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,8 @@ clean: compile: clean @solc --bin --abi --overwrite -o . deposit_contract.sol - @/bin/echo -n '{"abi": ' > deposit_contract.json + @echo -n '{"abi": ' > deposit_contract.json @cat DepositContract.abi >> deposit_contract.json - @/bin/echo -n ', "bytecode": "0x' >> deposit_contract.json + @echo -n ', "bytecode": "0x' >> deposit_contract.json @cat DepositContract.bin >> deposit_contract.json - @/bin/echo -n '"}' >> deposit_contract.json + @echo -n '"}' >> deposit_contract.json diff --git a/circle.yml b/circle.yml new file mode 100644 index 000000000..dfcae7743 --- /dev/null +++ b/circle.yml @@ -0,0 +1,16 @@ +version: 2.0 +jobs: + build: + docker: + - image: cimg/base:2020.01 + steps: + - checkout + - run: + name: Install solidity + command: | + sudo add-apt-repository ppa:ethereum/ethereum + sudo apt-get update + sudo apt-get install solc + - run: + name: Compile the contract + command: make From 48755f704fe20e8dcb60d45dbb6a605ad5fb6558 Mon Sep 17 00:00:00 2001 From: MrChico Date: Thu, 14 May 2020 12:42:59 +0200 Subject: [PATCH 19/69] Add revert reason strings (#11) Co-authored-by: Alex Beregszaszi --- deposit_contract.sol | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index f4e36b225..05509516b 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -76,18 +76,18 @@ contract DepositContract is IDepositContract { bytes32 deposit_data_root ) override external payable { // Extended ABI length checks since dynamic types are used. - require(pubkey.length == PUBKEY_LENGTH); - require(withdrawal_credentials.length == WITHDRAWAL_CREDENTIALS_LENGTH); - require(signature.length == SIGNATURE_LENGTH); + require(pubkey.length == PUBKEY_LENGTH, "DepositContract: invalid pubkey length"); + require(withdrawal_credentials.length == WITHDRAWAL_CREDENTIALS_LENGTH, "DepositContract: invalid withdrawal_credentials length"); + require(signature.length == SIGNATURE_LENGTH, "DepositContract: invalid signature length"); // Avoid overflowing the Merkle tree (and prevent edge case in computing `branch`) - require(deposit_count < MAX_DEPOSIT_COUNT); + require(deposit_count < MAX_DEPOSIT_COUNT, "DepositContract: merkle tree full"); // Check deposit amount - require(msg.value >= MIN_DEPOSIT_AMOUNT); - require(msg.value % GWEI == 0); + require(msg.value >= MIN_DEPOSIT_AMOUNT, "DepositContract: deposit value too low"); + require(msg.value % GWEI == 0, "DepositContract: deposit value not multiple of gwei"); uint deposit_amount = msg.value / GWEI; - require(deposit_amount < 2**64); + require(deposit_amount < 2**64, "DepositContract: deposit value too high"); // Emit `DepositEvent` log bytes memory amount = to_little_endian_64(uint64(deposit_amount)); @@ -110,7 +110,7 @@ contract DepositContract is IDepositContract { sha256(abi.encodePacked(amount, bytes24(0), signature_root)) )); // Verify computed and expected deposit data roots match - require(node == deposit_data_root); + require(node == deposit_data_root, "DepositContract: reconstructed DepositData does not match supplied deposit_data_root"); // Add deposit data root to Merkle tree (update a single `branch` node) deposit_count += 1; From 0b50a3e1f5b413ecc749671de77fe7c3d105e9e0 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 14 May 2020 11:46:54 +0100 Subject: [PATCH 20/69] Use "literal metadata sources" setting (#21) --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index af166fe4d..7de2d6d6b 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ clean: @rm -f DepositContract.abi DepositContract.bin IDepositContract.abi IDepositContract.bin deposit_contract.json compile: clean - @solc --bin --abi --overwrite -o . deposit_contract.sol + @solc --metadata-literal --bin --abi --overwrite -o . deposit_contract.sol @echo -n '{"abi": ' > deposit_contract.json @cat DepositContract.abi >> deposit_contract.json @echo -n ', "bytecode": "0x' >> deposit_contract.json From 2b6c17604395e0634211152aede5356adbdad643 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 14 May 2020 12:19:03 +0100 Subject: [PATCH 21/69] Add ERC-165 support (#4) --- deposit_contract.sol | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index 05509516b..39f7b2ba6 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -24,9 +24,20 @@ interface IDepositContract { function get_deposit_count() external view returns (bytes memory); } +// Based on official specification in https://eips.ethereum.org/EIPS/eip-165 +interface ERC165 { + /// @notice Query if a contract implements an interface + /// @param interfaceId The interface identifier, as specified in ERC-165 + /// @dev Interface identification is specified in ERC-165. This function + /// uses less than 30,000 gas. + /// @return `true` if the contract implements `interfaceId` and + /// `interfaceId` is not 0xffffffff, `false` otherwise + function supportsInterface(bytes4 interfaceId) external pure returns (bool); +} + // This is a rewrite of the Vyper Eth2.0 deposit contract in Solidity. // It tries to stay as close as possible to the original source code. -contract DepositContract is IDepositContract { +contract DepositContract is IDepositContract, ERC165 { uint constant GWEI = 1e9; uint constant MIN_DEPOSIT_AMOUNT = 1 ether; @@ -128,6 +139,10 @@ contract DepositContract is IDepositContract { assert(false); } + function supportsInterface(bytes4 interfaceId) override external pure returns (bool) { + return interfaceId == type(ERC165).interfaceId || interfaceId == type(IDepositContract).interfaceId; + } + function to_little_endian_64(uint64 value) internal pure returns (bytes memory ret) { // Unrolled the loop here. ret = new bytes(8); From bc9b7ccfd3a318a1db9bc406ca6c174348065851 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 14 May 2020 20:36:54 +0100 Subject: [PATCH 22/69] Add test job for running eth2.0-specs tests (#25) Also use python:3.8.1 docker image. --- circle.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index dfcae7743..d4b631593 100644 --- a/circle.yml +++ b/circle.yml @@ -2,7 +2,7 @@ version: 2.0 jobs: build: docker: - - image: cimg/base:2020.01 + - image: cimg/python:3.8.1 steps: - checkout - run: @@ -14,3 +14,12 @@ jobs: - run: name: Compile the contract command: make + - run: + name: Run eth2.0-specs tests + command: | + sudo apt-get install -y python3-venv + git clone https://github.com/ethereum/eth2.0-specs + cp -f deposit_contract.json eth2.0-specs/deposit_contract/contracts/validator_registration.json + cd eth2.0-specs + make install_deposit_contract_tester + make test_deposit_contract From 6c07707f1de1eeaf02e8ff31df17bd761789c033 Mon Sep 17 00:00:00 2001 From: MrChico Date: Thu, 14 May 2020 21:58:48 +0200 Subject: [PATCH 23/69] Add unit test and fuzzing against Vyper (#20) --- .gitmodules | 3 + Makefile | 15 +++- README.md | 8 ++ circle.yml | 30 ++++++++ lib/ds-test | 1 + shell.nix | 18 +++++ tests/deposit_contract.t.sol | 142 +++++++++++++++++++++++++++++++++++ tests/vyper_setup.sol | 16 ++++ 8 files changed, 232 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 160000 lib/ds-test create mode 100644 shell.nix create mode 100644 tests/deposit_contract.t.sol create mode 100644 tests/vyper_setup.sol diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..e12471968 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/ds-test"] + path = lib/ds-test + url = https://github.com/dapphub/ds-test diff --git a/Makefile b/Makefile index 7de2d6d6b..3615a47cd 100644 --- a/Makefile +++ b/Makefile @@ -2,11 +2,24 @@ all: compile clean: @rm -f DepositContract.abi DepositContract.bin IDepositContract.abi IDepositContract.bin deposit_contract.json + @rm -f DepositContractTest.abi DepositContractTest.bin + @rm -f VyperSetup.abi VyperSetup.bin + @rm -f DSTest.abi DSTest.bin + @rm -rf combined.json compile: clean - @solc --metadata-literal --bin --abi --overwrite -o . deposit_contract.sol + @git submodule update --recursive --init + @solc --metadata-literal --bin --abi --combined-json=abi,bin,bin-runtime,srcmap,srcmap-runtime,ast,metadata,storage-layout --overwrite -o . deposit_contract.sol tests/deposit_contract.t.sol @echo -n '{"abi": ' > deposit_contract.json @cat DepositContract.abi >> deposit_contract.json @echo -n ', "bytecode": "0x' >> deposit_contract.json @cat DepositContract.bin >> deposit_contract.json @echo -n '"}' >> deposit_contract.json + + +export DAPP_SKIP_BUILD:=1 +export DAPP_SRC:=. +export DAPP_JSON:=combined.json + +test: + dapp test -v --fuzz-runs 5 diff --git a/README.md b/README.md index f34864759..f596b5a11 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,11 @@ The motivation is to run the SMTChecker and the new Yul IR generator option (`-- 5. Finally in the `eth2.0-specs` directory run `make test_deposit_contract` to execute the tests The Makefile currently compiles the code without optimisations. To enable optimisations add `--optimize` to the `solc` line. + + +## Running randomized `dapp` tests: + +Install the latest version of `dapp` by following the instructions at [dapp.tools](https://dapp.tools/). Then run +```sh +make test +``` diff --git a/circle.yml b/circle.yml index d4b631593..9f72b396c 100644 --- a/circle.yml +++ b/circle.yml @@ -1,4 +1,5 @@ version: 2.0 + jobs: build: docker: @@ -23,3 +24,32 @@ jobs: cd eth2.0-specs make install_deposit_contract_tester make test_deposit_contract + - persist_to_workspace: + root: . + paths: + - combined.json + - lib + + test: + docker: + - image: nixorg/nix:circleci + steps: + - checkout + - attach_workspace: + at: /tmp/ + - run: + name: Test the contract + command: | + cp /tmp/combined.json . + cp -r /tmp/lib/* lib + nix-shell --command 'make test' + +workflows: + version: 2 + + build_and_test: + jobs: + - build + - test: + requires: + - build diff --git a/lib/ds-test b/lib/ds-test new file mode 160000 index 000000000..eb7148d43 --- /dev/null +++ b/lib/ds-test @@ -0,0 +1 @@ +Subproject commit eb7148d43c1ca6f9890361e2e2378364af2430ba diff --git a/shell.nix b/shell.nix new file mode 100644 index 000000000..d0727d49a --- /dev/null +++ b/shell.nix @@ -0,0 +1,18 @@ +let dapptools = builtins.fetchGit { + url = "https://github.com/dapphub/dapptools.git"; + rev = "11dcefe1f03b0acafe76b4d7d54821ef6bd63131"; + }; + nixpkgs = builtins.fetchGit { + url = "https://github.com/nixos/nixpkgs"; + ref = "release-19.03"; + rev = "f1707d8875276cfa110139435a7e8998b4c2a4fd"; + }; + pkgs-for-dapp = import nixpkgs { + overlays = [ + (import (dapptools + /overlay.nix)) + ]; + }; +in +pkgs-for-dapp.mkShell { + buildInputs = [ pkgs-for-dapp.dapp pkgs-for-dapp.solc pkgs-for-dapp.hevm ]; +} diff --git a/tests/deposit_contract.t.sol b/tests/deposit_contract.t.sol new file mode 100644 index 000000000..e3a5124b6 --- /dev/null +++ b/tests/deposit_contract.t.sol @@ -0,0 +1,142 @@ +pragma solidity ^0.6.0; + +import "../lib/ds-test/src/test.sol"; + +import "./vyper_setup.sol"; +import "../deposit_contract.sol"; + +contract DepositContractTest is DSTest { + DepositContract depositContract_sol; + DepositContract depositContract_vyp; + uint64 constant GWEI = 1000000000; + + function setUp() public { + VyperSetup vyperSetup = new VyperSetup(); + depositContract_vyp = DepositContract(vyperSetup.deployDeposit()); + depositContract_sol = new DepositContract(); + } + + // --- SUCCESS TESTS --- + + // Tests initilized storage values, comparing vyper and solidity + function test_empty_root() public { + bytes32 zHash = 0x0000000000000000000000000000000000000000000000000000000000000000; + bytes32 zHashN = zHash; + for (uint i = 0; i <= 31; i++) { + zHashN = sha256(abi.encodePacked(zHashN, zHashN)); + } + assertEq(sha256(abi.encodePacked(zHashN, zHash)), depositContract_vyp.get_deposit_root()); + assertEq(depositContract_sol.get_deposit_root(), depositContract_vyp.get_deposit_root()); + } + + // Generates 16 random deposits, insert them in both vyper and solidity version and compare get_deposit_root after each insertion + function test_16_deposits(bytes32[16] memory pubkey_one, bytes16[16] memory pubkey_two, bytes32[16] memory _withdrawal_credentials, + bytes32[16] memory sig_one, bytes32[16] memory sig_two, bytes32[16] memory sig_three, uint32[16] memory amount) public { + uint j; + for (uint i = 0; i < 16; i++) { + // as of dcaa774, the solidity version is more restrictive than vyper and requires deposits to be divisible by GWEI + uint64 gweiamount = amount[i] * GWEI; + if (1 ether <= gweiamount) { + j++; + deposit_in(depositContract_sol, pubkey_one[i], pubkey_two[i], _withdrawal_credentials[i], sig_one[i], sig_two[i], sig_three[i], gweiamount); + deposit_in(depositContract_vyp, pubkey_one[i], pubkey_two[i], _withdrawal_credentials[i], sig_one[i], sig_two[i], sig_three[i], gweiamount); + + assertEq(depositContract_sol.get_deposit_root(), depositContract_vyp.get_deposit_root()); + assertEq(keccak256(abi.encodePacked(depositContract_sol.get_deposit_count())), keccak256(abi.encodePacked(depositContract_vyp.get_deposit_count()))); + assertEq(keccak256(abi.encodePacked(depositContract_sol.get_deposit_count())), keccak256(to_little_endian_64(uint64(j)))); + } + } + } + + // The solidity contract fails when given a deposit which is not divisible by GWEI + + function testFail_deposit_not_divisible_by_gwei(bytes32 pubkey_one, bytes16 pubkey_two, bytes32 _withdrawal_credentials, + bytes32 sig_one, bytes32 sig_two, bytes32 sig_three) public { + deposit_in(depositContract_sol, pubkey_one, pubkey_two, _withdrawal_credentials, sig_one, sig_two, sig_three, 1 ether + 1); + } + + // --- FAILURE TESTS --- + + // if the node is given randomly instead of as the ssz root, the chances of success are so unlikely that we can assert it to be false + function testFail_malformed_node_vyp(bytes32 pubkey_one, bytes16 pubkey_two, bytes32 _withdrawal_credentials, bytes32 sig_one, + bytes32 sig_two, bytes32 sig_three, uint64 amount, bytes32 node) public { + bytes memory pubkey = abi.encodePacked(pubkey_one, pubkey_two); + bytes memory withdrawal_credentials = abi.encodePacked(_withdrawal_credentials); //I wish just recasting to `bytes` would work.. + bytes memory signature = abi.encodePacked(sig_one, sig_two, sig_three); + depositContract_vyp.deposit.value(amount)(pubkey, withdrawal_credentials, signature, node); + } + + // If the node is taken randomly instead of as the ssz root, the chances of success are so unlikely that we can assert it to be false + function testFail_malformed_node_sol(bytes32 pubkey_one, bytes16 pubkey_two, bytes32 _withdrawal_credentials, bytes32 sig_one, + bytes32 sig_two, bytes32 sig_three, uint64 amount, bytes32 node) public { + bytes memory pubkey = abi.encodePacked(pubkey_one, pubkey_two); + bytes memory withdrawal_credentials = abi.encodePacked(_withdrawal_credentials); + bytes memory signature = abi.encodePacked(sig_one, sig_two, sig_three); + depositContract_sol.deposit.value(amount)(pubkey, withdrawal_credentials, signature, node); + } + + // if bytes lengths are wrong, the call will fail + function testFail_malformed_calldata_vyp(bytes memory pubkey, bytes memory withdrawal_credentials, bytes memory signature, uint64 amount) public { + if (amount >= 1000000000000000000) { + if (!(pubkey.length == 48 && withdrawal_credentials.length == 32 && signature.length == 96)) { + depositContract_vyp.deposit.value(amount)(pubkey, withdrawal_credentials, signature, + encode_node(pubkey, withdrawal_credentials, signature, to_little_endian_64(amount / GWEI)) + ); + } else { revert(); } + } else { revert(); } + } + + function testFail_malformed_calldata_sol(bytes memory pubkey, bytes memory withdrawal_credentials, bytes memory signature, uint64 amount) public { + if (amount >= 1000000000000000000) { + if (!(pubkey.length == 48 && withdrawal_credentials.length == 32 && signature.length == 96)) { + depositContract_sol.deposit.value(amount)(pubkey, withdrawal_credentials, signature, + encode_node(pubkey, withdrawal_credentials, signature, to_little_endian_64(amount / GWEI)) + ); + } else { revert(); } + } else { revert(); } + } + + // --- HELPER FUNCTIONS --- + + function deposit_in(DepositContract depositContract, bytes32 pubkey_one, bytes16 pubkey_two, bytes32 _withdrawal_credentials, bytes32 sig_one, bytes32 sig_two, bytes32 sig_three, uint64 amount) public { + bytes memory pubkey = abi.encodePacked(pubkey_one, pubkey_two); + bytes memory withdrawal_credentials = abi.encodePacked(_withdrawal_credentials); + bytes memory signature = abi.encodePacked(sig_one, sig_two, sig_three); + bytes32 node = encode_node(pubkey, withdrawal_credentials, signature, to_little_endian_64(amount / GWEI)); + depositContract.deposit.value(amount)(pubkey, withdrawal_credentials, signature, node); + } + + function slice(bytes memory a, uint32 offset, uint32 size) pure internal returns (bytes memory result) { + result = new bytes(size); + for (uint i = 0; i < size; i++) { + result[i] = a[offset+i]; + } + } + + function encode_node(bytes memory pubkey, bytes memory withdrawal_credentials, bytes memory signature, bytes memory amount) public pure returns (bytes32) { + bytes16 zero_bytes16; + bytes24 zero_bytes24; + bytes32 zero_bytes32; + bytes32 pubkey_root = sha256(abi.encodePacked(pubkey, zero_bytes16)); + bytes32 signature_root = sha256(abi.encodePacked( + sha256(abi.encodePacked(slice(signature, 0, 64))), + sha256(abi.encodePacked(slice(signature, 64, 32), zero_bytes32)) + )); + return sha256(abi.encodePacked( + sha256(abi.encodePacked(pubkey_root, withdrawal_credentials)), + sha256(abi.encodePacked(amount, zero_bytes24, signature_root)) + )); + } + + function to_little_endian_64(uint64 value) internal pure returns (bytes memory ret) { + ret = new bytes(8); + ret[0] = bytes1(uint8(value & 0xff)); + ret[1] = bytes1(uint8((value >> 8) & 0xff)); + ret[2] = bytes1(uint8((value >> 16) & 0xff)); + ret[3] = bytes1(uint8((value >> 24) & 0xff)); + ret[4] = bytes1(uint8((value >> 32) & 0xff)); + ret[5] = bytes1(uint8((value >> 40) & 0xff)); + ret[6] = bytes1(uint8((value >> 48) & 0xff)); + ret[7] = bytes1(uint8((value >> 56) & 0xff)); + } +} diff --git a/tests/vyper_setup.sol b/tests/vyper_setup.sol new file mode 100644 index 000000000..8d82c754d --- /dev/null +++ b/tests/vyper_setup.sol @@ -0,0 +1,16 @@ +pragma solidity ^0.6.0; + +contract VyperSetup { + // Bytecode from https://github.com/ethereum/eth2.0-specs/blob/dev/deposit_contract/contracts/validator_registration.json + bytes constant public depositCode = hex"740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009857600080fd5b6101406000601f818352015b600061014051602081106100b757600080fd5b600260c052602060c020015460208261016001015260208101905061014051602081106100e357600080fd5b600260c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012157600080fd5b60c0519050606051600161014051018060405190131561014057600080fd5b809190121561014e57600080fd5b6020811061015b57600080fd5b600260c052602060c02001555b81516001018083528114156100a4575b505061123556600436101561000d576110b0565b600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a05260001561027f575b6101605261014052600061018052610140516101a0526101c060006008818352015b61018051600860008112156100e8578060000360020a82046100ef565b8060020a82025b905090506101805260ff6101a051166101e052610180516101e0516101805101101561011a57600080fd5b6101e0516101805101610180526101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff86000811215610163578060000360020a820461016a565b8060020a82025b905090506101a0525b81516001018083528114156100cb575b5050601860086020820661020001602082840111156101a157600080fd5b60208061022082610180600060045af15050818152809050905090508051602001806102c08284600060045af16101d757600080fd5b50506102c05160206001820306601f82010390506103206102c0516020818352015b826103205110151561020a57610226565b6000610320516102e001535b81516001018083528114156101f9575b50505060206102a05260406102c0510160206001820306601f8201039050610280525b60006102805111151561025b57610277565b602061028051036102a001516020610280510361028052610249565b610160515650005b63c5f2892f600051141561050e57341561029857600080fd5b6000610140526101405161016052600154610180526101a060006020818352015b600160016101805116141561033a5760006101a051602081106102db57600080fd5b600060c052602060c02001546020826102400101526020810190506101605160208261024001015260208101905080610240526102409050602060c0825160208401600060025af161032c57600080fd5b60c0519050610160526103a8565b6000610160516020826101c00101526020810190506101a0516020811061036057600080fd5b600260c052602060c02001546020826101c0010152602081019050806101c0526101c09050602060c0825160208401600060025af161039e57600080fd5b60c0519050610160525b61018060026103b657600080fd5b60028151048152505b81516001018083528114156102b9575b505060006101605160208261046001015260208101905061014051610160516101805163806732896102e0526001546103005261030051600658016100a9565b506103605260006103c0525b6103605160206001820306601f82010390506103c05110151561043d57610456565b6103c05161038001526103c0516020016103c05261041b565b61018052610160526101405261036060088060208461046001018260208501600060045af150508051820191505060006018602082066103e001602082840111156104a057600080fd5b60208061040082610140600060045af150508181528090509050905060188060208461046001018260208501600060045af150508051820191505080610460526104609050602060c0825160208401600060025af16104fe57600080fd5b60c051905060005260206000f350005b63621fd130600051141561061c57341561052757600080fd5b6380673289610140526001546101605261016051600658016100a9565b506101c0526000610220525b6101c05160206001820306601f8201039050610220511015156105725761058b565b610220516101e001526102205160200161022052610550565b6101c08051602001806102808284600060045af16105a857600080fd5b50506102805160206001820306601f82010390506102e0610280516020818352015b826102e0511015156105db576105f7565b60006102e0516102a001535b81516001018083528114156105ca575b5050506020610260526040610280510160206001820306601f8201039050610260f350005b632289511860005114156110af57605060043560040161014037603060043560040135111561064a57600080fd5b60406024356004016101c037602060243560040135111561066a57600080fd5b608060443560040161022037606060443560040135111561068a57600080fd5b63ffffffff6001541061069c57600080fd5b633b9aca006102e0526102e0516106b257600080fd5b6102e05134046102c052633b9aca006102c05110156106d057600080fd5b603061014051146106e057600080fd5b60206101c051146106f057600080fd5b6060610220511461070057600080fd5b610140610360525b6103605151602061036051016103605261036061036051101561072a57610708565b6380673289610380526102c0516103a0526103a051600658016100a9565b50610400526000610460525b6104005160206001820306601f8201039050610460511015156107765761078f565b6104605161042001526104605160200161046052610754565b610340610360525b61036051526020610360510361036052610140610360511015156107ba57610797565b6104008051602001806103008284600060045af16107d757600080fd5b5050610140610480525b61048051516020610480510161048052610480610480511015610803576107e1565b63806732896104a0526001546104c0526104c051600658016100a9565b50610520526000610580525b6105205160206001820306601f82010390506105805110151561084e57610867565b610580516105400152610580516020016105805261082c565b610460610480525b61048051526020610480510361048052610140610480511015156108925761086f565b6105208051602001806105a08284600060045af16108af57600080fd5b505060a061062052610620516106605261014080516020018061062051610660018284600060045af16108e157600080fd5b505061062051610660015160206001820306601f82010390506106006106205161066001516040818352015b826106005110151561091e5761093f565b600061060051610620516106800101535b815160010180835281141561090d575b505050602061062051610660015160206001820306601f82010390506106205101016106205261062051610680526101c080516020018061062051610660018284600060045af161098f57600080fd5b505061062051610660015160206001820306601f82010390506106006106205161066001516020818352015b82610600511015156109cc576109ed565b600061060051610620516106800101535b81516001018083528114156109bb575b505050602061062051610660015160206001820306601f820103905061062051010161062052610620516106a05261030080516020018061062051610660018284600060045af1610a3d57600080fd5b505061062051610660015160206001820306601f82010390506106006106205161066001516020818352015b8261060051101515610a7a57610a9b565b600061060051610620516106800101535b8151600101808352811415610a69575b505050602061062051610660015160206001820306601f820103905061062051010161062052610620516106c05261022080516020018061062051610660018284600060045af1610aeb57600080fd5b505061062051610660015160206001820306601f82010390506106006106205161066001516060818352015b8261060051101515610b2857610b49565b600061060051610620516106800101535b8151600101808352811415610b17575b505050602061062051610660015160206001820306601f820103905061062051010161062052610620516106e0526105a080516020018061062051610660018284600060045af1610b9957600080fd5b505061062051610660015160206001820306601f82010390506106006106205161066001516020818352015b8261060051101515610bd657610bf7565b600061060051610620516106800101535b8151600101808352811415610bc5575b505050602061062051610660015160206001820306601f8201039050610620510101610620527f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c561062051610660a160006107005260006101406030806020846107c001018260208501600060045af150508051820191505060006010602082066107400160208284011115610c8c57600080fd5b60208061076082610700600060045af15050818152809050905090506010806020846107c001018260208501600060045af1505080518201915050806107c0526107c09050602060c0825160208401600060025af1610cea57600080fd5b60c0519050610720526000600060406020820661086001610220518284011115610d1357600080fd5b6060806108808260206020880688030161022001600060045af1505081815280905090509050602060c0825160208401600060025af1610d5257600080fd5b60c0519050602082610a600101526020810190506000604060206020820661092001610220518284011115610d8657600080fd5b6060806109408260206020880688030161022001600060045af15050818152809050905090506020806020846109e001018260208501600060045af1505080518201915050610700516020826109e0010152602081019050806109e0526109e09050602060c0825160208401600060025af1610e0157600080fd5b60c0519050602082610a6001015260208101905080610a6052610a609050602060c0825160208401600060025af1610e3857600080fd5b60c0519050610840526000600061072051602082610b000101526020810190506101c0602080602084610b0001018260208501600060045af150508051820191505080610b0052610b009050602060c0825160208401600060025af1610e9d57600080fd5b60c0519050602082610c800101526020810190506000610300600880602084610c0001018260208501600060045af15050805182019150506000601860208206610b800160208284011115610ef157600080fd5b602080610ba082610700600060045af1505081815280905090509050601880602084610c0001018260208501600060045af150508051820191505061084051602082610c0001015260208101905080610c0052610c009050602060c0825160208401600060025af1610f6257600080fd5b60c0519050602082610c8001015260208101905080610c8052610c809050602060c0825160208401600060025af1610f9957600080fd5b60c0519050610ae052606435610ae05114610fb357600080fd5b6001805460018254011015610fc757600080fd5b6001815401815550600154610d0052610d2060006020818352015b60016001610d005116141561101757610ae051610d20516020811061100657600080fd5b600060c052602060c02001556110ab565b6000610d20516020811061102a57600080fd5b600060c052602060c0200154602082610d40010152602081019050610ae051602082610d4001015260208101905080610d4052610d409050602060c0825160208401600060025af161107b57600080fd5b60c0519050610ae052610d00600261109257600080fd5b60028151048152505b8151600101808352811415610fe2575b5050005b5b60006000fd5b61017f6112350361017f60003961017f611235036000f3"; + function write(bytes memory _code) public returns (address target) { + assembly { + target := create(0, add(_code, 0x20), mload(_code)) + } + } + + function deployDeposit() public returns (address) { + return write(depositCode); + } +} + From 5e783240302b2283144a1fca768bfb9d5214e0fb Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 15 May 2020 11:22:20 +0100 Subject: [PATCH 24/69] Split CircleCI jobs (#26) --- circle.yml | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/circle.yml b/circle.yml index 9f72b396c..254cdae89 100644 --- a/circle.yml +++ b/circle.yml @@ -1,9 +1,9 @@ -version: 2.0 +version: 2.1 jobs: build: docker: - - image: cimg/python:3.8.1 + - image: cimg/base:2020.01 steps: - checkout - run: @@ -15,21 +15,38 @@ jobs: - run: name: Compile the contract command: make - - run: - name: Run eth2.0-specs tests - command: | - sudo apt-get install -y python3-venv - git clone https://github.com/ethereum/eth2.0-specs - cp -f deposit_contract.json eth2.0-specs/deposit_contract/contracts/validator_registration.json - cd eth2.0-specs - make install_deposit_contract_tester - make test_deposit_contract - persist_to_workspace: root: . paths: + - deposit_contract.json - combined.json - lib + spectest: + docker: + - image: cimg/python:3.8.1 + steps: + - checkout + - attach_workspace: + at: /tmp/ + - run: + name: Update python3 + command: | + sudo apt-get update + sudo apt-get install -y python3-venv + - run: + name: Install eth2.0-specs tests + command: | + git clone https://github.com/ethereum/eth2.0-specs + cp -f /tmp/deposit_contract.json eth2.0-specs/deposit_contract/contracts/validator_registration.json + cd eth2.0-specs + make install_deposit_contract_tester + - run: + name: Run eth2.0-specs tests + command: | + cd eth2.0-specs + make test_deposit_contract + test: docker: - image: nixorg/nix:circleci @@ -50,6 +67,9 @@ workflows: build_and_test: jobs: - build - - test: + - spectest: requires: - build + - test: + requires: + - spectest From 62e328141100f08af6683a6d5af5dee2f459aea2 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 15 May 2020 11:48:00 +0100 Subject: [PATCH 25/69] Lock in Solidity 0.6.8 on CircleCI (#27) * Fix Makefile on macOS * Lock circleci to solc:0.6.8-alpine * Lock version to 0.6.8 --- Makefile | 7 ++++--- circle.yml | 9 ++++----- deposit_contract.sol | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 3615a47cd..a5a2879d6 100644 --- a/Makefile +++ b/Makefile @@ -8,13 +8,14 @@ clean: @rm -rf combined.json compile: clean + @# Note: using /bin/echo for macOS @git submodule update --recursive --init @solc --metadata-literal --bin --abi --combined-json=abi,bin,bin-runtime,srcmap,srcmap-runtime,ast,metadata,storage-layout --overwrite -o . deposit_contract.sol tests/deposit_contract.t.sol - @echo -n '{"abi": ' > deposit_contract.json + @/bin/echo -n '{"abi": ' > deposit_contract.json @cat DepositContract.abi >> deposit_contract.json - @echo -n ', "bytecode": "0x' >> deposit_contract.json + @/bin/echo -n ', "bytecode": "0x' >> deposit_contract.json @cat DepositContract.bin >> deposit_contract.json - @echo -n '"}' >> deposit_contract.json + @/bin/echo -n '"}' >> deposit_contract.json export DAPP_SKIP_BUILD:=1 diff --git a/circle.yml b/circle.yml index 254cdae89..70679e01e 100644 --- a/circle.yml +++ b/circle.yml @@ -3,15 +3,14 @@ version: 2.1 jobs: build: docker: - - image: cimg/base:2020.01 + - image: ethereum/solc:0.6.8-alpine steps: - checkout - run: - name: Install solidity + name: Install build essentials command: | - sudo add-apt-repository ppa:ethereum/ethereum - sudo apt-get update - sudo apt-get install solc + apk update + apk add git make - run: name: Compile the contract command: make diff --git a/deposit_contract.sol b/deposit_contract.sol index 39f7b2ba6..e6c215180 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -1,6 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.6.0; +pragma solidity 0.6.8; // This interface is designed to be compatible with the Vyper version. interface IDepositContract { From 69d0e8069dbce6ae6f50b88a127a144902b356f0 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 15 May 2020 13:13:31 +0100 Subject: [PATCH 26/69] Enable optimizer and set to 5m runs (#28) The `deposit` function can be used up to 2^32-1 times anyway. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a5a2879d6..739396aba 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ clean: compile: clean @# Note: using /bin/echo for macOS @git submodule update --recursive --init - @solc --metadata-literal --bin --abi --combined-json=abi,bin,bin-runtime,srcmap,srcmap-runtime,ast,metadata,storage-layout --overwrite -o . deposit_contract.sol tests/deposit_contract.t.sol + @solc --metadata-literal --optimize --optimize-runs 5000000 --bin --abi --combined-json=abi,bin,bin-runtime,srcmap,srcmap-runtime,ast,metadata,storage-layout --overwrite -o . deposit_contract.sol tests/deposit_contract.t.sol @/bin/echo -n '{"abi": ' > deposit_contract.json @cat DepositContract.abi >> deposit_contract.json @/bin/echo -n ', "bytecode": "0x' >> deposit_contract.json From 15bcfbaf913551b035408f7bba69b17e100ad202 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 15 May 2020 13:14:03 +0100 Subject: [PATCH 27/69] Use 0.6.8 features (#22) --- deposit_contract.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index e6c215180..efc66ed16 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -98,7 +98,7 @@ contract DepositContract is IDepositContract, ERC165 { require(msg.value >= MIN_DEPOSIT_AMOUNT, "DepositContract: deposit value too low"); require(msg.value % GWEI == 0, "DepositContract: deposit value not multiple of gwei"); uint deposit_amount = msg.value / GWEI; - require(deposit_amount < 2**64, "DepositContract: deposit value too high"); + require(deposit_amount <= type(uint64).max, "DepositContract: deposit value too high"); // Emit `DepositEvent` log bytes memory amount = to_little_endian_64(uint64(deposit_amount)); @@ -113,8 +113,8 @@ contract DepositContract is IDepositContract, ERC165 { // Compute deposit data root (`DepositData` hash tree root) bytes32 pubkey_root = sha256(abi.encodePacked(pubkey, bytes16(0))); bytes32 signature_root = sha256(abi.encodePacked( - sha256(abi.encodePacked(bytes(signature[:64]))), - sha256(abi.encodePacked(bytes(signature[64:]), bytes32(0))) + sha256(abi.encodePacked(signature[:64])), + sha256(abi.encodePacked(signature[64:], bytes32(0))) )); bytes32 node = sha256(abi.encodePacked( sha256(abi.encodePacked(pubkey_root, withdrawal_credentials)), From 636f22f0ac4e74415c169defef0737c85d51b4b0 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 15 May 2020 13:14:39 +0100 Subject: [PATCH 28/69] Move require(deposit_count) statement to where the value is used (post hash calculation) (#23) This tightly couples all require statements to their places of use. --- deposit_contract.sol | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index efc66ed16..8983c76cc 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -91,9 +91,6 @@ contract DepositContract is IDepositContract, ERC165 { require(withdrawal_credentials.length == WITHDRAWAL_CREDENTIALS_LENGTH, "DepositContract: invalid withdrawal_credentials length"); require(signature.length == SIGNATURE_LENGTH, "DepositContract: invalid signature length"); - // Avoid overflowing the Merkle tree (and prevent edge case in computing `branch`) - require(deposit_count < MAX_DEPOSIT_COUNT, "DepositContract: merkle tree full"); - // Check deposit amount require(msg.value >= MIN_DEPOSIT_AMOUNT, "DepositContract: deposit value too low"); require(msg.value % GWEI == 0, "DepositContract: deposit value not multiple of gwei"); @@ -120,9 +117,13 @@ contract DepositContract is IDepositContract, ERC165 { sha256(abi.encodePacked(pubkey_root, withdrawal_credentials)), sha256(abi.encodePacked(amount, bytes24(0), signature_root)) )); + // Verify computed and expected deposit data roots match require(node == deposit_data_root, "DepositContract: reconstructed DepositData does not match supplied deposit_data_root"); + // Avoid overflowing the Merkle tree (and prevent edge case in computing `branch`) + require(deposit_count < MAX_DEPOSIT_COUNT, "DepositContract: merkle tree full"); + // Add deposit data root to Merkle tree (update a single `branch` node) deposit_count += 1; uint size = deposit_count; From d1a5556a74116ac782ade06c975bba78b151f9c8 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 15 May 2020 13:17:14 +0100 Subject: [PATCH 29/69] Compare against eth2.0-specs v0.11.2 (#30) --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 70679e01e..b86a89aa2 100644 --- a/circle.yml +++ b/circle.yml @@ -36,7 +36,7 @@ jobs: - run: name: Install eth2.0-specs tests command: | - git clone https://github.com/ethereum/eth2.0-specs + git clone https://github.com/ethereum/eth2.0-specs --single-branch --branch v0.11.2 cp -f /tmp/deposit_contract.json eth2.0-specs/deposit_contract/contracts/validator_registration.json cd eth2.0-specs make install_deposit_contract_tester From 8f2c64485e72e2b0a07e0a34bfdd17390b5342a4 Mon Sep 17 00:00:00 2001 From: MrChico Date: Fri, 15 May 2020 18:46:38 +0200 Subject: [PATCH 30/69] Use less constants and fold the expressions into require statements (#24) --- README.md | 2 +- deposit_contract.sol | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index f596b5a11..c98b38c56 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ The motivation is to run the SMTChecker and the new Yul IR generator option (`-- ## Using this with the tests -1. Create the `deposit_contract.json` with running `make` (this requires `solc` to be in the path) +1. Create the `deposit_contract.json` by running `make` (this requires `solc` to be in the path) 2. Download [eth2.0-specs](https://github.com/ethereum/eth2.0-specs) 3. Replace `eth2.0-specs/deposit_contract/contracts/validator_registration.json` with `deposit_contract.json` 4. In the `eth2.0-specs` directory run `make install_deposit_contract_tester` to install the tools needed (make sure to have Python 3.7 and pip installed) diff --git a/deposit_contract.sol b/deposit_contract.sol index 8983c76cc..2c2231ffe 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -40,13 +40,9 @@ interface ERC165 { contract DepositContract is IDepositContract, ERC165 { uint constant GWEI = 1e9; - uint constant MIN_DEPOSIT_AMOUNT = 1 ether; uint constant DEPOSIT_CONTRACT_TREE_DEPTH = 32; // NOTE: this also ensures `deposit_count` will fit into 64-bits uint constant MAX_DEPOSIT_COUNT = 2**DEPOSIT_CONTRACT_TREE_DEPTH - 1; - uint constant PUBKEY_LENGTH = 48; // bytes - uint constant WITHDRAWAL_CREDENTIALS_LENGTH = 32; // bytes - uint constant SIGNATURE_LENGTH = 96; // bytes bytes32[DEPOSIT_CONTRACT_TREE_DEPTH] branch; uint256 deposit_count; @@ -87,12 +83,12 @@ contract DepositContract is IDepositContract, ERC165 { bytes32 deposit_data_root ) override external payable { // Extended ABI length checks since dynamic types are used. - require(pubkey.length == PUBKEY_LENGTH, "DepositContract: invalid pubkey length"); - require(withdrawal_credentials.length == WITHDRAWAL_CREDENTIALS_LENGTH, "DepositContract: invalid withdrawal_credentials length"); - require(signature.length == SIGNATURE_LENGTH, "DepositContract: invalid signature length"); + require(pubkey.length == 48, "DepositContract: invalid pubkey length"); + require(withdrawal_credentials.length == 32, "DepositContract: invalid withdrawal_credentials length"); + require(signature.length == 96, "DepositContract: invalid signature length"); // Check deposit amount - require(msg.value >= MIN_DEPOSIT_AMOUNT, "DepositContract: deposit value too low"); + require(msg.value >= 1 ether, "DepositContract: deposit value too low"); require(msg.value % GWEI == 0, "DepositContract: deposit value not multiple of gwei"); uint deposit_amount = msg.value / GWEI; require(deposit_amount <= type(uint64).max, "DepositContract: deposit value too high"); From a2e1e5aef01215325c72640c53934d13caabd5cd Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 15 May 2020 18:47:21 +0200 Subject: [PATCH 31/69] Use bytes8 index access (#19) Co-authored-by: Alex Beregszaszi --- deposit_contract.sol | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index 2c2231ffe..8b0693cc2 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -141,15 +141,16 @@ contract DepositContract is IDepositContract, ERC165 { } function to_little_endian_64(uint64 value) internal pure returns (bytes memory ret) { - // Unrolled the loop here. ret = new bytes(8); - ret[0] = bytes1(uint8(value)); - ret[1] = bytes1(uint8(value >> 8)); - ret[2] = bytes1(uint8(value >> 16)); - ret[3] = bytes1(uint8(value >> 24)); - ret[4] = bytes1(uint8(value >> 32)); - ret[5] = bytes1(uint8(value >> 40)); - ret[6] = bytes1(uint8(value >> 48)); - ret[7] = bytes1(uint8(value >> 56)); + bytes8 bytesValue = bytes8(value); + // Byteswapping during copying to bytes. + ret[0] = bytesValue[7]; + ret[1] = bytesValue[6]; + ret[2] = bytesValue[5]; + ret[3] = bytesValue[4]; + ret[4] = bytesValue[3]; + ret[5] = bytesValue[2]; + ret[6] = bytesValue[1]; + ret[7] = bytesValue[0]; } } From 15fcaa0828e68125e60feb89bd585c1ee7cea48a Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 15 May 2020 18:23:58 +0100 Subject: [PATCH 32/69] Introduce build directory for artifacts (#31) --- .gitignore | 1 + Makefile | 18 +++++++----------- circle.yml | 5 +++-- 3 files changed, 11 insertions(+), 13 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..378eac25d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/Makefile b/Makefile index 739396aba..55d672105 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,22 @@ all: compile clean: - @rm -f DepositContract.abi DepositContract.bin IDepositContract.abi IDepositContract.bin deposit_contract.json - @rm -f DepositContractTest.abi DepositContractTest.bin - @rm -f VyperSetup.abi VyperSetup.bin - @rm -f DSTest.abi DSTest.bin - @rm -rf combined.json + @rm -rf build + @rm -f deposit_contract.json +# Note: using /bin/echo for macOS support compile: clean - @# Note: using /bin/echo for macOS @git submodule update --recursive --init - @solc --metadata-literal --optimize --optimize-runs 5000000 --bin --abi --combined-json=abi,bin,bin-runtime,srcmap,srcmap-runtime,ast,metadata,storage-layout --overwrite -o . deposit_contract.sol tests/deposit_contract.t.sol + @solc --metadata-literal --optimize --optimize-runs 5000000 --bin --abi --combined-json=abi,bin,bin-runtime,srcmap,srcmap-runtime,ast,metadata,storage-layout --overwrite -o build deposit_contract.sol tests/deposit_contract.t.sol @/bin/echo -n '{"abi": ' > deposit_contract.json - @cat DepositContract.abi >> deposit_contract.json + @cat build/DepositContract.abi >> deposit_contract.json @/bin/echo -n ', "bytecode": "0x' >> deposit_contract.json - @cat DepositContract.bin >> deposit_contract.json + @cat build/DepositContract.bin >> deposit_contract.json @/bin/echo -n '"}' >> deposit_contract.json - export DAPP_SKIP_BUILD:=1 export DAPP_SRC:=. -export DAPP_JSON:=combined.json +export DAPP_JSON:=build/combined.json test: dapp test -v --fuzz-runs 5 diff --git a/circle.yml b/circle.yml index b86a89aa2..03922e13c 100644 --- a/circle.yml +++ b/circle.yml @@ -18,7 +18,7 @@ jobs: root: . paths: - deposit_contract.json - - combined.json + - build/combined.json - lib spectest: @@ -56,7 +56,8 @@ jobs: - run: name: Test the contract command: | - cp /tmp/combined.json . + mkdir build + cp -r /tmp/build/* build cp -r /tmp/lib/* lib nix-shell --command 'make test' From ebb06dd53f07d66209bd9d59d66012347c774b37 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 15 May 2020 19:25:45 +0100 Subject: [PATCH 33/69] Remove some warnings in tests (#32) --- tests/deposit_contract.t.sol | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/deposit_contract.t.sol b/tests/deposit_contract.t.sol index e3a5124b6..5742bd934 100644 --- a/tests/deposit_contract.t.sol +++ b/tests/deposit_contract.t.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.6.0; +pragma solidity ^0.6.2; import "../lib/ds-test/src/test.sol"; @@ -63,7 +63,7 @@ contract DepositContractTest is DSTest { bytes memory pubkey = abi.encodePacked(pubkey_one, pubkey_two); bytes memory withdrawal_credentials = abi.encodePacked(_withdrawal_credentials); //I wish just recasting to `bytes` would work.. bytes memory signature = abi.encodePacked(sig_one, sig_two, sig_three); - depositContract_vyp.deposit.value(amount)(pubkey, withdrawal_credentials, signature, node); + depositContract_vyp.deposit{value: amount}(pubkey, withdrawal_credentials, signature, node); } // If the node is taken randomly instead of as the ssz root, the chances of success are so unlikely that we can assert it to be false @@ -72,14 +72,14 @@ contract DepositContractTest is DSTest { bytes memory pubkey = abi.encodePacked(pubkey_one, pubkey_two); bytes memory withdrawal_credentials = abi.encodePacked(_withdrawal_credentials); bytes memory signature = abi.encodePacked(sig_one, sig_two, sig_three); - depositContract_sol.deposit.value(amount)(pubkey, withdrawal_credentials, signature, node); + depositContract_sol.deposit{value: amount}(pubkey, withdrawal_credentials, signature, node); } // if bytes lengths are wrong, the call will fail function testFail_malformed_calldata_vyp(bytes memory pubkey, bytes memory withdrawal_credentials, bytes memory signature, uint64 amount) public { if (amount >= 1000000000000000000) { if (!(pubkey.length == 48 && withdrawal_credentials.length == 32 && signature.length == 96)) { - depositContract_vyp.deposit.value(amount)(pubkey, withdrawal_credentials, signature, + depositContract_vyp.deposit{value: amount}(pubkey, withdrawal_credentials, signature, encode_node(pubkey, withdrawal_credentials, signature, to_little_endian_64(amount / GWEI)) ); } else { revert(); } @@ -89,7 +89,7 @@ contract DepositContractTest is DSTest { function testFail_malformed_calldata_sol(bytes memory pubkey, bytes memory withdrawal_credentials, bytes memory signature, uint64 amount) public { if (amount >= 1000000000000000000) { if (!(pubkey.length == 48 && withdrawal_credentials.length == 32 && signature.length == 96)) { - depositContract_sol.deposit.value(amount)(pubkey, withdrawal_credentials, signature, + depositContract_sol.deposit{value: amount}(pubkey, withdrawal_credentials, signature, encode_node(pubkey, withdrawal_credentials, signature, to_little_endian_64(amount / GWEI)) ); } else { revert(); } @@ -103,13 +103,13 @@ contract DepositContractTest is DSTest { bytes memory withdrawal_credentials = abi.encodePacked(_withdrawal_credentials); bytes memory signature = abi.encodePacked(sig_one, sig_two, sig_three); bytes32 node = encode_node(pubkey, withdrawal_credentials, signature, to_little_endian_64(amount / GWEI)); - depositContract.deposit.value(amount)(pubkey, withdrawal_credentials, signature, node); + depositContract.deposit{value: amount}(pubkey, withdrawal_credentials, signature, node); } function slice(bytes memory a, uint32 offset, uint32 size) pure internal returns (bytes memory result) { result = new bytes(size); for (uint i = 0; i < size; i++) { - result[i] = a[offset+i]; + result[i] = a[offset + i]; } } From 9fe3c2f62c8004cd73c3b11cf79bcc35d1d90324 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 15 May 2020 19:26:29 +0100 Subject: [PATCH 34/69] Add authors file (#33) --- AUTHORS | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 AUTHORS diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 000000000..4d06c4c57 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,28 @@ +The contract logic here is based on the deposit contract written in Vyper. + +The original repository (https://github.com/ethereum/deposit_contract) had the following authors: + +@NIC619 +@carver +@hwwhww +@davesque +@ralexstokes +@ChihChengLiang +@nisdas +@djrtwo +@JustinDrake +@vbuterin +@njgheorghita +@CarlBeek + +In eth2.0-specs repository (https://github.com/ethereum/eth2.0-specs), its current location, it had the following additional authors: + +@daejunpark + +And this repository has the following authors: + +@axic +@MrChico +@chriseth + +(All of the above are GitHub usernames in order of they appeared first in the commit history.) From 86dd9d9dcafc76ddcbb5ca900981f7493888ce40 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 15 May 2020 20:48:30 +0100 Subject: [PATCH 35/69] Document the interface using Doxygen/Natspec commands (#3) --- deposit_contract.sol | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/deposit_contract.sol b/deposit_contract.sol index 8b0693cc2..29e9d8a51 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -3,7 +3,10 @@ pragma solidity 0.6.8; // This interface is designed to be compatible with the Vyper version. +/// @notice This is the Ethereum 2.0 deposit contract interface. +/// For more information see the Phase 0 specification under https://github.com/ethereum/eth2.0-specs interface IDepositContract { + /// @notice A processed deposit event. event DepositEvent( bytes pubkey, bytes withdrawal_credentials, @@ -12,6 +15,12 @@ interface IDepositContract { bytes index ); + /// @notice Submit a Phase 0 DepositData object. + /// @param pubkey A BLS12-381 public key. + /// @param withdrawal_credentials Commitment to a public key for withdrawals. + /// @param signature A BLS12-381 signature. + /// @param deposit_data_root The SHA-256 hash of the SSZ-encoded DepositData object. + /// Used as a protection against malformed input. function deposit( bytes calldata pubkey, bytes calldata withdrawal_credentials, @@ -19,8 +28,12 @@ interface IDepositContract { bytes32 deposit_data_root ) external payable; + /// @notice Query the current deposit count. + /// @return The deposit count encoded as a little endian 64-bit number. function get_deposit_root() external view returns (bytes32); + /// @notice Query the current deposit count. + /// @return The deposit count encoded as a little endian 64-bit number. function get_deposit_count() external view returns (bytes memory); } @@ -37,6 +50,8 @@ interface ERC165 { // This is a rewrite of the Vyper Eth2.0 deposit contract in Solidity. // It tries to stay as close as possible to the original source code. +/// @notice This is the Ethereum 2.0 deposit contract interface. +/// For more information see the Phase 0 specification under https://github.com/ethereum/eth2.0-specs contract DepositContract is IDepositContract, ERC165 { uint constant GWEI = 1e9; @@ -55,6 +70,8 @@ contract DepositContract is IDepositContract, ERC165 { zero_hashes[height + 1] = sha256(abi.encodePacked(zero_hashes[height], zero_hashes[height])); } + /// @notice Query the current deposit root hash. + /// @return The deposit root hash. function get_deposit_root() override external view returns (bytes32) { bytes32 node; uint size = deposit_count; @@ -72,10 +89,18 @@ contract DepositContract is IDepositContract, ERC165 { )); } + /// @notice Query the current deposit count. + /// @return The deposit count encoded as a little endian 64-bit number. function get_deposit_count() override external view returns (bytes memory) { return to_little_endian_64(uint64(deposit_count)); } + /// @notice Submit a Phase 0 DepositData object. + /// @param pubkey A BLS12-381 public key. + /// @param withdrawal_credentials Commitment to a public key for withdrawals. + /// @param signature A BLS12-381 signature. + /// @param deposit_data_root The SHA-256 hash of the SSZ-encoded DepositData object. + /// Used as a protection against malformed input. function deposit( bytes calldata pubkey, bytes calldata withdrawal_credentials, From bb9bf826024d827a1dd29f2543bc4456642b3ddd Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 15 May 2020 21:07:17 +0100 Subject: [PATCH 36/69] Fix typo in Natspec (#35) --- deposit_contract.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index 29e9d8a51..4b6b05c0c 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -28,8 +28,8 @@ interface IDepositContract { bytes32 deposit_data_root ) external payable; - /// @notice Query the current deposit count. - /// @return The deposit count encoded as a little endian 64-bit number. + /// @notice Query the current deposit root hash. + /// @return The deposit root hash. function get_deposit_root() external view returns (bytes32); /// @notice Query the current deposit count. From 2ac62c4b173a217bf385f58624c21c86c340e317 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 15 May 2020 22:23:27 +0100 Subject: [PATCH 37/69] Lock in the generated deposit_contract.json and compare it on CircleCI (#29) --- circle.yml | 4 +++- deposit_contract.json | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 deposit_contract.json diff --git a/circle.yml b/circle.yml index 03922e13c..53d0c71b5 100644 --- a/circle.yml +++ b/circle.yml @@ -13,7 +13,9 @@ jobs: apk add git make - run: name: Compile the contract - command: make + command: | + make + git diff --color --exit-code - persist_to_workspace: root: . paths: diff --git a/deposit_contract.json b/deposit_contract.json new file mode 100644 index 000000000..d31a99329 --- /dev/null +++ b/deposit_contract.json @@ -0,0 +1 @@ +{"abi": [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"pubkey","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"withdrawal_credentials","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"amount","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"signature","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"index","type":"bytes"}],"name":"DepositEvent","type":"event"},{"inputs":[{"internalType":"bytes","name":"pubkey","type":"bytes"},{"internalType":"bytes","name":"withdrawal_credentials","type":"bytes"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"bytes32","name":"deposit_data_root","type":"bytes32"}],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"get_deposit_count","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"get_deposit_root","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}], "bytecode": "0x608060405234801561001057600080fd5b5060005b601f8110156101025760026021826020811061002c57fe5b01546021836020811061003b57fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b602083106100925780518252601f199092019160209182019101610073565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa1580156100d1573d6000803e3d6000fd5b5050506040513d60208110156100e657600080fd5b5051602160018301602081106100f857fe5b0155600101610014565b506118d680620001136000396000f3fe60806040526004361061003f5760003560e01c806301ffc9a71461004457806322895118146100a4578063621fd130146101ba578063c5f2892f14610244575b600080fd5b34801561005057600080fd5b506100906004803603602081101561006757600080fd5b50357fffffffff000000000000000000000000000000000000000000000000000000001661026b565b604080519115158252519081900360200190f35b6101b8600480360360808110156100ba57600080fd5b8101906020810181356401000000008111156100d557600080fd5b8201836020820111156100e757600080fd5b8035906020019184600183028401116401000000008311171561010957600080fd5b91939092909160208101903564010000000081111561012757600080fd5b82018360208201111561013957600080fd5b8035906020019184600183028401116401000000008311171561015b57600080fd5b91939092909160208101903564010000000081111561017957600080fd5b82018360208201111561018b57600080fd5b803590602001918460018302840111640100000000831117156101ad57600080fd5b919350915035610304565b005b3480156101c657600080fd5b506101cf6110b5565b6040805160208082528351818301528351919283929083019185019080838360005b838110156102095781810151838201526020016101f1565b50505050905090810190601f1680156102365780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561025057600080fd5b506102596110c7565b60408051918252519081900360200190f35b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f01ffc9a70000000000000000000000000000000000000000000000000000000014806102fe57507fffffffff0000000000000000000000000000000000000000000000000000000082167f8564090700000000000000000000000000000000000000000000000000000000145b92915050565b6030861461035d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806118056026913960400191505060405180910390fd5b602084146103b6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252603681526020018061179c6036913960400191505060405180910390fd5b6060821461040f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260298152602001806118786029913960400191505060405180910390fd5b670de0b6b3a7640000341015610470576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806118526026913960400191505060405180910390fd5b633b9aca003406156104cd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260338152602001806117d26033913960400191505060405180910390fd5b633b9aca00340467ffffffffffffffff811115610535576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602781526020018061182b6027913960400191505060405180910390fd5b6060610540826114ba565b90507f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c589898989858a8a6105756020546114ba565b6040805160a0808252810189905290819060208201908201606083016080840160c085018e8e80828437600083820152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690910187810386528c815260200190508c8c808284376000838201819052601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690920188810386528c5181528c51602091820193918e019250908190849084905b83811015610648578181015183820152602001610630565b50505050905090810190601f1680156106755780820380516001836020036101000a031916815260200191505b5086810383528881526020018989808284376000838201819052601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169092018881038452895181528951602091820193918b019250908190849084905b838110156106ef5781810151838201526020016106d7565b50505050905090810190601f16801561071c5780820380516001836020036101000a031916815260200191505b509d505050505050505050505050505060405180910390a1600060028a8a600060801b604051602001808484808284377fffffffffffffffffffffffffffffffff0000000000000000000000000000000090941691909301908152604080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0818403018152601090920190819052815191955093508392506020850191508083835b602083106107fc57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016107bf565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610859573d6000803e3d6000fd5b5050506040513d602081101561086e57600080fd5b5051905060006002806108846040848a8c6116fe565b6040516020018083838082843780830192505050925050506040516020818303038152906040526040518082805190602001908083835b602083106108f857805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016108bb565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610955573d6000803e3d6000fd5b5050506040513d602081101561096a57600080fd5b5051600261097b896040818d6116fe565b60405160009060200180848480828437919091019283525050604080518083038152602092830191829052805190945090925082918401908083835b602083106109f457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016109b7565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610a51573d6000803e3d6000fd5b5050506040513d6020811015610a6657600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610ada57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610a9d565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610b37573d6000803e3d6000fd5b5050506040513d6020811015610b4c57600080fd5b50516040805160208101858152929350600092600292839287928f928f92018383808284378083019250505093505050506040516020818303038152906040526040518082805190602001908083835b60208310610bd957805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610b9c565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610c36573d6000803e3d6000fd5b5050506040513d6020811015610c4b57600080fd5b50516040518651600291889160009188916020918201918291908601908083835b60208310610ca957805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610c6c565b6001836020036101000a0380198251168184511680821785525050505050509050018367ffffffffffffffff191667ffffffffffffffff1916815260180182815260200193505050506040516020818303038152906040526040518082805190602001908083835b60208310610d4e57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610d11565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610dab573d6000803e3d6000fd5b5050506040513d6020811015610dc057600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610e3457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610df7565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610e91573d6000803e3d6000fd5b5050506040513d6020811015610ea657600080fd5b50519050858114610f02576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260548152602001806117486054913960600191505060405180910390fd5b60205463ffffffff11610f60576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806117276021913960400191505060405180910390fd5b602080546001019081905560005b60208110156110a9578160011660011415610fa0578260008260208110610f9157fe5b0155506110ac95505050505050565b600260008260208110610faf57fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061102557805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610fe8565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015611082573d6000803e3d6000fd5b5050506040513d602081101561109757600080fd5b50519250600282049150600101610f6e565b50fe5b50505050505050565b60606110c26020546114ba565b905090565b6020546000908190815b60208110156112f05781600116600114156111e6576002600082602081106110f557fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061116b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161112e565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa1580156111c8573d6000803e3d6000fd5b5050506040513d60208110156111dd57600080fd5b505192506112e2565b600283602183602081106111f657fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061126b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161122e565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa1580156112c8573d6000803e3d6000fd5b5050506040513d60208110156112dd57600080fd5b505192505b6002820491506001016110d1565b506002826112ff6020546114ba565b600060401b6040516020018084815260200183805190602001908083835b6020831061135a57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161131d565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790527fffffffffffffffffffffffffffffffffffffffffffffffff000000000000000095909516920191825250604080518083037ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8018152601890920190819052815191955093508392850191508083835b6020831061143f57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101611402565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa15801561149c573d6000803e3d6000fd5b5050506040513d60208110156114b157600080fd5b50519250505090565b60408051600880825281830190925260609160208201818036833701905050905060c082901b8060071a60f81b826000815181106114f457fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060061a60f81b8260018151811061153757fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060051a60f81b8260028151811061157a57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060041a60f81b826003815181106115bd57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060031a60f81b8260048151811061160057fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060021a60f81b8260058151811061164357fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060011a60f81b8260068151811061168657fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060001a60f81b826007815181106116c957fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535050919050565b6000808585111561170d578182fd5b83861115611719578182fd5b505082019391909203915056fe4465706f736974436f6e74726163743a206d65726b6c6520747265652066756c6c4465706f736974436f6e74726163743a207265636f6e7374727563746564204465706f7369744461746120646f6573206e6f74206d6174636820737570706c696564206465706f7369745f646174615f726f6f744465706f736974436f6e74726163743a20696e76616c6964207769746864726177616c5f63726564656e7469616c73206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c7565206e6f74206d756c7469706c65206f6620677765694465706f736974436f6e74726163743a20696e76616c6964207075626b6579206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f20686967684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f206c6f774465706f736974436f6e74726163743a20696e76616c6964207369676e6174757265206c656e677468a264697066735822122048c9c1aefe892e05fe034c24a651f00a2a8c0eb7e7c569d35ac1920c1a6894bc64736f6c63430006080033"} \ No newline at end of file From 6894e55f07d858826718eab5331fbf79fcfe7f12 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 23 Jun 2020 22:41:20 +0100 Subject: [PATCH 38/69] Update README to reflect the current status (#37) --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c98b38c56..d5a71191e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ # eth2-deposit-contract -This is a just for fun port of the [Vyper Eth 2.0 deposit contract](https://github.com/ethereum/eth2.0-specs/blob/dev/deposit_contract/contracts/validator_registration.vy) to Solidity. +This is a port of the [Vyper Eth 2.0 deposit contract](https://github.com/ethereum/eth2.0-specs/blob/dev/deposit_contract/contracts/validator_registration.vy) to Solidity. -The motivation is to run the SMTChecker and the new Yul IR generator option (`--ir`) in the compiler. +The original motivation was to run the SMTChecker and the new Yul IR generator option (`--ir`) in the compiler. -**THIS IS NOT THE OFFICIAL DEPOSIT CONTRACT. NOT SUITABLE FOR ANY USE** +As of June 2020, this contract (the version tagged as `r1`) has been verified and is considered for adoption. +See this [blog post](https://blog.ethereum.org/2020/06/23/eth2-quick-update-no-12/) for more information. ## Using this with the tests From 3a0dd2b253003d313b92a109bb63d680c922d59e Mon Sep 17 00:00:00 2001 From: lsankar4033 Date: Tue, 28 Jul 2020 17:51:32 -0700 Subject: [PATCH 39/69] Add self-consistency check to attestation gossip validation --- specs/phase0/p2p-interface.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/specs/phase0/p2p-interface.md b/specs/phase0/p2p-interface.md index aa8d4aace..2d9afbdef 100644 --- a/specs/phase0/p2p-interface.md +++ b/specs/phase0/p2p-interface.md @@ -403,6 +403,8 @@ The following validations MUST pass before forwarding the `attestation` on the s - _[REJECT]_ The current `finalized_checkpoint` is an ancestor of the `block` defined by `attestation.data.beacon_block_root` -- i.e. `get_ancestor(store, attestation.data.beacon_block_root, compute_start_slot_at_epoch(store.finalized_checkpoint.epoch)) == store.finalized_checkpoint.root` +- _[REJECT]_ The attestation's epoch matches its target -- i.e. `attestation.data.target.epoch == + compute_epoch_at_slot(attestation.data.slot)` From bf6d5ce3b63560057ad2c79df1d092b2d2b97f15 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Mon, 3 Aug 2020 09:42:52 -0600 Subject: [PATCH 40/69] port #2005 and rearrange conditions --- specs/phase0/p2p-interface.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/specs/phase0/p2p-interface.md b/specs/phase0/p2p-interface.md index 2d9afbdef..76ff91eab 100644 --- a/specs/phase0/p2p-interface.md +++ b/specs/phase0/p2p-interface.md @@ -391,6 +391,8 @@ The following validations MUST pass before forwarding the `attestation` on the s (within a `MAXIMUM_GOSSIP_CLOCK_DISPARITY` allowance) -- i.e. `attestation.data.slot + ATTESTATION_PROPAGATION_SLOT_RANGE >= current_slot >= attestation.data.slot` (a client MAY queue future attestations for processing at the appropriate slot). +- _[REJECT]_ The attestation's epoch matches its target -- i.e. `attestation.data.target.epoch == + compute_epoch_at_slot(attestation.data.slot)` - _[REJECT]_ The attestation is unaggregated -- that is, it has exactly one participating validator (`len([bit in bit attestation.aggregation_bits if bit]) == 1`, i.e. exactly 1 bit is set). - _[IGNORE]_ There has been no other valid attestation seen on an attestation subnet @@ -400,11 +402,12 @@ The following validations MUST pass before forwarding the `attestation` on the s (via both gossip and non-gossip sources) (a client MAY queue aggregates for processing once block is retrieved). - _[REJECT]_ The block being voted for (`attestation.data.beacon_block_root`) passes validation. +- _[REJECT]_ The attestation's target block is an ancestor of the block named in the LMD vote -- i.e. + `get_ancestor(store, attestation.data.beacon_block_root, compute_start_slot_at_epoch(attestation.data.target.epoch)) == attestation.data.target.root` - _[REJECT]_ The current `finalized_checkpoint` is an ancestor of the `block` defined by `attestation.data.beacon_block_root` -- i.e. `get_ancestor(store, attestation.data.beacon_block_root, compute_start_slot_at_epoch(store.finalized_checkpoint.epoch)) == store.finalized_checkpoint.root` -- _[REJECT]_ The attestation's epoch matches its target -- i.e. `attestation.data.target.epoch == - compute_epoch_at_slot(attestation.data.slot)` + From 56dbc17793d8a6c62f506de2ced1494ea6bdc43b Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Wed, 5 Aug 2020 12:44:31 -0600 Subject: [PATCH 41/69] fix active shard count bugs --- specs/phase1/beacon-chain.md | 25 ++++++++++++++----- specs/phase1/phase1-fork.md | 1 - tests/core/pyspec/eth2spec/test/conftest.py | 6 ++++- .../phase1/unittests/test_get_start_shard.py | 13 ++++++++++ 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/specs/phase1/beacon-chain.md b/specs/phase1/beacon-chain.md index b64c31a57..4858f2575 100644 --- a/specs/phase1/beacon-chain.md +++ b/specs/phase1/beacon-chain.md @@ -106,6 +106,7 @@ Configuration is not namespaced. Instead it is strictly an extension; | Name | Value | | - | - | | `MAX_SHARDS` | `2**10` (= 1024) | +| `INITIAL_ACTIVE_SHARDS` | `2**6` (= 64) | | `LIGHT_CLIENT_COMMITTEE_SIZE` | `2**7` (= 128) | | `GASPRICE_ADJUSTMENT_COEFFICIENT` | `2**3` (= 8) | @@ -520,11 +521,24 @@ def compute_committee_source_epoch(epoch: Epoch, period: uint64) -> Epoch: ### Beacon state accessors +#### New `get_committee_count_per_slot` + +```python +def get_committee_count_per_slot(state: BeaconState, epoch: Epoch) -> uint64: + """ + Return the number of committees in each slot for the given ``epoch``. + """ + return max(uint64(1), min( + get_active_shard_count(state), + uint64(len(get_active_validator_indices(state, epoch))) // SLOTS_PER_EPOCH // TARGET_COMMITTEE_SIZE, + )) +``` + #### `get_active_shard_count` ```python def get_active_shard_count(state: BeaconState) -> uint64: - return len(state.shard_states) # May adapt in the future, or change over time. + return INITIAL_ACTIVE_SHARDS ``` #### `get_online_validator_indices` @@ -545,12 +559,11 @@ def get_shard_committee(beacon_state: BeaconState, epoch: Epoch, shard: Shard) - source_epoch = compute_committee_source_epoch(epoch, SHARD_COMMITTEE_PERIOD) active_validator_indices = get_active_validator_indices(beacon_state, source_epoch) seed = get_seed(beacon_state, source_epoch, DOMAIN_SHARD_COMMITTEE) - active_shard_count = get_active_shard_count(beacon_state) return compute_committee( indices=active_validator_indices, seed=seed, index=shard, - count=active_shard_count, + count=get_active_shard_count(beacon_state), ) ``` @@ -617,10 +630,11 @@ def get_start_shard(state: BeaconState, slot: Slot) -> Shard: else: # Previous epoch shard_delta = get_committee_count_delta(state, start_slot=slot, stop_slot=current_epoch_start_slot) - max_committees_per_epoch = MAX_COMMITTEES_PER_SLOT * SLOTS_PER_EPOCH + max_committees_per_slot = active_shard_count + max_committees_in_span = max_committees_per_slot * (current_epoch_start_slot - slot) return Shard( # Ensure positive - (state.current_epoch_start_shard + max_committees_per_epoch * active_shard_count - shard_delta) + (state.current_epoch_start_shard + max_committees_in_span - shard_delta) % active_shard_count ) ``` @@ -752,7 +766,6 @@ def process_operations(state: BeaconState, body: BeaconBlockBody) -> None: def validate_attestation(state: BeaconState, attestation: Attestation) -> None: data = attestation.data assert data.index < get_committee_count_per_slot(state, data.target.epoch) - assert data.index < get_active_shard_count(state) assert data.target.epoch in (get_previous_epoch(state), get_current_epoch(state)) assert data.target.epoch == compute_epoch_at_slot(data.slot) assert data.slot + MIN_ATTESTATION_INCLUSION_DELAY <= state.slot <= data.slot + SLOTS_PER_EPOCH diff --git a/specs/phase1/phase1-fork.md b/specs/phase1/phase1-fork.md index e3949aca8..a094b01fc 100644 --- a/specs/phase1/phase1-fork.md +++ b/specs/phase1/phase1-fork.md @@ -36,7 +36,6 @@ Warning: this configuration is not definitive. | - | - | | `PHASE_1_FORK_VERSION` | `Version('0x01000000')` | | `PHASE_1_FORK_SLOT` | `Slot(0)` **TBD** | -| `INITIAL_ACTIVE_SHARDS` | `2**6` (= 64) | ## Fork to Phase 1 diff --git a/tests/core/pyspec/eth2spec/test/conftest.py b/tests/core/pyspec/eth2spec/test/conftest.py index 21f7c7abb..addb31dde 100644 --- a/tests/core/pyspec/eth2spec/test/conftest.py +++ b/tests/core/pyspec/eth2spec/test/conftest.py @@ -50,7 +50,11 @@ def config(request): @fixture(autouse=True) def bls_default(request): - disable_bls = request.config.getoption("--disable-bls") + try: + disable_bls = request.config.getoption("--disable-bls") + except ValueError: + disable_bls = False + if disable_bls: context.DEFAULT_BLS_ACTIVE = False diff --git a/tests/core/pyspec/eth2spec/test/phase1/unittests/test_get_start_shard.py b/tests/core/pyspec/eth2spec/test/phase1/unittests/test_get_start_shard.py index c443545b9..a802d6c3c 100644 --- a/tests/core/pyspec/eth2spec/test/phase1/unittests/test_get_start_shard.py +++ b/tests/core/pyspec/eth2spec/test/phase1/unittests/test_get_start_shard.py @@ -74,3 +74,16 @@ def test_get_start_shard_previous_slot(spec, state): - spec.get_committee_count_delta(state, start_slot=slot, stop_slot=current_epoch_start_slot) ) % active_shard_count assert start_shard == expected_start_shard + + +@with_all_phases_except([PHASE0]) +@spec_state_test +def test_get_start_shard_far_past_epoch(spec, state): + initial_epoch = spec.get_current_epoch(state) + initial_start_slot = spec.compute_start_slot_at_epoch(initial_epoch) + initial_start_shard = state.current_epoch_start_shard + + for _ in range(spec.MAX_SHARDS + 2): + next_epoch(spec, state) + + assert spec.get_start_shard(state, initial_start_slot) == initial_start_shard From c3ae85387c8b561425da4bad7597a50565539bb1 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Wed, 5 Aug 2020 13:04:13 -0600 Subject: [PATCH 42/69] add larger validator set test for regression test for active_shard_count issue --- specs/phase1/beacon-chain.md | 1 + tests/core/pyspec/eth2spec/test/context.py | 9 ++++ .../test/phase0/sanity/test_blocks.py | 45 +++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/specs/phase1/beacon-chain.md b/specs/phase1/beacon-chain.md index 4858f2575..3cba3188d 100644 --- a/specs/phase1/beacon-chain.md +++ b/specs/phase1/beacon-chain.md @@ -47,6 +47,7 @@ - [`compute_updated_gasprice`](#compute_updated_gasprice) - [`compute_committee_source_epoch`](#compute_committee_source_epoch) - [Beacon state accessors](#beacon-state-accessors) + - [New `get_committee_count_per_slot`](#new-get_committee_count_per_slot) - [`get_active_shard_count`](#get_active_shard_count) - [`get_online_validator_indices`](#get_online_validator_indices) - [`get_shard_committee`](#get_shard_committee) diff --git a/tests/core/pyspec/eth2spec/test/context.py b/tests/core/pyspec/eth2spec/test/context.py index 68696ea0a..69be2fd0a 100644 --- a/tests/core/pyspec/eth2spec/test/context.py +++ b/tests/core/pyspec/eth2spec/test/context.py @@ -151,6 +151,15 @@ def low_single_balance(spec): return [1] +def large_validator_set(spec): + """ + Helper method to create a series of default balances. + Usage: `@with_custom_state(balances_fn=default_balances, ...)` + """ + num_validators = 2 * spec.SLOTS_PER_EPOCH * spec.MAX_COMMITTEES_PER_SLOT * spec.TARGET_COMMITTEE_SIZE + return [spec.MAX_EFFECTIVE_BALANCE] * num_validators + + def single_phase(fn): """ Decorator that filters out the phases data. diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py index 6d7ff096a..3ec76e8b8 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py @@ -22,7 +22,10 @@ from eth2spec.test.helpers.shard_transitions import get_shard_transition_of_comm from eth2spec.test.context import ( PHASE0, PHASE1, + spec_test, spec_state_test, with_all_phases, expect_assertion_error, always_bls, with_phases, + with_custom_state, single_phase, + large_validator_set, ) @@ -85,6 +88,28 @@ def test_empty_block_transition(spec, state): assert spec.get_randao_mix(state, spec.get_current_epoch(state)) != spec.Bytes32() +@with_all_phases +@spec_test +@with_custom_state(balances_fn=large_validator_set, threshold_fn=lambda spec: spec.EJECTION_BALANCE) +@single_phase +def test_empty_block_transition_large_validator_set(spec, state): + pre_slot = state.slot + pre_eth1_votes = len(state.eth1_data_votes) + + yield 'pre', state + + block = build_empty_block_for_next_slot(spec, state) + + signed_block = state_transition_and_sign_block(spec, state, block) + + yield 'blocks', [signed_block] + yield 'post', state + + assert len(state.eth1_data_votes) == pre_eth1_votes + 1 + assert spec.get_block_root_at_slot(state, pre_slot) == signed_block.message.parent_root + assert spec.get_randao_mix(state, spec.get_current_epoch(state)) != spec.Bytes32() + + def process_and_sign_block_without_header_validations(spec, state, block): """ Artificially bypass the restrictions in the state transition to transition and sign block @@ -288,6 +313,26 @@ def test_empty_epoch_transition(spec, state): assert spec.get_block_root_at_slot(state, slot) == block.parent_root +@with_all_phases +@spec_test +@with_custom_state(balances_fn=large_validator_set, threshold_fn=lambda spec: spec.EJECTION_BALANCE) +@single_phase +def test_empty_epoch_transition_large_validator_set(spec, state): + pre_slot = state.slot + yield 'pre', state + + block = build_empty_block(spec, state, state.slot + spec.SLOTS_PER_EPOCH) + + signed_block = state_transition_and_sign_block(spec, state, block) + + yield 'blocks', [signed_block] + yield 'post', state + + assert state.slot == block.slot + for slot in range(pre_slot, state.slot): + assert spec.get_block_root_at_slot(state, slot) == block.parent_root + + @with_all_phases @spec_state_test def test_empty_epoch_transition_not_finalizing(spec, state): From 76c96782e24f6aa26b4a0dd129208ae9e205f54b Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Mon, 10 Aug 2020 12:58:57 -0600 Subject: [PATCH 43/69] fix disable-bls default value --- tests/core/pyspec/eth2spec/test/conftest.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/conftest.py b/tests/core/pyspec/eth2spec/test/conftest.py index addb31dde..b961ee082 100644 --- a/tests/core/pyspec/eth2spec/test/conftest.py +++ b/tests/core/pyspec/eth2spec/test/conftest.py @@ -31,7 +31,7 @@ def pytest_addoption(parser): help="config: make the pyspec use the specified configuration" ) parser.addoption( - "--disable-bls", action="store_true", + "--disable-bls", action="store_true", default=False, help="bls-default: make tests that are not dependent on BLS run without BLS" ) parser.addoption( @@ -50,11 +50,7 @@ def config(request): @fixture(autouse=True) def bls_default(request): - try: - disable_bls = request.config.getoption("--disable-bls") - except ValueError: - disable_bls = False - + disable_bls = request.config.getoption("--disable-bls") if disable_bls: context.DEFAULT_BLS_ACTIVE = False From 8b39d41145e0fedbe6b6207596ee0cff1567ba29 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Mon, 10 Aug 2020 13:02:22 -0600 Subject: [PATCH 44/69] PR feedback --- specs/phase1/beacon-chain.md | 8 ++++++-- .../pyspec/eth2spec/test/phase0/sanity/test_blocks.py | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/specs/phase1/beacon-chain.md b/specs/phase1/beacon-chain.md index 3cba3188d..f31be03a2 100644 --- a/specs/phase1/beacon-chain.md +++ b/specs/phase1/beacon-chain.md @@ -47,7 +47,7 @@ - [`compute_updated_gasprice`](#compute_updated_gasprice) - [`compute_committee_source_epoch`](#compute_committee_source_epoch) - [Beacon state accessors](#beacon-state-accessors) - - [New `get_committee_count_per_slot`](#new-get_committee_count_per_slot) + - [Updated `get_committee_count_per_slot`](#updated-get_committee_count_per_slot) - [`get_active_shard_count`](#get_active_shard_count) - [`get_online_validator_indices`](#get_online_validator_indices) - [`get_shard_committee`](#get_shard_committee) @@ -522,7 +522,7 @@ def compute_committee_source_epoch(epoch: Epoch, period: uint64) -> Epoch: ### Beacon state accessors -#### New `get_committee_count_per_slot` +#### Updated `get_committee_count_per_slot` ```python def get_committee_count_per_slot(state: BeaconState, epoch: Epoch) -> uint64: @@ -539,6 +539,10 @@ def get_committee_count_per_slot(state: BeaconState, epoch: Epoch) -> uint64: ```python def get_active_shard_count(state: BeaconState) -> uint64: + """ + Return the number of active shards. + Note that this puts an upper bound on the number of committees per slot. + """ return INITIAL_ACTIVE_SHARDS ``` diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py index 3ec76e8b8..fa4e690af 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py @@ -76,6 +76,9 @@ def test_empty_block_transition(spec, state): yield 'pre', state + # Ensure pre-state has default randao + assert spec.get_randao_mix(state, spec.get_current_epoch(state)) == spec.Bytes32() + block = build_empty_block_for_next_slot(spec, state) signed_block = state_transition_and_sign_block(spec, state, block) @@ -98,6 +101,9 @@ def test_empty_block_transition_large_validator_set(spec, state): yield 'pre', state + # Ensure pre-state has default randao + assert spec.get_randao_mix(state, spec.get_current_epoch(state)) == spec.Bytes32() + block = build_empty_block_for_next_slot(spec, state) signed_block = state_transition_and_sign_block(spec, state, block) From b02c2e1c498ef36d65c5b3204208e94f89520a07 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Mon, 10 Aug 2020 21:00:23 -0600 Subject: [PATCH 45/69] fix randao mix in sanity tests --- .../eth2spec/test/phase0/sanity/test_blocks.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py index fa4e690af..5b98abac4 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py @@ -73,12 +73,10 @@ def test_same_slot_block_transition(spec, state): def test_empty_block_transition(spec, state): pre_slot = state.slot pre_eth1_votes = len(state.eth1_data_votes) + pre_mix = spec.get_randao_mix(state, spec.get_current_epoch(state)) yield 'pre', state - # Ensure pre-state has default randao - assert spec.get_randao_mix(state, spec.get_current_epoch(state)) == spec.Bytes32() - block = build_empty_block_for_next_slot(spec, state) signed_block = state_transition_and_sign_block(spec, state, block) @@ -88,7 +86,7 @@ def test_empty_block_transition(spec, state): assert len(state.eth1_data_votes) == pre_eth1_votes + 1 assert spec.get_block_root_at_slot(state, pre_slot) == signed_block.message.parent_root - assert spec.get_randao_mix(state, spec.get_current_epoch(state)) != spec.Bytes32() + assert spec.get_randao_mix(state, spec.get_current_epoch(state)) != pre_mix @with_all_phases @@ -98,12 +96,10 @@ def test_empty_block_transition(spec, state): def test_empty_block_transition_large_validator_set(spec, state): pre_slot = state.slot pre_eth1_votes = len(state.eth1_data_votes) + pre_mix = spec.get_randao_mix(state, spec.get_current_epoch(state)) yield 'pre', state - # Ensure pre-state has default randao - assert spec.get_randao_mix(state, spec.get_current_epoch(state)) == spec.Bytes32() - block = build_empty_block_for_next_slot(spec, state) signed_block = state_transition_and_sign_block(spec, state, block) @@ -113,7 +109,7 @@ def test_empty_block_transition_large_validator_set(spec, state): assert len(state.eth1_data_votes) == pre_eth1_votes + 1 assert spec.get_block_root_at_slot(state, pre_slot) == signed_block.message.parent_root - assert spec.get_randao_mix(state, spec.get_current_epoch(state)) != spec.Bytes32() + assert spec.get_randao_mix(state, spec.get_current_epoch(state)) != pre_mix def process_and_sign_block_without_header_validations(spec, state, block): From 537a3ee5154ecbcccb41ad933afa9246c9529a06 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 13 Aug 2020 20:39:17 +0100 Subject: [PATCH 46/69] Add graffiti (#34) Also update binary output due to metadata change. --- deposit_contract.json | 2 +- deposit_contract.sol | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/deposit_contract.json b/deposit_contract.json index d31a99329..b40f7ffd9 100644 --- a/deposit_contract.json +++ b/deposit_contract.json @@ -1 +1 @@ -{"abi": [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"pubkey","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"withdrawal_credentials","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"amount","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"signature","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"index","type":"bytes"}],"name":"DepositEvent","type":"event"},{"inputs":[{"internalType":"bytes","name":"pubkey","type":"bytes"},{"internalType":"bytes","name":"withdrawal_credentials","type":"bytes"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"bytes32","name":"deposit_data_root","type":"bytes32"}],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"get_deposit_count","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"get_deposit_root","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}], "bytecode": "0x608060405234801561001057600080fd5b5060005b601f8110156101025760026021826020811061002c57fe5b01546021836020811061003b57fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b602083106100925780518252601f199092019160209182019101610073565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa1580156100d1573d6000803e3d6000fd5b5050506040513d60208110156100e657600080fd5b5051602160018301602081106100f857fe5b0155600101610014565b506118d680620001136000396000f3fe60806040526004361061003f5760003560e01c806301ffc9a71461004457806322895118146100a4578063621fd130146101ba578063c5f2892f14610244575b600080fd5b34801561005057600080fd5b506100906004803603602081101561006757600080fd5b50357fffffffff000000000000000000000000000000000000000000000000000000001661026b565b604080519115158252519081900360200190f35b6101b8600480360360808110156100ba57600080fd5b8101906020810181356401000000008111156100d557600080fd5b8201836020820111156100e757600080fd5b8035906020019184600183028401116401000000008311171561010957600080fd5b91939092909160208101903564010000000081111561012757600080fd5b82018360208201111561013957600080fd5b8035906020019184600183028401116401000000008311171561015b57600080fd5b91939092909160208101903564010000000081111561017957600080fd5b82018360208201111561018b57600080fd5b803590602001918460018302840111640100000000831117156101ad57600080fd5b919350915035610304565b005b3480156101c657600080fd5b506101cf6110b5565b6040805160208082528351818301528351919283929083019185019080838360005b838110156102095781810151838201526020016101f1565b50505050905090810190601f1680156102365780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561025057600080fd5b506102596110c7565b60408051918252519081900360200190f35b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f01ffc9a70000000000000000000000000000000000000000000000000000000014806102fe57507fffffffff0000000000000000000000000000000000000000000000000000000082167f8564090700000000000000000000000000000000000000000000000000000000145b92915050565b6030861461035d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806118056026913960400191505060405180910390fd5b602084146103b6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252603681526020018061179c6036913960400191505060405180910390fd5b6060821461040f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260298152602001806118786029913960400191505060405180910390fd5b670de0b6b3a7640000341015610470576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806118526026913960400191505060405180910390fd5b633b9aca003406156104cd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260338152602001806117d26033913960400191505060405180910390fd5b633b9aca00340467ffffffffffffffff811115610535576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602781526020018061182b6027913960400191505060405180910390fd5b6060610540826114ba565b90507f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c589898989858a8a6105756020546114ba565b6040805160a0808252810189905290819060208201908201606083016080840160c085018e8e80828437600083820152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690910187810386528c815260200190508c8c808284376000838201819052601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690920188810386528c5181528c51602091820193918e019250908190849084905b83811015610648578181015183820152602001610630565b50505050905090810190601f1680156106755780820380516001836020036101000a031916815260200191505b5086810383528881526020018989808284376000838201819052601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169092018881038452895181528951602091820193918b019250908190849084905b838110156106ef5781810151838201526020016106d7565b50505050905090810190601f16801561071c5780820380516001836020036101000a031916815260200191505b509d505050505050505050505050505060405180910390a1600060028a8a600060801b604051602001808484808284377fffffffffffffffffffffffffffffffff0000000000000000000000000000000090941691909301908152604080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0818403018152601090920190819052815191955093508392506020850191508083835b602083106107fc57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016107bf565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610859573d6000803e3d6000fd5b5050506040513d602081101561086e57600080fd5b5051905060006002806108846040848a8c6116fe565b6040516020018083838082843780830192505050925050506040516020818303038152906040526040518082805190602001908083835b602083106108f857805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016108bb565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610955573d6000803e3d6000fd5b5050506040513d602081101561096a57600080fd5b5051600261097b896040818d6116fe565b60405160009060200180848480828437919091019283525050604080518083038152602092830191829052805190945090925082918401908083835b602083106109f457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016109b7565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610a51573d6000803e3d6000fd5b5050506040513d6020811015610a6657600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610ada57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610a9d565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610b37573d6000803e3d6000fd5b5050506040513d6020811015610b4c57600080fd5b50516040805160208101858152929350600092600292839287928f928f92018383808284378083019250505093505050506040516020818303038152906040526040518082805190602001908083835b60208310610bd957805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610b9c565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610c36573d6000803e3d6000fd5b5050506040513d6020811015610c4b57600080fd5b50516040518651600291889160009188916020918201918291908601908083835b60208310610ca957805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610c6c565b6001836020036101000a0380198251168184511680821785525050505050509050018367ffffffffffffffff191667ffffffffffffffff1916815260180182815260200193505050506040516020818303038152906040526040518082805190602001908083835b60208310610d4e57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610d11565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610dab573d6000803e3d6000fd5b5050506040513d6020811015610dc057600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610e3457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610df7565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610e91573d6000803e3d6000fd5b5050506040513d6020811015610ea657600080fd5b50519050858114610f02576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260548152602001806117486054913960600191505060405180910390fd5b60205463ffffffff11610f60576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806117276021913960400191505060405180910390fd5b602080546001019081905560005b60208110156110a9578160011660011415610fa0578260008260208110610f9157fe5b0155506110ac95505050505050565b600260008260208110610faf57fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061102557805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610fe8565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015611082573d6000803e3d6000fd5b5050506040513d602081101561109757600080fd5b50519250600282049150600101610f6e565b50fe5b50505050505050565b60606110c26020546114ba565b905090565b6020546000908190815b60208110156112f05781600116600114156111e6576002600082602081106110f557fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061116b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161112e565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa1580156111c8573d6000803e3d6000fd5b5050506040513d60208110156111dd57600080fd5b505192506112e2565b600283602183602081106111f657fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061126b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161122e565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa1580156112c8573d6000803e3d6000fd5b5050506040513d60208110156112dd57600080fd5b505192505b6002820491506001016110d1565b506002826112ff6020546114ba565b600060401b6040516020018084815260200183805190602001908083835b6020831061135a57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161131d565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790527fffffffffffffffffffffffffffffffffffffffffffffffff000000000000000095909516920191825250604080518083037ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8018152601890920190819052815191955093508392850191508083835b6020831061143f57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101611402565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa15801561149c573d6000803e3d6000fd5b5050506040513d60208110156114b157600080fd5b50519250505090565b60408051600880825281830190925260609160208201818036833701905050905060c082901b8060071a60f81b826000815181106114f457fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060061a60f81b8260018151811061153757fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060051a60f81b8260028151811061157a57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060041a60f81b826003815181106115bd57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060031a60f81b8260048151811061160057fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060021a60f81b8260058151811061164357fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060011a60f81b8260068151811061168657fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060001a60f81b826007815181106116c957fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535050919050565b6000808585111561170d578182fd5b83861115611719578182fd5b505082019391909203915056fe4465706f736974436f6e74726163743a206d65726b6c6520747265652066756c6c4465706f736974436f6e74726163743a207265636f6e7374727563746564204465706f7369744461746120646f6573206e6f74206d6174636820737570706c696564206465706f7369745f646174615f726f6f744465706f736974436f6e74726163743a20696e76616c6964207769746864726177616c5f63726564656e7469616c73206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c7565206e6f74206d756c7469706c65206f6620677765694465706f736974436f6e74726163743a20696e76616c6964207075626b6579206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f20686967684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f206c6f774465706f736974436f6e74726163743a20696e76616c6964207369676e6174757265206c656e677468a264697066735822122048c9c1aefe892e05fe034c24a651f00a2a8c0eb7e7c569d35ac1920c1a6894bc64736f6c63430006080033"} \ No newline at end of file +{"abi": [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"pubkey","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"withdrawal_credentials","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"amount","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"signature","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"index","type":"bytes"}],"name":"DepositEvent","type":"event"},{"inputs":[{"internalType":"bytes","name":"pubkey","type":"bytes"},{"internalType":"bytes","name":"withdrawal_credentials","type":"bytes"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"bytes32","name":"deposit_data_root","type":"bytes32"}],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"get_deposit_count","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"get_deposit_root","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}], "bytecode": "0x608060405234801561001057600080fd5b5060005b601f8110156101025760026021826020811061002c57fe5b01546021836020811061003b57fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b602083106100925780518252601f199092019160209182019101610073565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa1580156100d1573d6000803e3d6000fd5b5050506040513d60208110156100e657600080fd5b5051602160018301602081106100f857fe5b0155600101610014565b506118d680620001136000396000f3fe60806040526004361061003f5760003560e01c806301ffc9a71461004457806322895118146100a4578063621fd130146101ba578063c5f2892f14610244575b600080fd5b34801561005057600080fd5b506100906004803603602081101561006757600080fd5b50357fffffffff000000000000000000000000000000000000000000000000000000001661026b565b604080519115158252519081900360200190f35b6101b8600480360360808110156100ba57600080fd5b8101906020810181356401000000008111156100d557600080fd5b8201836020820111156100e757600080fd5b8035906020019184600183028401116401000000008311171561010957600080fd5b91939092909160208101903564010000000081111561012757600080fd5b82018360208201111561013957600080fd5b8035906020019184600183028401116401000000008311171561015b57600080fd5b91939092909160208101903564010000000081111561017957600080fd5b82018360208201111561018b57600080fd5b803590602001918460018302840111640100000000831117156101ad57600080fd5b919350915035610304565b005b3480156101c657600080fd5b506101cf6110b5565b6040805160208082528351818301528351919283929083019185019080838360005b838110156102095781810151838201526020016101f1565b50505050905090810190601f1680156102365780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561025057600080fd5b506102596110c7565b60408051918252519081900360200190f35b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f01ffc9a70000000000000000000000000000000000000000000000000000000014806102fe57507fffffffff0000000000000000000000000000000000000000000000000000000082167f8564090700000000000000000000000000000000000000000000000000000000145b92915050565b6030861461035d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806118056026913960400191505060405180910390fd5b602084146103b6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252603681526020018061179c6036913960400191505060405180910390fd5b6060821461040f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260298152602001806118786029913960400191505060405180910390fd5b670de0b6b3a7640000341015610470576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806118526026913960400191505060405180910390fd5b633b9aca003406156104cd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260338152602001806117d26033913960400191505060405180910390fd5b633b9aca00340467ffffffffffffffff811115610535576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602781526020018061182b6027913960400191505060405180910390fd5b6060610540826114ba565b90507f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c589898989858a8a6105756020546114ba565b6040805160a0808252810189905290819060208201908201606083016080840160c085018e8e80828437600083820152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690910187810386528c815260200190508c8c808284376000838201819052601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690920188810386528c5181528c51602091820193918e019250908190849084905b83811015610648578181015183820152602001610630565b50505050905090810190601f1680156106755780820380516001836020036101000a031916815260200191505b5086810383528881526020018989808284376000838201819052601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169092018881038452895181528951602091820193918b019250908190849084905b838110156106ef5781810151838201526020016106d7565b50505050905090810190601f16801561071c5780820380516001836020036101000a031916815260200191505b509d505050505050505050505050505060405180910390a1600060028a8a600060801b604051602001808484808284377fffffffffffffffffffffffffffffffff0000000000000000000000000000000090941691909301908152604080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0818403018152601090920190819052815191955093508392506020850191508083835b602083106107fc57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016107bf565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610859573d6000803e3d6000fd5b5050506040513d602081101561086e57600080fd5b5051905060006002806108846040848a8c6116fe565b6040516020018083838082843780830192505050925050506040516020818303038152906040526040518082805190602001908083835b602083106108f857805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016108bb565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610955573d6000803e3d6000fd5b5050506040513d602081101561096a57600080fd5b5051600261097b896040818d6116fe565b60405160009060200180848480828437919091019283525050604080518083038152602092830191829052805190945090925082918401908083835b602083106109f457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016109b7565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610a51573d6000803e3d6000fd5b5050506040513d6020811015610a6657600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610ada57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610a9d565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610b37573d6000803e3d6000fd5b5050506040513d6020811015610b4c57600080fd5b50516040805160208101858152929350600092600292839287928f928f92018383808284378083019250505093505050506040516020818303038152906040526040518082805190602001908083835b60208310610bd957805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610b9c565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610c36573d6000803e3d6000fd5b5050506040513d6020811015610c4b57600080fd5b50516040518651600291889160009188916020918201918291908601908083835b60208310610ca957805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610c6c565b6001836020036101000a0380198251168184511680821785525050505050509050018367ffffffffffffffff191667ffffffffffffffff1916815260180182815260200193505050506040516020818303038152906040526040518082805190602001908083835b60208310610d4e57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610d11565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610dab573d6000803e3d6000fd5b5050506040513d6020811015610dc057600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610e3457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610df7565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610e91573d6000803e3d6000fd5b5050506040513d6020811015610ea657600080fd5b50519050858114610f02576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260548152602001806117486054913960600191505060405180910390fd5b60205463ffffffff11610f60576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806117276021913960400191505060405180910390fd5b602080546001019081905560005b60208110156110a9578160011660011415610fa0578260008260208110610f9157fe5b0155506110ac95505050505050565b600260008260208110610faf57fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061102557805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610fe8565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015611082573d6000803e3d6000fd5b5050506040513d602081101561109757600080fd5b50519250600282049150600101610f6e565b50fe5b50505050505050565b60606110c26020546114ba565b905090565b6020546000908190815b60208110156112f05781600116600114156111e6576002600082602081106110f557fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061116b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161112e565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa1580156111c8573d6000803e3d6000fd5b5050506040513d60208110156111dd57600080fd5b505192506112e2565b600283602183602081106111f657fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061126b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161122e565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa1580156112c8573d6000803e3d6000fd5b5050506040513d60208110156112dd57600080fd5b505192505b6002820491506001016110d1565b506002826112ff6020546114ba565b600060401b6040516020018084815260200183805190602001908083835b6020831061135a57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161131d565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790527fffffffffffffffffffffffffffffffffffffffffffffffff000000000000000095909516920191825250604080518083037ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8018152601890920190819052815191955093508392850191508083835b6020831061143f57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101611402565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa15801561149c573d6000803e3d6000fd5b5050506040513d60208110156114b157600080fd5b50519250505090565b60408051600880825281830190925260609160208201818036833701905050905060c082901b8060071a60f81b826000815181106114f457fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060061a60f81b8260018151811061153757fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060051a60f81b8260028151811061157a57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060041a60f81b826003815181106115bd57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060031a60f81b8260048151811061160057fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060021a60f81b8260058151811061164357fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060011a60f81b8260068151811061168657fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060001a60f81b826007815181106116c957fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535050919050565b6000808585111561170d578182fd5b83861115611719578182fd5b505082019391909203915056fe4465706f736974436f6e74726163743a206d65726b6c6520747265652066756c6c4465706f736974436f6e74726163743a207265636f6e7374727563746564204465706f7369744461746120646f6573206e6f74206d6174636820737570706c696564206465706f7369745f646174615f726f6f744465706f736974436f6e74726163743a20696e76616c6964207769746864726177616c5f63726564656e7469616c73206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c7565206e6f74206d756c7469706c65206f6620677765694465706f736974436f6e74726163743a20696e76616c6964207075626b6579206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f20686967684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f206c6f774465706f736974436f6e74726163743a20696e76616c6964207369676e6174757265206c656e677468a26469706673582212202d643e7e9ac449f44920ebfc859db58bdeafd4eefccd5b4ebe12b2fd0492af4c64736f6c63430006080033"} \ No newline at end of file diff --git a/deposit_contract.sol b/deposit_contract.sol index 4b6b05c0c..2caaa4a4b 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -1,3 +1,12 @@ +// ┏━━━┓━┏┓━┏┓━━┏━━━┓━━┏━━━┓━━━━┏━━━┓━━━━━━━━━━━━━━━━━━━┏┓━━━━━┏━━━┓━━━━━━━━━┏┓━━━━━━━━━━━━━━┏┓━ +// ┃┏━━┛┏┛┗┓┃┃━━┃┏━┓┃━━┃┏━┓┃━━━━┗┓┏┓┃━━━━━━━━━━━━━━━━━━┏┛┗┓━━━━┃┏━┓┃━━━━━━━━┏┛┗┓━━━━━━━━━━━━┏┛┗┓ +// ┃┗━━┓┗┓┏┛┃┗━┓┗┛┏┛┃━━┃┃━┃┃━━━━━┃┃┃┃┏━━┓┏━━┓┏━━┓┏━━┓┏┓┗┓┏┛━━━━┃┃━┗┛┏━━┓┏━┓━┗┓┏┛┏━┓┏━━┓━┏━━┓┗┓┏┛ +// ┃┏━━┛━┃┃━┃┏┓┃┏━┛┏┛━━┃┃━┃┃━━━━━┃┃┃┃┃┏┓┃┃┏┓┃┃┏┓┃┃━━┫┣┫━┃┃━━━━━┃┃━┏┓┃┏┓┃┃┏┓┓━┃┃━┃┏┛┗━┓┃━┃┏━┛━┃┃━ +// ┃┗━━┓━┃┗┓┃┃┃┃┃┃┗━┓┏┓┃┗━┛┃━━━━┏┛┗┛┃┃┃━┫┃┗┛┃┃┗┛┃┣━━┃┃┃━┃┗┓━━━━┃┗━┛┃┃┗┛┃┃┃┃┃━┃┗┓┃┃━┃┗┛┗┓┃┗━┓━┃┗┓ +// ┗━━━┛━┗━┛┗┛┗┛┗━━━┛┗┛┗━━━┛━━━━┗━━━┛┗━━┛┃┏━┛┗━━┛┗━━┛┗┛━┗━┛━━━━┗━━━┛┗━━┛┗┛┗┛━┗━┛┗┛━┗━━━┛┗━━┛━┗━┛ +// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┃┃━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┗┛━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.6.8; From ebba75201239d2425201c41b3b9a2ca1ff14e6ca Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 13 Aug 2020 21:02:56 +0100 Subject: [PATCH 47/69] Upgrade to Solidity 0.6.11 (#39) Also update binary output due to metadata change. --- circle.yml | 2 +- deposit_contract.json | 2 +- deposit_contract.sol | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/circle.yml b/circle.yml index 53d0c71b5..c1b0b3506 100644 --- a/circle.yml +++ b/circle.yml @@ -3,7 +3,7 @@ version: 2.1 jobs: build: docker: - - image: ethereum/solc:0.6.8-alpine + - image: ethereum/solc:0.6.11-alpine steps: - checkout - run: diff --git a/deposit_contract.json b/deposit_contract.json index b40f7ffd9..150cd14ae 100644 --- a/deposit_contract.json +++ b/deposit_contract.json @@ -1 +1 @@ -{"abi": [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"pubkey","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"withdrawal_credentials","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"amount","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"signature","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"index","type":"bytes"}],"name":"DepositEvent","type":"event"},{"inputs":[{"internalType":"bytes","name":"pubkey","type":"bytes"},{"internalType":"bytes","name":"withdrawal_credentials","type":"bytes"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"bytes32","name":"deposit_data_root","type":"bytes32"}],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"get_deposit_count","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"get_deposit_root","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}], "bytecode": "0x608060405234801561001057600080fd5b5060005b601f8110156101025760026021826020811061002c57fe5b01546021836020811061003b57fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b602083106100925780518252601f199092019160209182019101610073565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa1580156100d1573d6000803e3d6000fd5b5050506040513d60208110156100e657600080fd5b5051602160018301602081106100f857fe5b0155600101610014565b506118d680620001136000396000f3fe60806040526004361061003f5760003560e01c806301ffc9a71461004457806322895118146100a4578063621fd130146101ba578063c5f2892f14610244575b600080fd5b34801561005057600080fd5b506100906004803603602081101561006757600080fd5b50357fffffffff000000000000000000000000000000000000000000000000000000001661026b565b604080519115158252519081900360200190f35b6101b8600480360360808110156100ba57600080fd5b8101906020810181356401000000008111156100d557600080fd5b8201836020820111156100e757600080fd5b8035906020019184600183028401116401000000008311171561010957600080fd5b91939092909160208101903564010000000081111561012757600080fd5b82018360208201111561013957600080fd5b8035906020019184600183028401116401000000008311171561015b57600080fd5b91939092909160208101903564010000000081111561017957600080fd5b82018360208201111561018b57600080fd5b803590602001918460018302840111640100000000831117156101ad57600080fd5b919350915035610304565b005b3480156101c657600080fd5b506101cf6110b5565b6040805160208082528351818301528351919283929083019185019080838360005b838110156102095781810151838201526020016101f1565b50505050905090810190601f1680156102365780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561025057600080fd5b506102596110c7565b60408051918252519081900360200190f35b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f01ffc9a70000000000000000000000000000000000000000000000000000000014806102fe57507fffffffff0000000000000000000000000000000000000000000000000000000082167f8564090700000000000000000000000000000000000000000000000000000000145b92915050565b6030861461035d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806118056026913960400191505060405180910390fd5b602084146103b6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252603681526020018061179c6036913960400191505060405180910390fd5b6060821461040f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260298152602001806118786029913960400191505060405180910390fd5b670de0b6b3a7640000341015610470576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806118526026913960400191505060405180910390fd5b633b9aca003406156104cd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260338152602001806117d26033913960400191505060405180910390fd5b633b9aca00340467ffffffffffffffff811115610535576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602781526020018061182b6027913960400191505060405180910390fd5b6060610540826114ba565b90507f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c589898989858a8a6105756020546114ba565b6040805160a0808252810189905290819060208201908201606083016080840160c085018e8e80828437600083820152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690910187810386528c815260200190508c8c808284376000838201819052601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690920188810386528c5181528c51602091820193918e019250908190849084905b83811015610648578181015183820152602001610630565b50505050905090810190601f1680156106755780820380516001836020036101000a031916815260200191505b5086810383528881526020018989808284376000838201819052601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169092018881038452895181528951602091820193918b019250908190849084905b838110156106ef5781810151838201526020016106d7565b50505050905090810190601f16801561071c5780820380516001836020036101000a031916815260200191505b509d505050505050505050505050505060405180910390a1600060028a8a600060801b604051602001808484808284377fffffffffffffffffffffffffffffffff0000000000000000000000000000000090941691909301908152604080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0818403018152601090920190819052815191955093508392506020850191508083835b602083106107fc57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016107bf565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610859573d6000803e3d6000fd5b5050506040513d602081101561086e57600080fd5b5051905060006002806108846040848a8c6116fe565b6040516020018083838082843780830192505050925050506040516020818303038152906040526040518082805190602001908083835b602083106108f857805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016108bb565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610955573d6000803e3d6000fd5b5050506040513d602081101561096a57600080fd5b5051600261097b896040818d6116fe565b60405160009060200180848480828437919091019283525050604080518083038152602092830191829052805190945090925082918401908083835b602083106109f457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016109b7565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610a51573d6000803e3d6000fd5b5050506040513d6020811015610a6657600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610ada57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610a9d565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610b37573d6000803e3d6000fd5b5050506040513d6020811015610b4c57600080fd5b50516040805160208101858152929350600092600292839287928f928f92018383808284378083019250505093505050506040516020818303038152906040526040518082805190602001908083835b60208310610bd957805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610b9c565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610c36573d6000803e3d6000fd5b5050506040513d6020811015610c4b57600080fd5b50516040518651600291889160009188916020918201918291908601908083835b60208310610ca957805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610c6c565b6001836020036101000a0380198251168184511680821785525050505050509050018367ffffffffffffffff191667ffffffffffffffff1916815260180182815260200193505050506040516020818303038152906040526040518082805190602001908083835b60208310610d4e57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610d11565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610dab573d6000803e3d6000fd5b5050506040513d6020811015610dc057600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610e3457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610df7565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610e91573d6000803e3d6000fd5b5050506040513d6020811015610ea657600080fd5b50519050858114610f02576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260548152602001806117486054913960600191505060405180910390fd5b60205463ffffffff11610f60576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806117276021913960400191505060405180910390fd5b602080546001019081905560005b60208110156110a9578160011660011415610fa0578260008260208110610f9157fe5b0155506110ac95505050505050565b600260008260208110610faf57fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061102557805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610fe8565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015611082573d6000803e3d6000fd5b5050506040513d602081101561109757600080fd5b50519250600282049150600101610f6e565b50fe5b50505050505050565b60606110c26020546114ba565b905090565b6020546000908190815b60208110156112f05781600116600114156111e6576002600082602081106110f557fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061116b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161112e565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa1580156111c8573d6000803e3d6000fd5b5050506040513d60208110156111dd57600080fd5b505192506112e2565b600283602183602081106111f657fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061126b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161122e565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa1580156112c8573d6000803e3d6000fd5b5050506040513d60208110156112dd57600080fd5b505192505b6002820491506001016110d1565b506002826112ff6020546114ba565b600060401b6040516020018084815260200183805190602001908083835b6020831061135a57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161131d565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790527fffffffffffffffffffffffffffffffffffffffffffffffff000000000000000095909516920191825250604080518083037ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8018152601890920190819052815191955093508392850191508083835b6020831061143f57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101611402565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa15801561149c573d6000803e3d6000fd5b5050506040513d60208110156114b157600080fd5b50519250505090565b60408051600880825281830190925260609160208201818036833701905050905060c082901b8060071a60f81b826000815181106114f457fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060061a60f81b8260018151811061153757fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060051a60f81b8260028151811061157a57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060041a60f81b826003815181106115bd57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060031a60f81b8260048151811061160057fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060021a60f81b8260058151811061164357fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060011a60f81b8260068151811061168657fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060001a60f81b826007815181106116c957fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535050919050565b6000808585111561170d578182fd5b83861115611719578182fd5b505082019391909203915056fe4465706f736974436f6e74726163743a206d65726b6c6520747265652066756c6c4465706f736974436f6e74726163743a207265636f6e7374727563746564204465706f7369744461746120646f6573206e6f74206d6174636820737570706c696564206465706f7369745f646174615f726f6f744465706f736974436f6e74726163743a20696e76616c6964207769746864726177616c5f63726564656e7469616c73206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c7565206e6f74206d756c7469706c65206f6620677765694465706f736974436f6e74726163743a20696e76616c6964207075626b6579206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f20686967684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f206c6f774465706f736974436f6e74726163743a20696e76616c6964207369676e6174757265206c656e677468a26469706673582212202d643e7e9ac449f44920ebfc859db58bdeafd4eefccd5b4ebe12b2fd0492af4c64736f6c63430006080033"} \ No newline at end of file +{"abi": [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"pubkey","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"withdrawal_credentials","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"amount","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"signature","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"index","type":"bytes"}],"name":"DepositEvent","type":"event"},{"inputs":[{"internalType":"bytes","name":"pubkey","type":"bytes"},{"internalType":"bytes","name":"withdrawal_credentials","type":"bytes"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"bytes32","name":"deposit_data_root","type":"bytes32"}],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"get_deposit_count","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"get_deposit_root","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}], "bytecode": "0x608060405234801561001057600080fd5b5060005b601f8110156101025760026021826020811061002c57fe5b01546021836020811061003b57fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b602083106100925780518252601f199092019160209182019101610073565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa1580156100d1573d6000803e3d6000fd5b5050506040513d60208110156100e657600080fd5b5051602160018301602081106100f857fe5b0155600101610014565b506118d680620001136000396000f3fe60806040526004361061003f5760003560e01c806301ffc9a71461004457806322895118146100a4578063621fd130146101ba578063c5f2892f14610244575b600080fd5b34801561005057600080fd5b506100906004803603602081101561006757600080fd5b50357fffffffff000000000000000000000000000000000000000000000000000000001661026b565b604080519115158252519081900360200190f35b6101b8600480360360808110156100ba57600080fd5b8101906020810181356401000000008111156100d557600080fd5b8201836020820111156100e757600080fd5b8035906020019184600183028401116401000000008311171561010957600080fd5b91939092909160208101903564010000000081111561012757600080fd5b82018360208201111561013957600080fd5b8035906020019184600183028401116401000000008311171561015b57600080fd5b91939092909160208101903564010000000081111561017957600080fd5b82018360208201111561018b57600080fd5b803590602001918460018302840111640100000000831117156101ad57600080fd5b919350915035610304565b005b3480156101c657600080fd5b506101cf6110b5565b6040805160208082528351818301528351919283929083019185019080838360005b838110156102095781810151838201526020016101f1565b50505050905090810190601f1680156102365780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561025057600080fd5b506102596110c7565b60408051918252519081900360200190f35b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f01ffc9a70000000000000000000000000000000000000000000000000000000014806102fe57507fffffffff0000000000000000000000000000000000000000000000000000000082167f8564090700000000000000000000000000000000000000000000000000000000145b92915050565b6030861461035d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806118056026913960400191505060405180910390fd5b602084146103b6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252603681526020018061179c6036913960400191505060405180910390fd5b6060821461040f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260298152602001806118786029913960400191505060405180910390fd5b670de0b6b3a7640000341015610470576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806118526026913960400191505060405180910390fd5b633b9aca003406156104cd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260338152602001806117d26033913960400191505060405180910390fd5b633b9aca00340467ffffffffffffffff811115610535576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602781526020018061182b6027913960400191505060405180910390fd5b6060610540826114ba565b90507f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c589898989858a8a6105756020546114ba565b6040805160a0808252810189905290819060208201908201606083016080840160c085018e8e80828437600083820152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690910187810386528c815260200190508c8c808284376000838201819052601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690920188810386528c5181528c51602091820193918e019250908190849084905b83811015610648578181015183820152602001610630565b50505050905090810190601f1680156106755780820380516001836020036101000a031916815260200191505b5086810383528881526020018989808284376000838201819052601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169092018881038452895181528951602091820193918b019250908190849084905b838110156106ef5781810151838201526020016106d7565b50505050905090810190601f16801561071c5780820380516001836020036101000a031916815260200191505b509d505050505050505050505050505060405180910390a1600060028a8a600060801b604051602001808484808284377fffffffffffffffffffffffffffffffff0000000000000000000000000000000090941691909301908152604080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0818403018152601090920190819052815191955093508392506020850191508083835b602083106107fc57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016107bf565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610859573d6000803e3d6000fd5b5050506040513d602081101561086e57600080fd5b5051905060006002806108846040848a8c6116fe565b6040516020018083838082843780830192505050925050506040516020818303038152906040526040518082805190602001908083835b602083106108f857805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016108bb565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610955573d6000803e3d6000fd5b5050506040513d602081101561096a57600080fd5b5051600261097b896040818d6116fe565b60405160009060200180848480828437919091019283525050604080518083038152602092830191829052805190945090925082918401908083835b602083106109f457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016109b7565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610a51573d6000803e3d6000fd5b5050506040513d6020811015610a6657600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610ada57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610a9d565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610b37573d6000803e3d6000fd5b5050506040513d6020811015610b4c57600080fd5b50516040805160208101858152929350600092600292839287928f928f92018383808284378083019250505093505050506040516020818303038152906040526040518082805190602001908083835b60208310610bd957805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610b9c565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610c36573d6000803e3d6000fd5b5050506040513d6020811015610c4b57600080fd5b50516040518651600291889160009188916020918201918291908601908083835b60208310610ca957805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610c6c565b6001836020036101000a0380198251168184511680821785525050505050509050018367ffffffffffffffff191667ffffffffffffffff1916815260180182815260200193505050506040516020818303038152906040526040518082805190602001908083835b60208310610d4e57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610d11565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610dab573d6000803e3d6000fd5b5050506040513d6020811015610dc057600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610e3457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610df7565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610e91573d6000803e3d6000fd5b5050506040513d6020811015610ea657600080fd5b50519050858114610f02576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260548152602001806117486054913960600191505060405180910390fd5b60205463ffffffff11610f60576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806117276021913960400191505060405180910390fd5b602080546001019081905560005b60208110156110a9578160011660011415610fa0578260008260208110610f9157fe5b0155506110ac95505050505050565b600260008260208110610faf57fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061102557805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610fe8565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015611082573d6000803e3d6000fd5b5050506040513d602081101561109757600080fd5b50519250600282049150600101610f6e565b50fe5b50505050505050565b60606110c26020546114ba565b905090565b6020546000908190815b60208110156112f05781600116600114156111e6576002600082602081106110f557fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061116b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161112e565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa1580156111c8573d6000803e3d6000fd5b5050506040513d60208110156111dd57600080fd5b505192506112e2565b600283602183602081106111f657fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061126b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161122e565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa1580156112c8573d6000803e3d6000fd5b5050506040513d60208110156112dd57600080fd5b505192505b6002820491506001016110d1565b506002826112ff6020546114ba565b600060401b6040516020018084815260200183805190602001908083835b6020831061135a57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161131d565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790527fffffffffffffffffffffffffffffffffffffffffffffffff000000000000000095909516920191825250604080518083037ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8018152601890920190819052815191955093508392850191508083835b6020831061143f57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101611402565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa15801561149c573d6000803e3d6000fd5b5050506040513d60208110156114b157600080fd5b50519250505090565b60408051600880825281830190925260609160208201818036833701905050905060c082901b8060071a60f81b826000815181106114f457fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060061a60f81b8260018151811061153757fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060051a60f81b8260028151811061157a57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060041a60f81b826003815181106115bd57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060031a60f81b8260048151811061160057fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060021a60f81b8260058151811061164357fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060011a60f81b8260068151811061168657fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060001a60f81b826007815181106116c957fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535050919050565b6000808585111561170d578182fd5b83861115611719578182fd5b505082019391909203915056fe4465706f736974436f6e74726163743a206d65726b6c6520747265652066756c6c4465706f736974436f6e74726163743a207265636f6e7374727563746564204465706f7369744461746120646f6573206e6f74206d6174636820737570706c696564206465706f7369745f646174615f726f6f744465706f736974436f6e74726163743a20696e76616c6964207769746864726177616c5f63726564656e7469616c73206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c7565206e6f74206d756c7469706c65206f6620677765694465706f736974436f6e74726163743a20696e76616c6964207075626b6579206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f20686967684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f206c6f774465706f736974436f6e74726163743a20696e76616c6964207369676e6174757265206c656e677468a2646970667358221220335950bd2d98c278f0495488ea87d72639ff47d535be235dca97784b8d630c8964736f6c634300060b0033"} \ No newline at end of file diff --git a/deposit_contract.sol b/deposit_contract.sol index 2caaa4a4b..a066bb10d 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -9,7 +9,7 @@ // SPDX-License-Identifier: Apache-2.0 -pragma solidity 0.6.8; +pragma solidity 0.6.11; // This interface is designed to be compatible with the Vyper version. /// @notice This is the Ethereum 2.0 deposit contract interface. @@ -62,8 +62,6 @@ interface ERC165 { /// @notice This is the Ethereum 2.0 deposit contract interface. /// For more information see the Phase 0 specification under https://github.com/ethereum/eth2.0-specs contract DepositContract is IDepositContract, ERC165 { - uint constant GWEI = 1e9; - uint constant DEPOSIT_CONTRACT_TREE_DEPTH = 32; // NOTE: this also ensures `deposit_count` will fit into 64-bits uint constant MAX_DEPOSIT_COUNT = 2**DEPOSIT_CONTRACT_TREE_DEPTH - 1; @@ -123,8 +121,8 @@ contract DepositContract is IDepositContract, ERC165 { // Check deposit amount require(msg.value >= 1 ether, "DepositContract: deposit value too low"); - require(msg.value % GWEI == 0, "DepositContract: deposit value not multiple of gwei"); - uint deposit_amount = msg.value / GWEI; + require(msg.value % 1 gwei == 0, "DepositContract: deposit value not multiple of gwei"); + uint deposit_amount = msg.value / 1 gwei; require(deposit_amount <= type(uint64).max, "DepositContract: deposit value too high"); // Emit `DepositEvent` log From 2739718922b1facb3464c48c4433c757531b4298 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 13 Aug 2020 21:14:46 +0100 Subject: [PATCH 48/69] Remove duplicated Natspec from the implementation (#36) Also update binary output due to metadata change. --- deposit_contract.json | 2 +- deposit_contract.sol | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/deposit_contract.json b/deposit_contract.json index 150cd14ae..ecec0945c 100644 --- a/deposit_contract.json +++ b/deposit_contract.json @@ -1 +1 @@ -{"abi": [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"pubkey","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"withdrawal_credentials","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"amount","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"signature","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"index","type":"bytes"}],"name":"DepositEvent","type":"event"},{"inputs":[{"internalType":"bytes","name":"pubkey","type":"bytes"},{"internalType":"bytes","name":"withdrawal_credentials","type":"bytes"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"bytes32","name":"deposit_data_root","type":"bytes32"}],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"get_deposit_count","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"get_deposit_root","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}], "bytecode": "0x608060405234801561001057600080fd5b5060005b601f8110156101025760026021826020811061002c57fe5b01546021836020811061003b57fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b602083106100925780518252601f199092019160209182019101610073565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa1580156100d1573d6000803e3d6000fd5b5050506040513d60208110156100e657600080fd5b5051602160018301602081106100f857fe5b0155600101610014565b506118d680620001136000396000f3fe60806040526004361061003f5760003560e01c806301ffc9a71461004457806322895118146100a4578063621fd130146101ba578063c5f2892f14610244575b600080fd5b34801561005057600080fd5b506100906004803603602081101561006757600080fd5b50357fffffffff000000000000000000000000000000000000000000000000000000001661026b565b604080519115158252519081900360200190f35b6101b8600480360360808110156100ba57600080fd5b8101906020810181356401000000008111156100d557600080fd5b8201836020820111156100e757600080fd5b8035906020019184600183028401116401000000008311171561010957600080fd5b91939092909160208101903564010000000081111561012757600080fd5b82018360208201111561013957600080fd5b8035906020019184600183028401116401000000008311171561015b57600080fd5b91939092909160208101903564010000000081111561017957600080fd5b82018360208201111561018b57600080fd5b803590602001918460018302840111640100000000831117156101ad57600080fd5b919350915035610304565b005b3480156101c657600080fd5b506101cf6110b5565b6040805160208082528351818301528351919283929083019185019080838360005b838110156102095781810151838201526020016101f1565b50505050905090810190601f1680156102365780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561025057600080fd5b506102596110c7565b60408051918252519081900360200190f35b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f01ffc9a70000000000000000000000000000000000000000000000000000000014806102fe57507fffffffff0000000000000000000000000000000000000000000000000000000082167f8564090700000000000000000000000000000000000000000000000000000000145b92915050565b6030861461035d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806118056026913960400191505060405180910390fd5b602084146103b6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252603681526020018061179c6036913960400191505060405180910390fd5b6060821461040f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260298152602001806118786029913960400191505060405180910390fd5b670de0b6b3a7640000341015610470576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806118526026913960400191505060405180910390fd5b633b9aca003406156104cd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260338152602001806117d26033913960400191505060405180910390fd5b633b9aca00340467ffffffffffffffff811115610535576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602781526020018061182b6027913960400191505060405180910390fd5b6060610540826114ba565b90507f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c589898989858a8a6105756020546114ba565b6040805160a0808252810189905290819060208201908201606083016080840160c085018e8e80828437600083820152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690910187810386528c815260200190508c8c808284376000838201819052601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690920188810386528c5181528c51602091820193918e019250908190849084905b83811015610648578181015183820152602001610630565b50505050905090810190601f1680156106755780820380516001836020036101000a031916815260200191505b5086810383528881526020018989808284376000838201819052601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169092018881038452895181528951602091820193918b019250908190849084905b838110156106ef5781810151838201526020016106d7565b50505050905090810190601f16801561071c5780820380516001836020036101000a031916815260200191505b509d505050505050505050505050505060405180910390a1600060028a8a600060801b604051602001808484808284377fffffffffffffffffffffffffffffffff0000000000000000000000000000000090941691909301908152604080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0818403018152601090920190819052815191955093508392506020850191508083835b602083106107fc57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016107bf565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610859573d6000803e3d6000fd5b5050506040513d602081101561086e57600080fd5b5051905060006002806108846040848a8c6116fe565b6040516020018083838082843780830192505050925050506040516020818303038152906040526040518082805190602001908083835b602083106108f857805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016108bb565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610955573d6000803e3d6000fd5b5050506040513d602081101561096a57600080fd5b5051600261097b896040818d6116fe565b60405160009060200180848480828437919091019283525050604080518083038152602092830191829052805190945090925082918401908083835b602083106109f457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016109b7565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610a51573d6000803e3d6000fd5b5050506040513d6020811015610a6657600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610ada57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610a9d565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610b37573d6000803e3d6000fd5b5050506040513d6020811015610b4c57600080fd5b50516040805160208101858152929350600092600292839287928f928f92018383808284378083019250505093505050506040516020818303038152906040526040518082805190602001908083835b60208310610bd957805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610b9c565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610c36573d6000803e3d6000fd5b5050506040513d6020811015610c4b57600080fd5b50516040518651600291889160009188916020918201918291908601908083835b60208310610ca957805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610c6c565b6001836020036101000a0380198251168184511680821785525050505050509050018367ffffffffffffffff191667ffffffffffffffff1916815260180182815260200193505050506040516020818303038152906040526040518082805190602001908083835b60208310610d4e57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610d11565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610dab573d6000803e3d6000fd5b5050506040513d6020811015610dc057600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610e3457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610df7565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610e91573d6000803e3d6000fd5b5050506040513d6020811015610ea657600080fd5b50519050858114610f02576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260548152602001806117486054913960600191505060405180910390fd5b60205463ffffffff11610f60576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806117276021913960400191505060405180910390fd5b602080546001019081905560005b60208110156110a9578160011660011415610fa0578260008260208110610f9157fe5b0155506110ac95505050505050565b600260008260208110610faf57fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061102557805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610fe8565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015611082573d6000803e3d6000fd5b5050506040513d602081101561109757600080fd5b50519250600282049150600101610f6e565b50fe5b50505050505050565b60606110c26020546114ba565b905090565b6020546000908190815b60208110156112f05781600116600114156111e6576002600082602081106110f557fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061116b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161112e565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa1580156111c8573d6000803e3d6000fd5b5050506040513d60208110156111dd57600080fd5b505192506112e2565b600283602183602081106111f657fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061126b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161122e565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa1580156112c8573d6000803e3d6000fd5b5050506040513d60208110156112dd57600080fd5b505192505b6002820491506001016110d1565b506002826112ff6020546114ba565b600060401b6040516020018084815260200183805190602001908083835b6020831061135a57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161131d565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790527fffffffffffffffffffffffffffffffffffffffffffffffff000000000000000095909516920191825250604080518083037ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8018152601890920190819052815191955093508392850191508083835b6020831061143f57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101611402565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa15801561149c573d6000803e3d6000fd5b5050506040513d60208110156114b157600080fd5b50519250505090565b60408051600880825281830190925260609160208201818036833701905050905060c082901b8060071a60f81b826000815181106114f457fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060061a60f81b8260018151811061153757fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060051a60f81b8260028151811061157a57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060041a60f81b826003815181106115bd57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060031a60f81b8260048151811061160057fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060021a60f81b8260058151811061164357fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060011a60f81b8260068151811061168657fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060001a60f81b826007815181106116c957fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535050919050565b6000808585111561170d578182fd5b83861115611719578182fd5b505082019391909203915056fe4465706f736974436f6e74726163743a206d65726b6c6520747265652066756c6c4465706f736974436f6e74726163743a207265636f6e7374727563746564204465706f7369744461746120646f6573206e6f74206d6174636820737570706c696564206465706f7369745f646174615f726f6f744465706f736974436f6e74726163743a20696e76616c6964207769746864726177616c5f63726564656e7469616c73206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c7565206e6f74206d756c7469706c65206f6620677765694465706f736974436f6e74726163743a20696e76616c6964207075626b6579206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f20686967684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f206c6f774465706f736974436f6e74726163743a20696e76616c6964207369676e6174757265206c656e677468a2646970667358221220335950bd2d98c278f0495488ea87d72639ff47d535be235dca97784b8d630c8964736f6c634300060b0033"} \ No newline at end of file +{"abi": [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"pubkey","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"withdrawal_credentials","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"amount","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"signature","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"index","type":"bytes"}],"name":"DepositEvent","type":"event"},{"inputs":[{"internalType":"bytes","name":"pubkey","type":"bytes"},{"internalType":"bytes","name":"withdrawal_credentials","type":"bytes"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"bytes32","name":"deposit_data_root","type":"bytes32"}],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"get_deposit_count","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"get_deposit_root","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}], "bytecode": "0x608060405234801561001057600080fd5b5060005b601f8110156101025760026021826020811061002c57fe5b01546021836020811061003b57fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b602083106100925780518252601f199092019160209182019101610073565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa1580156100d1573d6000803e3d6000fd5b5050506040513d60208110156100e657600080fd5b5051602160018301602081106100f857fe5b0155600101610014565b506118d680620001136000396000f3fe60806040526004361061003f5760003560e01c806301ffc9a71461004457806322895118146100a4578063621fd130146101ba578063c5f2892f14610244575b600080fd5b34801561005057600080fd5b506100906004803603602081101561006757600080fd5b50357fffffffff000000000000000000000000000000000000000000000000000000001661026b565b604080519115158252519081900360200190f35b6101b8600480360360808110156100ba57600080fd5b8101906020810181356401000000008111156100d557600080fd5b8201836020820111156100e757600080fd5b8035906020019184600183028401116401000000008311171561010957600080fd5b91939092909160208101903564010000000081111561012757600080fd5b82018360208201111561013957600080fd5b8035906020019184600183028401116401000000008311171561015b57600080fd5b91939092909160208101903564010000000081111561017957600080fd5b82018360208201111561018b57600080fd5b803590602001918460018302840111640100000000831117156101ad57600080fd5b919350915035610304565b005b3480156101c657600080fd5b506101cf6110b5565b6040805160208082528351818301528351919283929083019185019080838360005b838110156102095781810151838201526020016101f1565b50505050905090810190601f1680156102365780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561025057600080fd5b506102596110c7565b60408051918252519081900360200190f35b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f01ffc9a70000000000000000000000000000000000000000000000000000000014806102fe57507fffffffff0000000000000000000000000000000000000000000000000000000082167f8564090700000000000000000000000000000000000000000000000000000000145b92915050565b6030861461035d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806118056026913960400191505060405180910390fd5b602084146103b6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252603681526020018061179c6036913960400191505060405180910390fd5b6060821461040f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260298152602001806118786029913960400191505060405180910390fd5b670de0b6b3a7640000341015610470576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806118526026913960400191505060405180910390fd5b633b9aca003406156104cd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260338152602001806117d26033913960400191505060405180910390fd5b633b9aca00340467ffffffffffffffff811115610535576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602781526020018061182b6027913960400191505060405180910390fd5b6060610540826114ba565b90507f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c589898989858a8a6105756020546114ba565b6040805160a0808252810189905290819060208201908201606083016080840160c085018e8e80828437600083820152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690910187810386528c815260200190508c8c808284376000838201819052601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690920188810386528c5181528c51602091820193918e019250908190849084905b83811015610648578181015183820152602001610630565b50505050905090810190601f1680156106755780820380516001836020036101000a031916815260200191505b5086810383528881526020018989808284376000838201819052601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169092018881038452895181528951602091820193918b019250908190849084905b838110156106ef5781810151838201526020016106d7565b50505050905090810190601f16801561071c5780820380516001836020036101000a031916815260200191505b509d505050505050505050505050505060405180910390a1600060028a8a600060801b604051602001808484808284377fffffffffffffffffffffffffffffffff0000000000000000000000000000000090941691909301908152604080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0818403018152601090920190819052815191955093508392506020850191508083835b602083106107fc57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016107bf565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610859573d6000803e3d6000fd5b5050506040513d602081101561086e57600080fd5b5051905060006002806108846040848a8c6116fe565b6040516020018083838082843780830192505050925050506040516020818303038152906040526040518082805190602001908083835b602083106108f857805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016108bb565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610955573d6000803e3d6000fd5b5050506040513d602081101561096a57600080fd5b5051600261097b896040818d6116fe565b60405160009060200180848480828437919091019283525050604080518083038152602092830191829052805190945090925082918401908083835b602083106109f457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016109b7565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610a51573d6000803e3d6000fd5b5050506040513d6020811015610a6657600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610ada57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610a9d565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610b37573d6000803e3d6000fd5b5050506040513d6020811015610b4c57600080fd5b50516040805160208101858152929350600092600292839287928f928f92018383808284378083019250505093505050506040516020818303038152906040526040518082805190602001908083835b60208310610bd957805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610b9c565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610c36573d6000803e3d6000fd5b5050506040513d6020811015610c4b57600080fd5b50516040518651600291889160009188916020918201918291908601908083835b60208310610ca957805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610c6c565b6001836020036101000a0380198251168184511680821785525050505050509050018367ffffffffffffffff191667ffffffffffffffff1916815260180182815260200193505050506040516020818303038152906040526040518082805190602001908083835b60208310610d4e57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610d11565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610dab573d6000803e3d6000fd5b5050506040513d6020811015610dc057600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610e3457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610df7565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610e91573d6000803e3d6000fd5b5050506040513d6020811015610ea657600080fd5b50519050858114610f02576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260548152602001806117486054913960600191505060405180910390fd5b60205463ffffffff11610f60576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806117276021913960400191505060405180910390fd5b602080546001019081905560005b60208110156110a9578160011660011415610fa0578260008260208110610f9157fe5b0155506110ac95505050505050565b600260008260208110610faf57fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061102557805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610fe8565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015611082573d6000803e3d6000fd5b5050506040513d602081101561109757600080fd5b50519250600282049150600101610f6e565b50fe5b50505050505050565b60606110c26020546114ba565b905090565b6020546000908190815b60208110156112f05781600116600114156111e6576002600082602081106110f557fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061116b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161112e565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa1580156111c8573d6000803e3d6000fd5b5050506040513d60208110156111dd57600080fd5b505192506112e2565b600283602183602081106111f657fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061126b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161122e565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa1580156112c8573d6000803e3d6000fd5b5050506040513d60208110156112dd57600080fd5b505192505b6002820491506001016110d1565b506002826112ff6020546114ba565b600060401b6040516020018084815260200183805190602001908083835b6020831061135a57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161131d565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790527fffffffffffffffffffffffffffffffffffffffffffffffff000000000000000095909516920191825250604080518083037ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8018152601890920190819052815191955093508392850191508083835b6020831061143f57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101611402565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa15801561149c573d6000803e3d6000fd5b5050506040513d60208110156114b157600080fd5b50519250505090565b60408051600880825281830190925260609160208201818036833701905050905060c082901b8060071a60f81b826000815181106114f457fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060061a60f81b8260018151811061153757fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060051a60f81b8260028151811061157a57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060041a60f81b826003815181106115bd57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060031a60f81b8260048151811061160057fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060021a60f81b8260058151811061164357fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060011a60f81b8260068151811061168657fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060001a60f81b826007815181106116c957fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535050919050565b6000808585111561170d578182fd5b83861115611719578182fd5b505082019391909203915056fe4465706f736974436f6e74726163743a206d65726b6c6520747265652066756c6c4465706f736974436f6e74726163743a207265636f6e7374727563746564204465706f7369744461746120646f6573206e6f74206d6174636820737570706c696564206465706f7369745f646174615f726f6f744465706f736974436f6e74726163743a20696e76616c6964207769746864726177616c5f63726564656e7469616c73206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c7565206e6f74206d756c7469706c65206f6620677765694465706f736974436f6e74726163743a20696e76616c6964207075626b6579206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f20686967684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f206c6f774465706f736974436f6e74726163743a20696e76616c6964207369676e6174757265206c656e677468a2646970667358221220409ac756a5addf5c0c525435ecea8ac232c91ba1bb1339e0514b0638c7724a4e64736f6c634300060b0033"} \ No newline at end of file diff --git a/deposit_contract.sol b/deposit_contract.sol index a066bb10d..175c95897 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -77,8 +77,6 @@ contract DepositContract is IDepositContract, ERC165 { zero_hashes[height + 1] = sha256(abi.encodePacked(zero_hashes[height], zero_hashes[height])); } - /// @notice Query the current deposit root hash. - /// @return The deposit root hash. function get_deposit_root() override external view returns (bytes32) { bytes32 node; uint size = deposit_count; @@ -96,18 +94,10 @@ contract DepositContract is IDepositContract, ERC165 { )); } - /// @notice Query the current deposit count. - /// @return The deposit count encoded as a little endian 64-bit number. function get_deposit_count() override external view returns (bytes memory) { return to_little_endian_64(uint64(deposit_count)); } - /// @notice Submit a Phase 0 DepositData object. - /// @param pubkey A BLS12-381 public key. - /// @param withdrawal_credentials Commitment to a public key for withdrawals. - /// @param signature A BLS12-381 signature. - /// @param deposit_data_root The SHA-256 hash of the SSZ-encoded DepositData object. - /// Used as a protection against malformed input. function deposit( bytes calldata pubkey, bytes calldata withdrawal_credentials, From ed8e1cc9aa757443c13879158955e3828b2a8a3b Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Fri, 14 Aug 2020 04:31:56 +0800 Subject: [PATCH 49/69] Relicense from Apache2.0 to CC0-1.0 (#38) Also update binary output due to metadata change. Agreed by all authors, including @chriseth, @MrChico, and @axic. --- LICENSE | 278 +++++++++++++++--------------------------- deposit_contract.json | 2 +- deposit_contract.sol | 2 +- 3 files changed, 98 insertions(+), 184 deletions(-) diff --git a/LICENSE b/LICENSE index d64569567..670154e35 100644 --- a/LICENSE +++ b/LICENSE @@ -1,202 +1,116 @@ +CC0 1.0 Universal - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ +Statement of Purpose - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION +The laws of most jurisdictions throughout the world automatically confer +exclusive Copyright and Related Rights (defined below) upon the creator and +subsequent owner(s) (each and all, an "owner") of an original work of +authorship and/or a database (each, a "Work"). - 1. Definitions. +Certain owners wish to permanently relinquish those rights to a Work for the +purpose of contributing to a commons of creative, cultural and scientific +works ("Commons") that the public can reliably and without fear of later +claims of infringement build upon, modify, incorporate in other works, reuse +and redistribute as freely as possible in any form whatsoever and for any +purposes, including without limitation commercial purposes. These owners may +contribute to the Commons to promote the ideal of a free culture and the +further production of creative, cultural and scientific works, or to gain +reputation or greater distribution for their Work in part through the use and +efforts of others. - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. +For these and/or other purposes and motivations, and without any expectation +of additional consideration or compensation, the person associating CC0 with a +Work (the "Affirmer"), to the extent that he or she is an owner of Copyright +and Related Rights in the Work, voluntarily elects to apply CC0 to the Work +and publicly distribute the Work under its terms, with knowledge of his or her +Copyright and Related Rights in the Work and the meaning and intended legal +effect of CC0 on those rights. - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. +1. Copyright and Related Rights. A Work made available under CC0 may be +protected by copyright and related or neighboring rights ("Copyright and +Related Rights"). Copyright and Related Rights include, but are not limited +to, the following: - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. + i. the right to reproduce, adapt, distribute, perform, display, communicate, + and translate a Work; - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. + ii. moral rights retained by the original author(s) and/or performer(s); - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. + iii. publicity and privacy rights pertaining to a person's image or likeness + depicted in a Work; - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. + iv. rights protecting against unfair competition in regards to a Work, + subject to the limitations in paragraph 4(a), below; - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). + v. rights protecting the extraction, dissemination, use and reuse of data in + a Work; - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. + vi. database rights (such as those arising under Directive 96/9/EC of the + European Parliament and of the Council of 11 March 1996 on the legal + protection of databases, and under any national implementation thereof, + including any amended or successor version of such directive); and - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." + vii. other similar, equivalent or corresponding rights throughout the world + based on applicable law or treaty, and any national implementations thereof. - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. +2. Waiver. To the greatest extent permitted by, but not in contravention of, +applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and +unconditionally waives, abandons, and surrenders all of Affirmer's Copyright +and Related Rights and associated claims and causes of action, whether now +known or unknown (including existing as well as future claims and causes of +action), in the Work (i) in all territories worldwide, (ii) for the maximum +duration provided by applicable law or treaty (including future time +extensions), (iii) in any current or future medium and for any number of +copies, and (iv) for any purpose whatsoever, including without limitation +commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes +the Waiver for the benefit of each member of the public at large and to the +detriment of Affirmer's heirs and successors, fully intending that such Waiver +shall not be subject to revocation, rescission, cancellation, termination, or +any other legal or equitable action to disrupt the quiet enjoyment of the Work +by the public as contemplated by Affirmer's express Statement of Purpose. - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. +3. Public License Fallback. Should any part of the Waiver for any reason be +judged legally invalid or ineffective under applicable law, then the Waiver +shall be preserved to the maximum extent permitted taking into account +Affirmer's express Statement of Purpose. In addition, to the extent the Waiver +is so judged Affirmer hereby grants to each affected person a royalty-free, +non transferable, non sublicensable, non exclusive, irrevocable and +unconditional license to exercise Affirmer's Copyright and Related Rights in +the Work (i) in all territories worldwide, (ii) for the maximum duration +provided by applicable law or treaty (including future time extensions), (iii) +in any current or future medium and for any number of copies, and (iv) for any +purpose whatsoever, including without limitation commercial, advertising or +promotional purposes (the "License"). The License shall be deemed effective as +of the date CC0 was applied by Affirmer to the Work. Should any part of the +License for any reason be judged legally invalid or ineffective under +applicable law, such partial invalidity or ineffectiveness shall not +invalidate the remainder of the License, and in such case Affirmer hereby +affirms that he or she will not (i) exercise any of his or her remaining +Copyright and Related Rights in the Work or (ii) assert any associated claims +and causes of action with respect to the Work, in either case contrary to +Affirmer's express Statement of Purpose. - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. +4. Limitations and Disclaimers. - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: + a. No trademark or patent rights held by Affirmer are waived, abandoned, + surrendered, licensed or otherwise affected by this document. - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and + b. Affirmer offers the Work as-is and makes no representations or warranties + of any kind concerning the Work, express, implied, statutory or otherwise, + including without limitation warranties of title, merchantability, fitness + for a particular purpose, non infringement, or the absence of latent or + other defects, accuracy, or the present or absence of errors, whether or not + discoverable, all to the greatest extent permissible under applicable law. - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and + c. Affirmer disclaims responsibility for clearing rights of other persons + that may apply to the Work or any use thereof, including without limitation + any person's Copyright and Related Rights in the Work. Further, Affirmer + disclaims responsibility for obtaining any necessary consents, permissions + or other rights required for any use of the Work. - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and + d. Affirmer understands and acknowledges that Creative Commons is not a + party to this document and has no duty or obligation with respect to this + CC0 or use of the Work. - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +For more information, please see + diff --git a/deposit_contract.json b/deposit_contract.json index ecec0945c..060fe729c 100644 --- a/deposit_contract.json +++ b/deposit_contract.json @@ -1 +1 @@ -{"abi": [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"pubkey","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"withdrawal_credentials","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"amount","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"signature","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"index","type":"bytes"}],"name":"DepositEvent","type":"event"},{"inputs":[{"internalType":"bytes","name":"pubkey","type":"bytes"},{"internalType":"bytes","name":"withdrawal_credentials","type":"bytes"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"bytes32","name":"deposit_data_root","type":"bytes32"}],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"get_deposit_count","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"get_deposit_root","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}], "bytecode": "0x608060405234801561001057600080fd5b5060005b601f8110156101025760026021826020811061002c57fe5b01546021836020811061003b57fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b602083106100925780518252601f199092019160209182019101610073565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa1580156100d1573d6000803e3d6000fd5b5050506040513d60208110156100e657600080fd5b5051602160018301602081106100f857fe5b0155600101610014565b506118d680620001136000396000f3fe60806040526004361061003f5760003560e01c806301ffc9a71461004457806322895118146100a4578063621fd130146101ba578063c5f2892f14610244575b600080fd5b34801561005057600080fd5b506100906004803603602081101561006757600080fd5b50357fffffffff000000000000000000000000000000000000000000000000000000001661026b565b604080519115158252519081900360200190f35b6101b8600480360360808110156100ba57600080fd5b8101906020810181356401000000008111156100d557600080fd5b8201836020820111156100e757600080fd5b8035906020019184600183028401116401000000008311171561010957600080fd5b91939092909160208101903564010000000081111561012757600080fd5b82018360208201111561013957600080fd5b8035906020019184600183028401116401000000008311171561015b57600080fd5b91939092909160208101903564010000000081111561017957600080fd5b82018360208201111561018b57600080fd5b803590602001918460018302840111640100000000831117156101ad57600080fd5b919350915035610304565b005b3480156101c657600080fd5b506101cf6110b5565b6040805160208082528351818301528351919283929083019185019080838360005b838110156102095781810151838201526020016101f1565b50505050905090810190601f1680156102365780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561025057600080fd5b506102596110c7565b60408051918252519081900360200190f35b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f01ffc9a70000000000000000000000000000000000000000000000000000000014806102fe57507fffffffff0000000000000000000000000000000000000000000000000000000082167f8564090700000000000000000000000000000000000000000000000000000000145b92915050565b6030861461035d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806118056026913960400191505060405180910390fd5b602084146103b6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252603681526020018061179c6036913960400191505060405180910390fd5b6060821461040f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260298152602001806118786029913960400191505060405180910390fd5b670de0b6b3a7640000341015610470576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806118526026913960400191505060405180910390fd5b633b9aca003406156104cd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260338152602001806117d26033913960400191505060405180910390fd5b633b9aca00340467ffffffffffffffff811115610535576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602781526020018061182b6027913960400191505060405180910390fd5b6060610540826114ba565b90507f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c589898989858a8a6105756020546114ba565b6040805160a0808252810189905290819060208201908201606083016080840160c085018e8e80828437600083820152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690910187810386528c815260200190508c8c808284376000838201819052601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690920188810386528c5181528c51602091820193918e019250908190849084905b83811015610648578181015183820152602001610630565b50505050905090810190601f1680156106755780820380516001836020036101000a031916815260200191505b5086810383528881526020018989808284376000838201819052601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169092018881038452895181528951602091820193918b019250908190849084905b838110156106ef5781810151838201526020016106d7565b50505050905090810190601f16801561071c5780820380516001836020036101000a031916815260200191505b509d505050505050505050505050505060405180910390a1600060028a8a600060801b604051602001808484808284377fffffffffffffffffffffffffffffffff0000000000000000000000000000000090941691909301908152604080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0818403018152601090920190819052815191955093508392506020850191508083835b602083106107fc57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016107bf565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610859573d6000803e3d6000fd5b5050506040513d602081101561086e57600080fd5b5051905060006002806108846040848a8c6116fe565b6040516020018083838082843780830192505050925050506040516020818303038152906040526040518082805190602001908083835b602083106108f857805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016108bb565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610955573d6000803e3d6000fd5b5050506040513d602081101561096a57600080fd5b5051600261097b896040818d6116fe565b60405160009060200180848480828437919091019283525050604080518083038152602092830191829052805190945090925082918401908083835b602083106109f457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016109b7565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610a51573d6000803e3d6000fd5b5050506040513d6020811015610a6657600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610ada57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610a9d565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610b37573d6000803e3d6000fd5b5050506040513d6020811015610b4c57600080fd5b50516040805160208101858152929350600092600292839287928f928f92018383808284378083019250505093505050506040516020818303038152906040526040518082805190602001908083835b60208310610bd957805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610b9c565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610c36573d6000803e3d6000fd5b5050506040513d6020811015610c4b57600080fd5b50516040518651600291889160009188916020918201918291908601908083835b60208310610ca957805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610c6c565b6001836020036101000a0380198251168184511680821785525050505050509050018367ffffffffffffffff191667ffffffffffffffff1916815260180182815260200193505050506040516020818303038152906040526040518082805190602001908083835b60208310610d4e57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610d11565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610dab573d6000803e3d6000fd5b5050506040513d6020811015610dc057600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610e3457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610df7565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610e91573d6000803e3d6000fd5b5050506040513d6020811015610ea657600080fd5b50519050858114610f02576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260548152602001806117486054913960600191505060405180910390fd5b60205463ffffffff11610f60576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806117276021913960400191505060405180910390fd5b602080546001019081905560005b60208110156110a9578160011660011415610fa0578260008260208110610f9157fe5b0155506110ac95505050505050565b600260008260208110610faf57fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061102557805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610fe8565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015611082573d6000803e3d6000fd5b5050506040513d602081101561109757600080fd5b50519250600282049150600101610f6e565b50fe5b50505050505050565b60606110c26020546114ba565b905090565b6020546000908190815b60208110156112f05781600116600114156111e6576002600082602081106110f557fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061116b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161112e565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa1580156111c8573d6000803e3d6000fd5b5050506040513d60208110156111dd57600080fd5b505192506112e2565b600283602183602081106111f657fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061126b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161122e565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa1580156112c8573d6000803e3d6000fd5b5050506040513d60208110156112dd57600080fd5b505192505b6002820491506001016110d1565b506002826112ff6020546114ba565b600060401b6040516020018084815260200183805190602001908083835b6020831061135a57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161131d565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790527fffffffffffffffffffffffffffffffffffffffffffffffff000000000000000095909516920191825250604080518083037ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8018152601890920190819052815191955093508392850191508083835b6020831061143f57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101611402565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa15801561149c573d6000803e3d6000fd5b5050506040513d60208110156114b157600080fd5b50519250505090565b60408051600880825281830190925260609160208201818036833701905050905060c082901b8060071a60f81b826000815181106114f457fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060061a60f81b8260018151811061153757fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060051a60f81b8260028151811061157a57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060041a60f81b826003815181106115bd57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060031a60f81b8260048151811061160057fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060021a60f81b8260058151811061164357fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060011a60f81b8260068151811061168657fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060001a60f81b826007815181106116c957fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535050919050565b6000808585111561170d578182fd5b83861115611719578182fd5b505082019391909203915056fe4465706f736974436f6e74726163743a206d65726b6c6520747265652066756c6c4465706f736974436f6e74726163743a207265636f6e7374727563746564204465706f7369744461746120646f6573206e6f74206d6174636820737570706c696564206465706f7369745f646174615f726f6f744465706f736974436f6e74726163743a20696e76616c6964207769746864726177616c5f63726564656e7469616c73206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c7565206e6f74206d756c7469706c65206f6620677765694465706f736974436f6e74726163743a20696e76616c6964207075626b6579206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f20686967684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f206c6f774465706f736974436f6e74726163743a20696e76616c6964207369676e6174757265206c656e677468a2646970667358221220409ac756a5addf5c0c525435ecea8ac232c91ba1bb1339e0514b0638c7724a4e64736f6c634300060b0033"} \ No newline at end of file +{"abi": [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"pubkey","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"withdrawal_credentials","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"amount","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"signature","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"index","type":"bytes"}],"name":"DepositEvent","type":"event"},{"inputs":[{"internalType":"bytes","name":"pubkey","type":"bytes"},{"internalType":"bytes","name":"withdrawal_credentials","type":"bytes"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"bytes32","name":"deposit_data_root","type":"bytes32"}],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"get_deposit_count","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"get_deposit_root","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}], "bytecode": "0x608060405234801561001057600080fd5b5060005b601f8110156101025760026021826020811061002c57fe5b01546021836020811061003b57fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b602083106100925780518252601f199092019160209182019101610073565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa1580156100d1573d6000803e3d6000fd5b5050506040513d60208110156100e657600080fd5b5051602160018301602081106100f857fe5b0155600101610014565b506118d680620001136000396000f3fe60806040526004361061003f5760003560e01c806301ffc9a71461004457806322895118146100a4578063621fd130146101ba578063c5f2892f14610244575b600080fd5b34801561005057600080fd5b506100906004803603602081101561006757600080fd5b50357fffffffff000000000000000000000000000000000000000000000000000000001661026b565b604080519115158252519081900360200190f35b6101b8600480360360808110156100ba57600080fd5b8101906020810181356401000000008111156100d557600080fd5b8201836020820111156100e757600080fd5b8035906020019184600183028401116401000000008311171561010957600080fd5b91939092909160208101903564010000000081111561012757600080fd5b82018360208201111561013957600080fd5b8035906020019184600183028401116401000000008311171561015b57600080fd5b91939092909160208101903564010000000081111561017957600080fd5b82018360208201111561018b57600080fd5b803590602001918460018302840111640100000000831117156101ad57600080fd5b919350915035610304565b005b3480156101c657600080fd5b506101cf6110b5565b6040805160208082528351818301528351919283929083019185019080838360005b838110156102095781810151838201526020016101f1565b50505050905090810190601f1680156102365780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561025057600080fd5b506102596110c7565b60408051918252519081900360200190f35b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f01ffc9a70000000000000000000000000000000000000000000000000000000014806102fe57507fffffffff0000000000000000000000000000000000000000000000000000000082167f8564090700000000000000000000000000000000000000000000000000000000145b92915050565b6030861461035d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806118056026913960400191505060405180910390fd5b602084146103b6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252603681526020018061179c6036913960400191505060405180910390fd5b6060821461040f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260298152602001806118786029913960400191505060405180910390fd5b670de0b6b3a7640000341015610470576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806118526026913960400191505060405180910390fd5b633b9aca003406156104cd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260338152602001806117d26033913960400191505060405180910390fd5b633b9aca00340467ffffffffffffffff811115610535576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602781526020018061182b6027913960400191505060405180910390fd5b6060610540826114ba565b90507f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c589898989858a8a6105756020546114ba565b6040805160a0808252810189905290819060208201908201606083016080840160c085018e8e80828437600083820152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690910187810386528c815260200190508c8c808284376000838201819052601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690920188810386528c5181528c51602091820193918e019250908190849084905b83811015610648578181015183820152602001610630565b50505050905090810190601f1680156106755780820380516001836020036101000a031916815260200191505b5086810383528881526020018989808284376000838201819052601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169092018881038452895181528951602091820193918b019250908190849084905b838110156106ef5781810151838201526020016106d7565b50505050905090810190601f16801561071c5780820380516001836020036101000a031916815260200191505b509d505050505050505050505050505060405180910390a1600060028a8a600060801b604051602001808484808284377fffffffffffffffffffffffffffffffff0000000000000000000000000000000090941691909301908152604080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0818403018152601090920190819052815191955093508392506020850191508083835b602083106107fc57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016107bf565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610859573d6000803e3d6000fd5b5050506040513d602081101561086e57600080fd5b5051905060006002806108846040848a8c6116fe565b6040516020018083838082843780830192505050925050506040516020818303038152906040526040518082805190602001908083835b602083106108f857805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016108bb565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610955573d6000803e3d6000fd5b5050506040513d602081101561096a57600080fd5b5051600261097b896040818d6116fe565b60405160009060200180848480828437919091019283525050604080518083038152602092830191829052805190945090925082918401908083835b602083106109f457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016109b7565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610a51573d6000803e3d6000fd5b5050506040513d6020811015610a6657600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610ada57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610a9d565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610b37573d6000803e3d6000fd5b5050506040513d6020811015610b4c57600080fd5b50516040805160208101858152929350600092600292839287928f928f92018383808284378083019250505093505050506040516020818303038152906040526040518082805190602001908083835b60208310610bd957805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610b9c565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610c36573d6000803e3d6000fd5b5050506040513d6020811015610c4b57600080fd5b50516040518651600291889160009188916020918201918291908601908083835b60208310610ca957805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610c6c565b6001836020036101000a0380198251168184511680821785525050505050509050018367ffffffffffffffff191667ffffffffffffffff1916815260180182815260200193505050506040516020818303038152906040526040518082805190602001908083835b60208310610d4e57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610d11565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610dab573d6000803e3d6000fd5b5050506040513d6020811015610dc057600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610e3457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610df7565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610e91573d6000803e3d6000fd5b5050506040513d6020811015610ea657600080fd5b50519050858114610f02576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260548152602001806117486054913960600191505060405180910390fd5b60205463ffffffff11610f60576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806117276021913960400191505060405180910390fd5b602080546001019081905560005b60208110156110a9578160011660011415610fa0578260008260208110610f9157fe5b0155506110ac95505050505050565b600260008260208110610faf57fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061102557805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610fe8565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015611082573d6000803e3d6000fd5b5050506040513d602081101561109757600080fd5b50519250600282049150600101610f6e565b50fe5b50505050505050565b60606110c26020546114ba565b905090565b6020546000908190815b60208110156112f05781600116600114156111e6576002600082602081106110f557fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061116b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161112e565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa1580156111c8573d6000803e3d6000fd5b5050506040513d60208110156111dd57600080fd5b505192506112e2565b600283602183602081106111f657fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061126b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161122e565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa1580156112c8573d6000803e3d6000fd5b5050506040513d60208110156112dd57600080fd5b505192505b6002820491506001016110d1565b506002826112ff6020546114ba565b600060401b6040516020018084815260200183805190602001908083835b6020831061135a57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161131d565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790527fffffffffffffffffffffffffffffffffffffffffffffffff000000000000000095909516920191825250604080518083037ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8018152601890920190819052815191955093508392850191508083835b6020831061143f57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101611402565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa15801561149c573d6000803e3d6000fd5b5050506040513d60208110156114b157600080fd5b50519250505090565b60408051600880825281830190925260609160208201818036833701905050905060c082901b8060071a60f81b826000815181106114f457fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060061a60f81b8260018151811061153757fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060051a60f81b8260028151811061157a57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060041a60f81b826003815181106115bd57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060031a60f81b8260048151811061160057fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060021a60f81b8260058151811061164357fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060011a60f81b8260068151811061168657fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060001a60f81b826007815181106116c957fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535050919050565b6000808585111561170d578182fd5b83861115611719578182fd5b505082019391909203915056fe4465706f736974436f6e74726163743a206d65726b6c6520747265652066756c6c4465706f736974436f6e74726163743a207265636f6e7374727563746564204465706f7369744461746120646f6573206e6f74206d6174636820737570706c696564206465706f7369745f646174615f726f6f744465706f736974436f6e74726163743a20696e76616c6964207769746864726177616c5f63726564656e7469616c73206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c7565206e6f74206d756c7469706c65206f6620677765694465706f736974436f6e74726163743a20696e76616c6964207075626b6579206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f20686967684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f206c6f774465706f736974436f6e74726163743a20696e76616c6964207369676e6174757265206c656e677468a2646970667358221220dceca8706b29e917dacf25fceef95acac8d90d765ac926663ce4096195952b6164736f6c634300060b0033"} \ No newline at end of file diff --git a/deposit_contract.sol b/deposit_contract.sol index 175c95897..21d0b895a 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -7,7 +7,7 @@ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┃┃━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┗┛━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: CC0-1.0 pragma solidity 0.6.11; From e4a9c5fa29def20c4264cd860868f131d6f40e72 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Mon, 17 Aug 2020 22:05:05 +0800 Subject: [PATCH 50/69] Move files --- .gitattributes => solidity_deposit_contract/.gitattributes | 0 .gitmodules => solidity_deposit_contract/.gitmodules | 0 AUTHORS => solidity_deposit_contract/AUTHORS | 0 LICENSE => solidity_deposit_contract/LICENSE | 0 Makefile => solidity_deposit_contract/Makefile | 0 README.md => solidity_deposit_contract/README.md | 0 circle.yml => solidity_deposit_contract/circle.yml | 0 .../deposit_contract.json | 0 .../deposit_contract.sol | 0 {lib => solidity_deposit_contract/lib}/ds-test | 0 shell.nix => solidity_deposit_contract/shell.nix | 0 {tests => solidity_deposit_contract/tests}/deposit_contract.t.sol | 0 {tests => solidity_deposit_contract/tests}/vyper_setup.sol | 0 13 files changed, 0 insertions(+), 0 deletions(-) rename .gitattributes => solidity_deposit_contract/.gitattributes (100%) rename .gitmodules => solidity_deposit_contract/.gitmodules (100%) rename AUTHORS => solidity_deposit_contract/AUTHORS (100%) rename LICENSE => solidity_deposit_contract/LICENSE (100%) rename Makefile => solidity_deposit_contract/Makefile (100%) rename README.md => solidity_deposit_contract/README.md (100%) rename circle.yml => solidity_deposit_contract/circle.yml (100%) rename deposit_contract.json => solidity_deposit_contract/deposit_contract.json (100%) rename deposit_contract.sol => solidity_deposit_contract/deposit_contract.sol (100%) rename {lib => solidity_deposit_contract/lib}/ds-test (100%) rename shell.nix => solidity_deposit_contract/shell.nix (100%) rename {tests => solidity_deposit_contract/tests}/deposit_contract.t.sol (100%) rename {tests => solidity_deposit_contract/tests}/vyper_setup.sol (100%) diff --git a/.gitattributes b/solidity_deposit_contract/.gitattributes similarity index 100% rename from .gitattributes rename to solidity_deposit_contract/.gitattributes diff --git a/.gitmodules b/solidity_deposit_contract/.gitmodules similarity index 100% rename from .gitmodules rename to solidity_deposit_contract/.gitmodules diff --git a/AUTHORS b/solidity_deposit_contract/AUTHORS similarity index 100% rename from AUTHORS rename to solidity_deposit_contract/AUTHORS diff --git a/LICENSE b/solidity_deposit_contract/LICENSE similarity index 100% rename from LICENSE rename to solidity_deposit_contract/LICENSE diff --git a/Makefile b/solidity_deposit_contract/Makefile similarity index 100% rename from Makefile rename to solidity_deposit_contract/Makefile diff --git a/README.md b/solidity_deposit_contract/README.md similarity index 100% rename from README.md rename to solidity_deposit_contract/README.md diff --git a/circle.yml b/solidity_deposit_contract/circle.yml similarity index 100% rename from circle.yml rename to solidity_deposit_contract/circle.yml diff --git a/deposit_contract.json b/solidity_deposit_contract/deposit_contract.json similarity index 100% rename from deposit_contract.json rename to solidity_deposit_contract/deposit_contract.json diff --git a/deposit_contract.sol b/solidity_deposit_contract/deposit_contract.sol similarity index 100% rename from deposit_contract.sol rename to solidity_deposit_contract/deposit_contract.sol diff --git a/lib/ds-test b/solidity_deposit_contract/lib/ds-test similarity index 100% rename from lib/ds-test rename to solidity_deposit_contract/lib/ds-test diff --git a/shell.nix b/solidity_deposit_contract/shell.nix similarity index 100% rename from shell.nix rename to solidity_deposit_contract/shell.nix diff --git a/tests/deposit_contract.t.sol b/solidity_deposit_contract/tests/deposit_contract.t.sol similarity index 100% rename from tests/deposit_contract.t.sol rename to solidity_deposit_contract/tests/deposit_contract.t.sol diff --git a/tests/vyper_setup.sol b/solidity_deposit_contract/tests/vyper_setup.sol similarity index 100% rename from tests/vyper_setup.sol rename to solidity_deposit_contract/tests/vyper_setup.sol From 487d19ccb1ca5eec91a86a325b79d3ca09e7a534 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 23 Jul 2020 19:40:24 +0800 Subject: [PATCH 51/69] Fix typo --- solidity_deposit_contract/tests/deposit_contract.t.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solidity_deposit_contract/tests/deposit_contract.t.sol b/solidity_deposit_contract/tests/deposit_contract.t.sol index 5742bd934..c4a6718ba 100644 --- a/solidity_deposit_contract/tests/deposit_contract.t.sol +++ b/solidity_deposit_contract/tests/deposit_contract.t.sol @@ -18,7 +18,7 @@ contract DepositContractTest is DSTest { // --- SUCCESS TESTS --- - // Tests initilized storage values, comparing vyper and solidity + // Tests initialized storage values, comparing vyper and solidity function test_empty_root() public { bytes32 zHash = 0x0000000000000000000000000000000000000000000000000000000000000000; bytes32 zHashN = zHash; From 80fb1264017a204bdf95d32fa0a502446999cd2a Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 23 Jul 2020 22:16:40 +0800 Subject: [PATCH 52/69] WIP: add solidity deposit contract CI workflow Export `DAPP_LIB` Fix .gitmodules update CI solc version Kick cache Make metadata remain the same --- .circleci/config.yml | 145 ++++++++++++------ .gitattributes | 1 + .../.gitmodules => .gitmodules | 2 +- Makefile | 35 +++-- solidity_deposit_contract/.gitattributes | 1 - 5 files changed, 122 insertions(+), 62 deletions(-) rename solidity_deposit_contract/.gitmodules => .gitmodules (59%) delete mode 100644 solidity_deposit_contract/.gitattributes diff --git a/.circleci/config.yml b/.circleci/config.yml index 565b1c92f..a6931b17e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -145,54 +145,95 @@ jobs: - run: name: Run linter command: make lint - install_deposit_contract_compiler: +# install_deposit_contract_compiler: +# docker: +# # The deposit contract compiler is pinned to python 3.7 because of the vyper version pin. +# - image: circleci/python:3.7 +# working_directory: ~/specs-repo +# steps: +# - restore_cache: +# key: v3-specs-repo-{{ .Branch }}-{{ .Revision }} +# - restore_deposit_contract_compiler_cached_venv +# - run: +# name: Install deposit contract compiler requirements +# command: make install_deposit_contract_compiler +# - save_deposit_contract_compiler_cached_venv +# install_deposit_contract_tester: +# docker: +# - image: circleci/python:3.8 +# working_directory: ~/specs-repo +# steps: +# - restore_cache: +# key: v3-specs-repo-{{ .Branch }}-{{ .Revision }} +# - restore_deposit_contract_tester_cached_venv +# - run: +# name: Install deposit contract tester requirements +# command: make install_deposit_contract_tester +# - save_deposit_contract_tester_cached_venv +# test_compile_deposit_contract: +# docker: +# - image: circleci/python:3.7 +# working_directory: ~/specs-repo +# steps: +# - restore_cache: +# key: v3-specs-repo-{{ .Branch }}-{{ .Revision }} +# - restore_deposit_contract_compiler_cached_venv +# - run: +# name: Run deposit contract compile test +# command: make test_compile_deposit_contract +# test_deposit_contract: +# docker: +# - image: circleci/python:3.8 +# working_directory: ~/specs-repo +# steps: +# - restore_cache: +# key: v3-specs-repo-{{ .Branch }}-{{ .Revision }} +# - restore_deposit_contract_tester_cached_venv +# - run: +# name: Run deposit contract test +# command: make test_deposit_contract + build_deposit_contract: docker: - # The deposit contract compiler is pinned to python 3.7 because of the vyper version pin. - - image: circleci/python:3.7 - working_directory: ~/specs-repo + - image: ethereum/solc:0.6.11-alpine steps: - - restore_cache: - key: v3-specs-repo-{{ .Branch }}-{{ .Revision }} - - restore_deposit_contract_compiler_cached_venv + - checkout - run: - name: Install deposit contract compiler requirements - command: make install_deposit_contract_compiler - - save_deposit_contract_compiler_cached_venv - install_deposit_contract_tester: - docker: - - image: circleci/python:3.8 - working_directory: ~/specs-repo - steps: - - restore_cache: - key: v3-specs-repo-{{ .Branch }}-{{ .Revision }} - - restore_deposit_contract_tester_cached_venv + name: Install build essentials + command: | + apk update + apk add git make - run: - name: Install deposit contract tester requirements - command: make install_deposit_contract_tester - - save_deposit_contract_tester_cached_venv - test_compile_deposit_contract: - docker: - - image: circleci/python:3.7 - working_directory: ~/specs-repo - steps: - - restore_cache: - key: v3-specs-repo-{{ .Branch }}-{{ .Revision }} - - restore_deposit_contract_compiler_cached_venv - - run: - name: Run deposit contract compile test - command: make test_compile_deposit_contract + name: Compile the contract + command: | + make compile_deposit_contract + git diff --color --exit-code + - persist_to_workspace: + root: . + paths: + - ./solidity_deposit_contract/deposit_contract.json + - ./build/combined.json + - ./solidity_deposit_contract/lib test_deposit_contract: docker: - - image: circleci/python:3.8 - working_directory: ~/specs-repo + - image: nixorg/nix:circleci steps: + - checkout - restore_cache: - key: v3-specs-repo-{{ .Branch }}-{{ .Revision }} - - restore_deposit_contract_tester_cached_venv + key: nix-store-test-v2 + - attach_workspace: + at: /tmp/ - run: - name: Run deposit contract test - command: make test_deposit_contract - + name: Test the contract + command: | + mkdir build + cp -r /tmp/build/* build + cp -r /tmp/solidity_deposit_contract/lib/* ./solidity_deposit_contract/lib + cp -r /tmp/solidity_deposit_contract/deposit_contract.json ./solidity_deposit_contract/deposit_contract.json + nix-shell --command 'make test_deposit_contract' ./solidity_deposit_contract/shell.nix + - save_cache: + key: nix-store-test-v2 + paths: + - /nix workflows: version: 2.1 test_spec: @@ -209,15 +250,21 @@ workflows: - lint: requires: - test - - install_deposit_contract_compiler: - requires: - - checkout_specs - - test_compile_deposit_contract: - requires: - - install_deposit_contract_compiler - - install_deposit_contract_tester: - requires: - - checkout_specs + # - install_deposit_contract_compiler: + # requires: + # - checkout_specs + # - test_compile_deposit_contract: + # requires: + # - install_deposit_contract_compiler + # - install_deposit_contract_tester: + # requires: + # - checkout_specs + # - test_deposit_contract: + # requires: + # - install_deposit_contract_tester + build_and_test_deposit_contract: + jobs: + - build_deposit_contract - test_deposit_contract: requires: - - install_deposit_contract_tester + - build_deposit_contract diff --git a/.gitattributes b/.gitattributes index c2b17bf1a..97437110d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ *.vy linguist-language=Python +*.sol linguist-language=Solidity diff --git a/solidity_deposit_contract/.gitmodules b/.gitmodules similarity index 59% rename from solidity_deposit_contract/.gitmodules rename to .gitmodules index e12471968..6fcad6b97 100644 --- a/solidity_deposit_contract/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "lib/ds-test"] - path = lib/ds-test + path = solidity_deposit_contract/lib/ds-test url = https://github.com/dapphub/ds-test diff --git a/Makefile b/Makefile index f5cb1c702..52825a3eb 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,9 @@ TEST_VECTOR_DIR = ../eth2.0-spec-tests/tests GENERATOR_DIR = ./tests/generators DEPOSIT_CONTRACT_COMPILER_DIR = ./deposit_contract/compiler DEPOSIT_CONTRACT_TESTER_DIR = ./deposit_contract/tester +SOLIDITY_DEPOSIT_CONTRACT_DIR = ./solidity_deposit_contract +SOLIDITY_DEPOSIT_CONTRACT_SOURCE = ${SOLIDITY_DEPOSIT_CONTRACT_DIR}/deposit_contract.sol +SOLIDITY_FILE_NAME = deposit_contract.json CONFIGS_DIR = ./configs # Collect a list of generator names @@ -25,6 +28,11 @@ COV_INDEX_FILE=$(PY_SPEC_DIR)/$(COV_HTML_OUT)/index.html CURRENT_DIR = ${CURDIR} LINTER_CONFIG_FILE = $(CURRENT_DIR)/linter.ini +export DAPP_SKIP_BUILD:=1 +export DAPP_SRC:=$(SOLIDITY_DEPOSIT_CONTRACT_DIR) +export DAPP_LIB:=$(SOLIDITY_DEPOSIT_CONTRACT_DIR)/lib +export DAPP_JSON:=build/combined.json + .PHONY: clean partial_clean all test citest lint generate_tests pyspec install_test open_cov \ install_deposit_contract_tester test_deposit_contract install_deposit_contract_compiler \ compile_deposit_contract test_compile_deposit_contract check_toc @@ -107,23 +115,28 @@ lint: pyspec flake8 --config $(LINTER_CONFIG_FILE) ./eth2spec \ && mypy --config-file $(LINTER_CONFIG_FILE) -p eth2spec.phase0 -p eth2spec.phase1 -install_deposit_contract_tester: - cd $(DEPOSIT_CONTRACT_TESTER_DIR); python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements.txt +# install_deposit_contract_tester: +# cd $(DEPOSIT_CONTRACT_TESTER_DIR); python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements.txt test_deposit_contract: - cd $(DEPOSIT_CONTRACT_TESTER_DIR); . venv/bin/activate; \ - python -m pytest . + dapp test -v --fuzz-runs 5 -install_deposit_contract_compiler: - cd $(DEPOSIT_CONTRACT_COMPILER_DIR); python3.7 -m venv venv; . venv/bin/activate; pip3.7 install -r requirements.txt +# install_deposit_contract_compiler: +# cd $(DEPOSIT_CONTRACT_COMPILER_DIR); python3.7 -m venv venv; . venv/bin/activate; pip3.7 install -r requirements.txt compile_deposit_contract: - cd $(DEPOSIT_CONTRACT_COMPILER_DIR); . venv/bin/activate; \ - python3.7 deposit_contract/compile.py ../contracts/validator_registration.vy + @cd $(SOLIDITY_DEPOSIT_CONTRACT_DIR) + @git submodule update --recursive --init + @solc --metadata-literal --optimize --optimize-runs 5000000 --bin --abi --combined-json=abi,bin,bin-runtime,srcmap,srcmap-runtime,ast,metadata,storage-layout --overwrite -o build $(SOLIDITY_DEPOSIT_CONTRACT_SOURCE) $(SOLIDITY_DEPOSIT_CONTRACT_DIR)/tests/deposit_contract.t.sol + @/bin/echo -n '{"abi": ' > $(SOLIDITY_FILE_NAME) + @cat build/DepositContract.abi >> $(SOLIDITY_FILE_NAME) + @/bin/echo -n ', "bytecode": "0x' >> $(SOLIDITY_FILE_NAME) + @cat build/DepositContract.bin >> $(SOLIDITY_FILE_NAME) + @/bin/echo -n '"}' >> $(SOLIDITY_FILE_NAME) -test_compile_deposit_contract: - cd $(DEPOSIT_CONTRACT_COMPILER_DIR); . venv/bin/activate; \ - python3.7 -m pytest . +# test_compile_deposit_contract: +# cd $(DEPOSIT_CONTRACT_COMPILER_DIR); . venv/bin/activate; \ +# python3.7 -m pytest . # Runs a generator, identified by param 1 define run_generator diff --git a/solidity_deposit_contract/.gitattributes b/solidity_deposit_contract/.gitattributes deleted file mode 100644 index 52031de51..000000000 --- a/solidity_deposit_contract/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -*.sol linguist-language=Solidity From cd22036c532f5a9eb79604a38826c72f38677430 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Mon, 17 Aug 2020 23:56:24 +0800 Subject: [PATCH 53/69] Move files --- .../web3_tester}/requirements.txt | 0 .../tester => solidity_deposit_contract/web3_tester}/setup.py | 0 .../web3_tester/tests}/__init__.py | 0 .../web3_tester/tests}/conftest.py | 0 .../web3_tester/tests}/test_deposit.py | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename {deposit_contract/tester => solidity_deposit_contract/web3_tester}/requirements.txt (100%) rename {deposit_contract/tester => solidity_deposit_contract/web3_tester}/setup.py (100%) rename {deposit_contract/tester/deposit_contract => solidity_deposit_contract/web3_tester/tests}/__init__.py (100%) rename {deposit_contract/tester/deposit_contract => solidity_deposit_contract/web3_tester/tests}/conftest.py (100%) rename {deposit_contract/tester/deposit_contract => solidity_deposit_contract/web3_tester/tests}/test_deposit.py (100%) diff --git a/deposit_contract/tester/requirements.txt b/solidity_deposit_contract/web3_tester/requirements.txt similarity index 100% rename from deposit_contract/tester/requirements.txt rename to solidity_deposit_contract/web3_tester/requirements.txt diff --git a/deposit_contract/tester/setup.py b/solidity_deposit_contract/web3_tester/setup.py similarity index 100% rename from deposit_contract/tester/setup.py rename to solidity_deposit_contract/web3_tester/setup.py diff --git a/deposit_contract/tester/deposit_contract/__init__.py b/solidity_deposit_contract/web3_tester/tests/__init__.py similarity index 100% rename from deposit_contract/tester/deposit_contract/__init__.py rename to solidity_deposit_contract/web3_tester/tests/__init__.py diff --git a/deposit_contract/tester/deposit_contract/conftest.py b/solidity_deposit_contract/web3_tester/tests/conftest.py similarity index 100% rename from deposit_contract/tester/deposit_contract/conftest.py rename to solidity_deposit_contract/web3_tester/tests/conftest.py diff --git a/deposit_contract/tester/deposit_contract/test_deposit.py b/solidity_deposit_contract/web3_tester/tests/test_deposit.py similarity index 100% rename from deposit_contract/tester/deposit_contract/test_deposit.py rename to solidity_deposit_contract/web3_tester/tests/test_deposit.py From 377b2e3f833209839eea382e2d3087b9f6fa2278 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Tue, 18 Aug 2020 00:10:28 +0800 Subject: [PATCH 54/69] Clean up the CI workflow, enable web3.py tests --- .circleci/config.yml | 111 ++++++------------ Makefile | 23 ++-- .../web3_tester/tests/conftest.py | 2 +- .../web3_tester/tests/test_deposit.py | 2 +- 4 files changed, 46 insertions(+), 92 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a6931b17e..df415f2eb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -44,32 +44,19 @@ commands: venv_name: v22-pyspec reqs_checksum: cache-{{ checksum "setup.py" }} venv_path: ./venv - restore_deposit_contract_compiler_cached_venv: - description: "Restore the venv from cache for the deposit contract compiler" - steps: - - restore_cached_venv: - venv_name: v23-deposit-contract-compiler - reqs_checksum: cache-{{ checksum "deposit_contract/compiler/requirements.txt" }} - save_deposit_contract_compiler_cached_venv: - description: "Save the venv to cache for later use of the deposit contract compiler" - steps: - - save_cached_venv: - venv_name: v23-deposit-contract-compiler - reqs_checksum: cache-{{ checksum "deposit_contract/compiler/requirements.txt" }} - venv_path: ./deposit_contract/compiler/venv restore_deposit_contract_tester_cached_venv: description: "Restore the venv from cache for the deposit contract tester" steps: - restore_cached_venv: - venv_name: v22-deposit-contract-tester - reqs_checksum: cache-{{ checksum "setup.py" }}-{{ checksum "deposit_contract/tester/requirements.txt" }} + venv_name: v23-deposit-contract-tester + reqs_checksum: cache-{{ checksum "setup.py" }}-{{ checksum "solidity_deposit_contract/web3_tester/requirements.txt" }} save_deposit_contract_tester_cached_venv: description: "Save the venv to cache for later use of the deposit contract tester" steps: - save_cached_venv: - venv_name: v22-deposit-contract-tester - reqs_checksum: cache-{{ checksum "setup.py" }}-{{ checksum "deposit_contract/tester/requirements.txt" }} - venv_path: ./deposit_contract/tester/venv + venv_name: v23-deposit-contract-tester + reqs_checksum: cache-{{ checksum "setup.py" }}-{{ checksum "solidity_deposit_contract/web3_tester/requirements.txt" }} + venv_path: ./solidity_deposit_contract/web3_tester/venv jobs: checkout_specs: docker: @@ -145,53 +132,6 @@ jobs: - run: name: Run linter command: make lint -# install_deposit_contract_compiler: -# docker: -# # The deposit contract compiler is pinned to python 3.7 because of the vyper version pin. -# - image: circleci/python:3.7 -# working_directory: ~/specs-repo -# steps: -# - restore_cache: -# key: v3-specs-repo-{{ .Branch }}-{{ .Revision }} -# - restore_deposit_contract_compiler_cached_venv -# - run: -# name: Install deposit contract compiler requirements -# command: make install_deposit_contract_compiler -# - save_deposit_contract_compiler_cached_venv -# install_deposit_contract_tester: -# docker: -# - image: circleci/python:3.8 -# working_directory: ~/specs-repo -# steps: -# - restore_cache: -# key: v3-specs-repo-{{ .Branch }}-{{ .Revision }} -# - restore_deposit_contract_tester_cached_venv -# - run: -# name: Install deposit contract tester requirements -# command: make install_deposit_contract_tester -# - save_deposit_contract_tester_cached_venv -# test_compile_deposit_contract: -# docker: -# - image: circleci/python:3.7 -# working_directory: ~/specs-repo -# steps: -# - restore_cache: -# key: v3-specs-repo-{{ .Branch }}-{{ .Revision }} -# - restore_deposit_contract_compiler_cached_venv -# - run: -# name: Run deposit contract compile test -# command: make test_compile_deposit_contract -# test_deposit_contract: -# docker: -# - image: circleci/python:3.8 -# working_directory: ~/specs-repo -# steps: -# - restore_cache: -# key: v3-specs-repo-{{ .Branch }}-{{ .Revision }} -# - restore_deposit_contract_tester_cached_venv -# - run: -# name: Run deposit contract test -# command: make test_deposit_contract build_deposit_contract: docker: - image: ethereum/solc:0.6.11-alpine @@ -234,6 +174,29 @@ jobs: key: nix-store-test-v2 paths: - /nix + install_deposit_contract_web3_tester: + docker: + - image: circleci/python:3.8 + working_directory: ~/specs-repo + steps: + - restore_cache: + key: v3-specs-repo-{{ .Branch }}-{{ .Revision }} + - restore_deposit_contract_tester_cached_venv + - run: + name: Install deposit contract tester requirements + command: make install_deposit_contract_web3_tester + - save_deposit_contract_tester_cached_venv + test_deposit_contract_web3_tests: + docker: + - image: circleci/python:3.8 + working_directory: ~/specs-repo + steps: + - restore_cache: + key: v3-specs-repo-{{ .Branch }}-{{ .Revision }} + - restore_deposit_contract_tester_cached_venv + - run: + name: Run deposit contract test with web3.py + command: make test_deposit_contract_web3_tests workflows: version: 2.1 test_spec: @@ -250,18 +213,12 @@ workflows: - lint: requires: - test - # - install_deposit_contract_compiler: - # requires: - # - checkout_specs - # - test_compile_deposit_contract: - # requires: - # - install_deposit_contract_compiler - # - install_deposit_contract_tester: - # requires: - # - checkout_specs - # - test_deposit_contract: - # requires: - # - install_deposit_contract_tester + - install_deposit_contract_web3_tester: + requires: + - checkout_specs + - test_deposit_contract_web3_tests: + requires: + - install_deposit_contract_web3_tester build_and_test_deposit_contract: jobs: - build_deposit_contract diff --git a/Makefile b/Makefile index 52825a3eb..4f6a98be7 100644 --- a/Makefile +++ b/Makefile @@ -5,10 +5,10 @@ PY_SPEC_DIR = $(TEST_LIBS_DIR)/pyspec TEST_VECTOR_DIR = ../eth2.0-spec-tests/tests GENERATOR_DIR = ./tests/generators DEPOSIT_CONTRACT_COMPILER_DIR = ./deposit_contract/compiler -DEPOSIT_CONTRACT_TESTER_DIR = ./deposit_contract/tester SOLIDITY_DEPOSIT_CONTRACT_DIR = ./solidity_deposit_contract SOLIDITY_DEPOSIT_CONTRACT_SOURCE = ${SOLIDITY_DEPOSIT_CONTRACT_DIR}/deposit_contract.sol SOLIDITY_FILE_NAME = deposit_contract.json +DEPOSIT_CONTRACT_TESTER_DIR = ${SOLIDITY_DEPOSIT_CONTRACT_DIR}/web3_tester CONFIGS_DIR = ./configs # Collect a list of generator names @@ -115,15 +115,6 @@ lint: pyspec flake8 --config $(LINTER_CONFIG_FILE) ./eth2spec \ && mypy --config-file $(LINTER_CONFIG_FILE) -p eth2spec.phase0 -p eth2spec.phase1 -# install_deposit_contract_tester: -# cd $(DEPOSIT_CONTRACT_TESTER_DIR); python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements.txt - -test_deposit_contract: - dapp test -v --fuzz-runs 5 - -# install_deposit_contract_compiler: -# cd $(DEPOSIT_CONTRACT_COMPILER_DIR); python3.7 -m venv venv; . venv/bin/activate; pip3.7 install -r requirements.txt - compile_deposit_contract: @cd $(SOLIDITY_DEPOSIT_CONTRACT_DIR) @git submodule update --recursive --init @@ -134,9 +125,15 @@ compile_deposit_contract: @cat build/DepositContract.bin >> $(SOLIDITY_FILE_NAME) @/bin/echo -n '"}' >> $(SOLIDITY_FILE_NAME) -# test_compile_deposit_contract: -# cd $(DEPOSIT_CONTRACT_COMPILER_DIR); . venv/bin/activate; \ -# python3.7 -m pytest . +test_deposit_contract: + dapp test -v --fuzz-runs 5 + +install_deposit_contract_web3_tester: + cd $(DEPOSIT_CONTRACT_TESTER_DIR); python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements.txt + +test_deposit_contract_web3_tests: + cd $(DEPOSIT_CONTRACT_TESTER_DIR); . venv/bin/activate; \ + python -m pytest . # Runs a generator, identified by param 1 define run_generator diff --git a/solidity_deposit_contract/web3_tester/tests/conftest.py b/solidity_deposit_contract/web3_tester/tests/conftest.py index c20501b11..57b5f6b7a 100644 --- a/solidity_deposit_contract/web3_tester/tests/conftest.py +++ b/solidity_deposit_contract/web3_tester/tests/conftest.py @@ -15,7 +15,7 @@ DIR = os.path.dirname(__file__) def get_deposit_contract_json(): - file_path = os.path.join(DIR, '../../contracts/validator_registration.json') + file_path = os.path.join(DIR, '../../deposit_contract.json') deposit_contract_json = open(file_path).read() return json.loads(deposit_contract_json) diff --git a/solidity_deposit_contract/web3_tester/tests/test_deposit.py b/solidity_deposit_contract/web3_tester/tests/test_deposit.py index 5fa98e232..4b16446a1 100644 --- a/solidity_deposit_contract/web3_tester/tests/test_deposit.py +++ b/solidity_deposit_contract/web3_tester/tests/test_deposit.py @@ -6,7 +6,7 @@ from eth2spec.phase0.spec import DepositData from eth2spec.utils.ssz.ssz_typing import List from eth2spec.utils.ssz.ssz_impl import hash_tree_root -from deposit_contract.conftest import ( +from tests.conftest import ( FULL_DEPOSIT_AMOUNT, MIN_DEPOSIT_AMOUNT, ) From 094dd1470f804f09f0767a574538a666ba2719b3 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Tue, 18 Aug 2020 00:20:20 +0800 Subject: [PATCH 55/69] Cleaning --- Makefile | 2 +- deposit_contract/README.md | 38 ------ .../compiler/deposit_contract/__init__.py | 0 .../compiler/deposit_contract/compile.py | 31 ----- .../compiler/deposit_contract/test_compile.py | 29 ----- deposit_contract/compiler/requirements.txt | 7 -- deposit_contract/compiler/setup.py | 10 -- .../contracts/validator_registration.json | 1 - .../contracts/validator_registration.vy | 110 ----------------- solidity_deposit_contract/LICENSE | 116 ------------------ solidity_deposit_contract/Makefile | 22 ---- solidity_deposit_contract/README.md | 14 +-- solidity_deposit_contract/circle.yml | 77 ------------ .../tests/vyper_setup.sol | 2 +- 14 files changed, 6 insertions(+), 453 deletions(-) delete mode 100644 deposit_contract/README.md delete mode 100644 deposit_contract/compiler/deposit_contract/__init__.py delete mode 100644 deposit_contract/compiler/deposit_contract/compile.py delete mode 100644 deposit_contract/compiler/deposit_contract/test_compile.py delete mode 100644 deposit_contract/compiler/requirements.txt delete mode 100644 deposit_contract/compiler/setup.py delete mode 100644 deposit_contract/contracts/validator_registration.json delete mode 100644 deposit_contract/contracts/validator_registration.vy delete mode 100644 solidity_deposit_contract/LICENSE delete mode 100644 solidity_deposit_contract/Makefile delete mode 100644 solidity_deposit_contract/circle.yml diff --git a/Makefile b/Makefile index 4f6a98be7..1282401e8 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,7 @@ partial_clean: rm -rf $(PY_SPEC_DIR)/.coverage rm -rf $(PY_SPEC_DIR)/test-reports rm -rf eth2spec.egg-info dist build - + rm -rf build clean: partial_clean rm -rf venv diff --git a/deposit_contract/README.md b/deposit_contract/README.md deleted file mode 100644 index e7ec591e5..000000000 --- a/deposit_contract/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# Deposit contract - -## How to set up the testing environment? - -Under the `eth2.0-specs` directory, execute: - -```sh -make install_deposit_contract_tester -``` - -## How to compile the contract? - -```sh -make compile_deposit_contract -``` - -The compiler dependencies can be installed with: - -```sh -make install_deposit_contract_compiler -``` - -Note that this requires python 3.7 to be installed. The pinned vyper version will not work on 3.8. - -The ABI and bytecode will be updated at [`contracts/validator_registration.json`](./contracts/validator_registration.json). - - -## How to run tests? - -For running the contract tests: -```sh -make test_deposit_contract -``` - -For testing the compiler output against the expected formally-verified bytecode: -```sh -make test_compile_deposit_contract -``` diff --git a/deposit_contract/compiler/deposit_contract/__init__.py b/deposit_contract/compiler/deposit_contract/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/deposit_contract/compiler/deposit_contract/compile.py b/deposit_contract/compiler/deposit_contract/compile.py deleted file mode 100644 index 6d6781878..000000000 --- a/deposit_contract/compiler/deposit_contract/compile.py +++ /dev/null @@ -1,31 +0,0 @@ -import argparse -import json -import os - -from vyper import compiler - -DIR = os.path.dirname(__file__) - - -def generate_compiled_json(file_path: str): - deposit_contract_code = open(file_path).read() - abi = compiler.mk_full_signature(deposit_contract_code) - bytecode = compiler.compile_code(deposit_contract_code)['bytecode'] - contract_json = { - 'abi': abi, - 'bytecode': bytecode, - } - # write json - basename = os.path.basename(file_path) - dirname = os.path.dirname(file_path) - contract_name = basename.split('.')[0] - with open(dirname + "/{}.json".format(contract_name), 'w') as f_write: - json.dump(contract_json, f_write) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument("path", type=str, help="the path of the contract") - args = parser.parse_args() - path = args.path - generate_compiled_json(path) diff --git a/deposit_contract/compiler/deposit_contract/test_compile.py b/deposit_contract/compiler/deposit_contract/test_compile.py deleted file mode 100644 index 6922cf80c..000000000 --- a/deposit_contract/compiler/deposit_contract/test_compile.py +++ /dev/null @@ -1,29 +0,0 @@ -from vyper import compiler - -import json -import os - -DIR = os.path.dirname(__file__) - - -def get_deposit_contract_code(): - file_path = os.path.join(DIR, '../../contracts/validator_registration.vy') - deposit_contract_code = open(file_path).read() - return deposit_contract_code - - -def get_deposit_contract_json(): - file_path = os.path.join(DIR, '../../contracts/validator_registration.json') - deposit_contract_json = open(file_path).read() - return json.loads(deposit_contract_json) - - -def test_compile_deposit_contract(): - compiled_deposit_contract_json = get_deposit_contract_json() - - deposit_contract_code = get_deposit_contract_code() - abi = compiler.mk_full_signature(deposit_contract_code) - bytecode = compiler.compile_code(deposit_contract_code)['bytecode'] - - assert abi == compiled_deposit_contract_json["abi"] - assert bytecode == compiled_deposit_contract_json["bytecode"] diff --git a/deposit_contract/compiler/requirements.txt b/deposit_contract/compiler/requirements.txt deleted file mode 100644 index 209d43012..000000000 --- a/deposit_contract/compiler/requirements.txt +++ /dev/null @@ -1,7 +0,0 @@ -# Vyper beta version used to generate the bytecode that was then formally verified. -# On top of this beta version, a later change was backported, and included in the formal verification: -# https://github.com/vyperlang/vyper/issues/1761 -# The resulting vyper version is pinned and maintained as protected branch. -git+https://github.com/vyperlang/vyper@1761-HOTFIX-v0.1.0-beta.13 - -pytest==3.6.1 diff --git a/deposit_contract/compiler/setup.py b/deposit_contract/compiler/setup.py deleted file mode 100644 index add6d8043..000000000 --- a/deposit_contract/compiler/setup.py +++ /dev/null @@ -1,10 +0,0 @@ -from distutils.core import setup - -setup( - name='deposit_contract_compiler', - packages=['deposit_contract'], - package_dir={"": "."}, - python_requires="3.7", # pinned vyper compiler stops working after 3.7. See vyper issue 1835. - tests_requires=["pytest==3.6.1"], - install_requires=[], # see requirements.txt file -) diff --git a/deposit_contract/contracts/validator_registration.json b/deposit_contract/contracts/validator_registration.json deleted file mode 100644 index 12cfd74ac..000000000 --- a/deposit_contract/contracts/validator_registration.json +++ /dev/null @@ -1 +0,0 @@ -{"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": 95628}, {"name": "get_deposit_count", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 18231}, {"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": 1342274}], "bytecode": "0x740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009857600080fd5b6101406000601f818352015b600061014051602081106100b757600080fd5b600260c052602060c020015460208261016001015260208101905061014051602081106100e357600080fd5b600260c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012157600080fd5b60c0519050606051600161014051018060405190131561014057600080fd5b809190121561014e57600080fd5b6020811061015b57600080fd5b600260c052602060c02001555b81516001018083528114156100a4575b505061123556600436101561000d576110b0565b600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a05260001561027f575b6101605261014052600061018052610140516101a0526101c060006008818352015b61018051600860008112156100e8578060000360020a82046100ef565b8060020a82025b905090506101805260ff6101a051166101e052610180516101e0516101805101101561011a57600080fd5b6101e0516101805101610180526101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff86000811215610163578060000360020a820461016a565b8060020a82025b905090506101a0525b81516001018083528114156100cb575b5050601860086020820661020001602082840111156101a157600080fd5b60208061022082610180600060045af15050818152809050905090508051602001806102c08284600060045af16101d757600080fd5b50506102c05160206001820306601f82010390506103206102c0516020818352015b826103205110151561020a57610226565b6000610320516102e001535b81516001018083528114156101f9575b50505060206102a05260406102c0510160206001820306601f8201039050610280525b60006102805111151561025b57610277565b602061028051036102a001516020610280510361028052610249565b610160515650005b63c5f2892f600051141561050e57341561029857600080fd5b6000610140526101405161016052600154610180526101a060006020818352015b600160016101805116141561033a5760006101a051602081106102db57600080fd5b600060c052602060c02001546020826102400101526020810190506101605160208261024001015260208101905080610240526102409050602060c0825160208401600060025af161032c57600080fd5b60c0519050610160526103a8565b6000610160516020826101c00101526020810190506101a0516020811061036057600080fd5b600260c052602060c02001546020826101c0010152602081019050806101c0526101c09050602060c0825160208401600060025af161039e57600080fd5b60c0519050610160525b61018060026103b657600080fd5b60028151048152505b81516001018083528114156102b9575b505060006101605160208261046001015260208101905061014051610160516101805163806732896102e0526001546103005261030051600658016100a9565b506103605260006103c0525b6103605160206001820306601f82010390506103c05110151561043d57610456565b6103c05161038001526103c0516020016103c05261041b565b61018052610160526101405261036060088060208461046001018260208501600060045af150508051820191505060006018602082066103e001602082840111156104a057600080fd5b60208061040082610140600060045af150508181528090509050905060188060208461046001018260208501600060045af150508051820191505080610460526104609050602060c0825160208401600060025af16104fe57600080fd5b60c051905060005260206000f350005b63621fd130600051141561061c57341561052757600080fd5b6380673289610140526001546101605261016051600658016100a9565b506101c0526000610220525b6101c05160206001820306601f8201039050610220511015156105725761058b565b610220516101e001526102205160200161022052610550565b6101c08051602001806102808284600060045af16105a857600080fd5b50506102805160206001820306601f82010390506102e0610280516020818352015b826102e0511015156105db576105f7565b60006102e0516102a001535b81516001018083528114156105ca575b5050506020610260526040610280510160206001820306601f8201039050610260f350005b632289511860005114156110af57605060043560040161014037603060043560040135111561064a57600080fd5b60406024356004016101c037602060243560040135111561066a57600080fd5b608060443560040161022037606060443560040135111561068a57600080fd5b63ffffffff6001541061069c57600080fd5b633b9aca006102e0526102e0516106b257600080fd5b6102e05134046102c052633b9aca006102c05110156106d057600080fd5b603061014051146106e057600080fd5b60206101c051146106f057600080fd5b6060610220511461070057600080fd5b610140610360525b6103605151602061036051016103605261036061036051101561072a57610708565b6380673289610380526102c0516103a0526103a051600658016100a9565b50610400526000610460525b6104005160206001820306601f8201039050610460511015156107765761078f565b6104605161042001526104605160200161046052610754565b610340610360525b61036051526020610360510361036052610140610360511015156107ba57610797565b6104008051602001806103008284600060045af16107d757600080fd5b5050610140610480525b61048051516020610480510161048052610480610480511015610803576107e1565b63806732896104a0526001546104c0526104c051600658016100a9565b50610520526000610580525b6105205160206001820306601f82010390506105805110151561084e57610867565b610580516105400152610580516020016105805261082c565b610460610480525b61048051526020610480510361048052610140610480511015156108925761086f565b6105208051602001806105a08284600060045af16108af57600080fd5b505060a061062052610620516106605261014080516020018061062051610660018284600060045af16108e157600080fd5b505061062051610660015160206001820306601f82010390506106006106205161066001516040818352015b826106005110151561091e5761093f565b600061060051610620516106800101535b815160010180835281141561090d575b505050602061062051610660015160206001820306601f82010390506106205101016106205261062051610680526101c080516020018061062051610660018284600060045af161098f57600080fd5b505061062051610660015160206001820306601f82010390506106006106205161066001516020818352015b82610600511015156109cc576109ed565b600061060051610620516106800101535b81516001018083528114156109bb575b505050602061062051610660015160206001820306601f820103905061062051010161062052610620516106a05261030080516020018061062051610660018284600060045af1610a3d57600080fd5b505061062051610660015160206001820306601f82010390506106006106205161066001516020818352015b8261060051101515610a7a57610a9b565b600061060051610620516106800101535b8151600101808352811415610a69575b505050602061062051610660015160206001820306601f820103905061062051010161062052610620516106c05261022080516020018061062051610660018284600060045af1610aeb57600080fd5b505061062051610660015160206001820306601f82010390506106006106205161066001516060818352015b8261060051101515610b2857610b49565b600061060051610620516106800101535b8151600101808352811415610b17575b505050602061062051610660015160206001820306601f820103905061062051010161062052610620516106e0526105a080516020018061062051610660018284600060045af1610b9957600080fd5b505061062051610660015160206001820306601f82010390506106006106205161066001516020818352015b8261060051101515610bd657610bf7565b600061060051610620516106800101535b8151600101808352811415610bc5575b505050602061062051610660015160206001820306601f8201039050610620510101610620527f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c561062051610660a160006107005260006101406030806020846107c001018260208501600060045af150508051820191505060006010602082066107400160208284011115610c8c57600080fd5b60208061076082610700600060045af15050818152809050905090506010806020846107c001018260208501600060045af1505080518201915050806107c0526107c09050602060c0825160208401600060025af1610cea57600080fd5b60c0519050610720526000600060406020820661086001610220518284011115610d1357600080fd5b6060806108808260206020880688030161022001600060045af1505081815280905090509050602060c0825160208401600060025af1610d5257600080fd5b60c0519050602082610a600101526020810190506000604060206020820661092001610220518284011115610d8657600080fd5b6060806109408260206020880688030161022001600060045af15050818152809050905090506020806020846109e001018260208501600060045af1505080518201915050610700516020826109e0010152602081019050806109e0526109e09050602060c0825160208401600060025af1610e0157600080fd5b60c0519050602082610a6001015260208101905080610a6052610a609050602060c0825160208401600060025af1610e3857600080fd5b60c0519050610840526000600061072051602082610b000101526020810190506101c0602080602084610b0001018260208501600060045af150508051820191505080610b0052610b009050602060c0825160208401600060025af1610e9d57600080fd5b60c0519050602082610c800101526020810190506000610300600880602084610c0001018260208501600060045af15050805182019150506000601860208206610b800160208284011115610ef157600080fd5b602080610ba082610700600060045af1505081815280905090509050601880602084610c0001018260208501600060045af150508051820191505061084051602082610c0001015260208101905080610c0052610c009050602060c0825160208401600060025af1610f6257600080fd5b60c0519050602082610c8001015260208101905080610c8052610c809050602060c0825160208401600060025af1610f9957600080fd5b60c0519050610ae052606435610ae05114610fb357600080fd5b6001805460018254011015610fc757600080fd5b6001815401815550600154610d0052610d2060006020818352015b60016001610d005116141561101757610ae051610d20516020811061100657600080fd5b600060c052602060c02001556110ab565b6000610d20516020811061102a57600080fd5b600060c052602060c0200154602082610d40010152602081019050610ae051602082610d4001015260208101905080610d4052610d409050602060c0825160208401600060025af161107b57600080fd5b60c0519050610ae052610d00600261109257600080fd5b60028151048152505b8151600101808352811415610fe2575b5050005b5b60006000fd5b61017f6112350361017f60003961017f611235036000f3"} \ No newline at end of file diff --git a/deposit_contract/contracts/validator_registration.vy b/deposit_contract/contracts/validator_registration.vy deleted file mode 100644 index 671252e2e..000000000 --- a/deposit_contract/contracts/validator_registration.vy +++ /dev/null @@ -1,110 +0,0 @@ -# Vyper target 0.1.0b13.hotfix1761 -MIN_DEPOSIT_AMOUNT: constant(uint256) = 1000000000 # Gwei -DEPOSIT_CONTRACT_TREE_DEPTH: constant(uint256) = 32 -MAX_DEPOSIT_COUNT: constant(uint256) = 4294967295 # 2**DEPOSIT_CONTRACT_TREE_DEPTH - 1 -PUBKEY_LENGTH: constant(uint256) = 48 # bytes -WITHDRAWAL_CREDENTIALS_LENGTH: constant(uint256) = 32 # bytes -SIGNATURE_LENGTH: constant(uint256) = 96 # bytes -AMOUNT_LENGTH: constant(uint256) = 8 # bytes - -DepositEvent: event({ - pubkey: bytes[48], - withdrawal_credentials: bytes[32], - amount: bytes[8], - signature: bytes[96], - index: bytes[8], -}) - -branch: bytes32[DEPOSIT_CONTRACT_TREE_DEPTH] -deposit_count: uint256 - -# Compute hashes in empty sparse Merkle tree -zero_hashes: bytes32[DEPOSIT_CONTRACT_TREE_DEPTH] -@public -def __init__(): - for i in range(DEPOSIT_CONTRACT_TREE_DEPTH - 1): - self.zero_hashes[i + 1] = sha256(concat(self.zero_hashes[i], self.zero_hashes[i])) - - -@private -@constant -def to_little_endian_64(value: uint256) -> bytes[8]: - # Reversing bytes using bitwise uint256 manipulations - # Note: array accesses of bytes[] are not currently supported in Vyper - # Note: this function is only called when `value < 2**64` - y: uint256 = 0 - x: uint256 = value - for _ in range(8): - y = shift(y, 8) - y = y + bitwise_and(x, 255) - x = shift(x, -8) - return slice(convert(y, bytes32), start=24, len=8) - - -@public -@constant -def get_deposit_root() -> bytes32: - zero_bytes32: bytes32 = 0x0000000000000000000000000000000000000000000000000000000000000000 - node: bytes32 = zero_bytes32 - size: uint256 = self.deposit_count - for height in range(DEPOSIT_CONTRACT_TREE_DEPTH): - if bitwise_and(size, 1) == 1: # More gas efficient than `size % 2 == 1` - node = sha256(concat(self.branch[height], node)) - else: - node = sha256(concat(node, self.zero_hashes[height])) - size /= 2 - return sha256(concat(node, self.to_little_endian_64(self.deposit_count), slice(zero_bytes32, start=0, len=24))) - - -@public -@constant -def get_deposit_count() -> bytes[8]: - return self.to_little_endian_64(self.deposit_count) - - -@payable -@public -def deposit(pubkey: bytes[PUBKEY_LENGTH], - withdrawal_credentials: bytes[WITHDRAWAL_CREDENTIALS_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 - - # Check deposit amount - deposit_amount: uint256 = msg.value / as_wei_value(1, "gwei") - assert deposit_amount >= MIN_DEPOSIT_AMOUNT - - # Length checks for safety - 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 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( - sha256(slice(signature, start=0, len=64)), - sha256(concat(slice(signature, start=64, len=SIGNATURE_LENGTH - 64), zero_bytes32)), - )) - node: bytes32 = sha256(concat( - sha256(concat(pubkey_root, withdrawal_credentials)), - sha256(concat(amount, slice(zero_bytes32, start=0, len=32 - AMOUNT_LENGTH), signature_root)), - )) - # 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) - self.deposit_count += 1 - size: uint256 = self.deposit_count - for height in range(DEPOSIT_CONTRACT_TREE_DEPTH): - if bitwise_and(size, 1) == 1: # More gas efficient than `size % 2 == 1` - self.branch[height] = node - break - node = sha256(concat(self.branch[height], node)) - size /= 2 - diff --git a/solidity_deposit_contract/LICENSE b/solidity_deposit_contract/LICENSE deleted file mode 100644 index 670154e35..000000000 --- a/solidity_deposit_contract/LICENSE +++ /dev/null @@ -1,116 +0,0 @@ -CC0 1.0 Universal - -Statement of Purpose - -The laws of most jurisdictions throughout the world automatically confer -exclusive Copyright and Related Rights (defined below) upon the creator and -subsequent owner(s) (each and all, an "owner") of an original work of -authorship and/or a database (each, a "Work"). - -Certain owners wish to permanently relinquish those rights to a Work for the -purpose of contributing to a commons of creative, cultural and scientific -works ("Commons") that the public can reliably and without fear of later -claims of infringement build upon, modify, incorporate in other works, reuse -and redistribute as freely as possible in any form whatsoever and for any -purposes, including without limitation commercial purposes. These owners may -contribute to the Commons to promote the ideal of a free culture and the -further production of creative, cultural and scientific works, or to gain -reputation or greater distribution for their Work in part through the use and -efforts of others. - -For these and/or other purposes and motivations, and without any expectation -of additional consideration or compensation, the person associating CC0 with a -Work (the "Affirmer"), to the extent that he or she is an owner of Copyright -and Related Rights in the Work, voluntarily elects to apply CC0 to the Work -and publicly distribute the Work under its terms, with knowledge of his or her -Copyright and Related Rights in the Work and the meaning and intended legal -effect of CC0 on those rights. - -1. Copyright and Related Rights. A Work made available under CC0 may be -protected by copyright and related or neighboring rights ("Copyright and -Related Rights"). Copyright and Related Rights include, but are not limited -to, the following: - - i. the right to reproduce, adapt, distribute, perform, display, communicate, - and translate a Work; - - ii. moral rights retained by the original author(s) and/or performer(s); - - iii. publicity and privacy rights pertaining to a person's image or likeness - depicted in a Work; - - iv. rights protecting against unfair competition in regards to a Work, - subject to the limitations in paragraph 4(a), below; - - v. rights protecting the extraction, dissemination, use and reuse of data in - a Work; - - vi. database rights (such as those arising under Directive 96/9/EC of the - European Parliament and of the Council of 11 March 1996 on the legal - protection of databases, and under any national implementation thereof, - including any amended or successor version of such directive); and - - vii. other similar, equivalent or corresponding rights throughout the world - based on applicable law or treaty, and any national implementations thereof. - -2. Waiver. To the greatest extent permitted by, but not in contravention of, -applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and -unconditionally waives, abandons, and surrenders all of Affirmer's Copyright -and Related Rights and associated claims and causes of action, whether now -known or unknown (including existing as well as future claims and causes of -action), in the Work (i) in all territories worldwide, (ii) for the maximum -duration provided by applicable law or treaty (including future time -extensions), (iii) in any current or future medium and for any number of -copies, and (iv) for any purpose whatsoever, including without limitation -commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes -the Waiver for the benefit of each member of the public at large and to the -detriment of Affirmer's heirs and successors, fully intending that such Waiver -shall not be subject to revocation, rescission, cancellation, termination, or -any other legal or equitable action to disrupt the quiet enjoyment of the Work -by the public as contemplated by Affirmer's express Statement of Purpose. - -3. Public License Fallback. Should any part of the Waiver for any reason be -judged legally invalid or ineffective under applicable law, then the Waiver -shall be preserved to the maximum extent permitted taking into account -Affirmer's express Statement of Purpose. In addition, to the extent the Waiver -is so judged Affirmer hereby grants to each affected person a royalty-free, -non transferable, non sublicensable, non exclusive, irrevocable and -unconditional license to exercise Affirmer's Copyright and Related Rights in -the Work (i) in all territories worldwide, (ii) for the maximum duration -provided by applicable law or treaty (including future time extensions), (iii) -in any current or future medium and for any number of copies, and (iv) for any -purpose whatsoever, including without limitation commercial, advertising or -promotional purposes (the "License"). The License shall be deemed effective as -of the date CC0 was applied by Affirmer to the Work. Should any part of the -License for any reason be judged legally invalid or ineffective under -applicable law, such partial invalidity or ineffectiveness shall not -invalidate the remainder of the License, and in such case Affirmer hereby -affirms that he or she will not (i) exercise any of his or her remaining -Copyright and Related Rights in the Work or (ii) assert any associated claims -and causes of action with respect to the Work, in either case contrary to -Affirmer's express Statement of Purpose. - -4. Limitations and Disclaimers. - - a. No trademark or patent rights held by Affirmer are waived, abandoned, - surrendered, licensed or otherwise affected by this document. - - b. Affirmer offers the Work as-is and makes no representations or warranties - of any kind concerning the Work, express, implied, statutory or otherwise, - including without limitation warranties of title, merchantability, fitness - for a particular purpose, non infringement, or the absence of latent or - other defects, accuracy, or the present or absence of errors, whether or not - discoverable, all to the greatest extent permissible under applicable law. - - c. Affirmer disclaims responsibility for clearing rights of other persons - that may apply to the Work or any use thereof, including without limitation - any person's Copyright and Related Rights in the Work. Further, Affirmer - disclaims responsibility for obtaining any necessary consents, permissions - or other rights required for any use of the Work. - - d. Affirmer understands and acknowledges that Creative Commons is not a - party to this document and has no duty or obligation with respect to this - CC0 or use of the Work. - -For more information, please see - diff --git a/solidity_deposit_contract/Makefile b/solidity_deposit_contract/Makefile deleted file mode 100644 index 55d672105..000000000 --- a/solidity_deposit_contract/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -all: compile - -clean: - @rm -rf build - @rm -f deposit_contract.json - -# Note: using /bin/echo for macOS support -compile: clean - @git submodule update --recursive --init - @solc --metadata-literal --optimize --optimize-runs 5000000 --bin --abi --combined-json=abi,bin,bin-runtime,srcmap,srcmap-runtime,ast,metadata,storage-layout --overwrite -o build deposit_contract.sol tests/deposit_contract.t.sol - @/bin/echo -n '{"abi": ' > deposit_contract.json - @cat build/DepositContract.abi >> deposit_contract.json - @/bin/echo -n ', "bytecode": "0x' >> deposit_contract.json - @cat build/DepositContract.bin >> deposit_contract.json - @/bin/echo -n '"}' >> deposit_contract.json - -export DAPP_SKIP_BUILD:=1 -export DAPP_SRC:=. -export DAPP_JSON:=build/combined.json - -test: - dapp test -v --fuzz-runs 5 diff --git a/solidity_deposit_contract/README.md b/solidity_deposit_contract/README.md index d5a71191e..947eb0f19 100644 --- a/solidity_deposit_contract/README.md +++ b/solidity_deposit_contract/README.md @@ -1,22 +1,16 @@ # eth2-deposit-contract -This is a port of the [Vyper Eth 2.0 deposit contract](https://github.com/ethereum/eth2.0-specs/blob/dev/deposit_contract/contracts/validator_registration.vy) to Solidity. +This is a port of the [Vyper Eth 2.0 deposit contract](https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/deposit_contract/contracts/validator_registration.vy) to Solidity. The original motivation was to run the SMTChecker and the new Yul IR generator option (`--ir`) in the compiler. As of June 2020, this contract (the version tagged as `r1`) has been verified and is considered for adoption. See this [blog post](https://blog.ethereum.org/2020/06/23/eth2-quick-update-no-12/) for more information. -## Using this with the tests - -1. Create the `deposit_contract.json` by running `make` (this requires `solc` to be in the path) -2. Download [eth2.0-specs](https://github.com/ethereum/eth2.0-specs) -3. Replace `eth2.0-specs/deposit_contract/contracts/validator_registration.json` with `deposit_contract.json` -4. In the `eth2.0-specs` directory run `make install_deposit_contract_tester` to install the tools needed (make sure to have Python 3.7 and pip installed) -5. Finally in the `eth2.0-specs` directory run `make test_deposit_contract` to execute the tests - -The Makefile currently compiles the code without optimisations. To enable optimisations add `--optimize` to the `solc` line. +## Running web3 tests +1. In the `eth2.0-specs` directory run `make install_deposit_contract_web3_tester` to install the tools needed (make sure to have Python 3.7 and pip installed) +2. In the `eth2.0-specs` directory run `make test_deposit_contract_web3_tests` to execute the tests ## Running randomized `dapp` tests: diff --git a/solidity_deposit_contract/circle.yml b/solidity_deposit_contract/circle.yml deleted file mode 100644 index c1b0b3506..000000000 --- a/solidity_deposit_contract/circle.yml +++ /dev/null @@ -1,77 +0,0 @@ -version: 2.1 - -jobs: - build: - docker: - - image: ethereum/solc:0.6.11-alpine - steps: - - checkout - - run: - name: Install build essentials - command: | - apk update - apk add git make - - run: - name: Compile the contract - command: | - make - git diff --color --exit-code - - persist_to_workspace: - root: . - paths: - - deposit_contract.json - - build/combined.json - - lib - - spectest: - docker: - - image: cimg/python:3.8.1 - steps: - - checkout - - attach_workspace: - at: /tmp/ - - run: - name: Update python3 - command: | - sudo apt-get update - sudo apt-get install -y python3-venv - - run: - name: Install eth2.0-specs tests - command: | - git clone https://github.com/ethereum/eth2.0-specs --single-branch --branch v0.11.2 - cp -f /tmp/deposit_contract.json eth2.0-specs/deposit_contract/contracts/validator_registration.json - cd eth2.0-specs - make install_deposit_contract_tester - - run: - name: Run eth2.0-specs tests - command: | - cd eth2.0-specs - make test_deposit_contract - - test: - docker: - - image: nixorg/nix:circleci - steps: - - checkout - - attach_workspace: - at: /tmp/ - - run: - name: Test the contract - command: | - mkdir build - cp -r /tmp/build/* build - cp -r /tmp/lib/* lib - nix-shell --command 'make test' - -workflows: - version: 2 - - build_and_test: - jobs: - - build - - spectest: - requires: - - build - - test: - requires: - - spectest diff --git a/solidity_deposit_contract/tests/vyper_setup.sol b/solidity_deposit_contract/tests/vyper_setup.sol index 8d82c754d..15a5b6e59 100644 --- a/solidity_deposit_contract/tests/vyper_setup.sol +++ b/solidity_deposit_contract/tests/vyper_setup.sol @@ -1,7 +1,7 @@ pragma solidity ^0.6.0; contract VyperSetup { - // Bytecode from https://github.com/ethereum/eth2.0-specs/blob/dev/deposit_contract/contracts/validator_registration.json + // Bytecode from https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/deposit_contract/contracts/validator_registration.vy bytes constant public depositCode = hex"740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009857600080fd5b6101406000601f818352015b600061014051602081106100b757600080fd5b600260c052602060c020015460208261016001015260208101905061014051602081106100e357600080fd5b600260c052602060c020015460208261016001015260208101905080610160526101609050602060c0825160208401600060025af161012157600080fd5b60c0519050606051600161014051018060405190131561014057600080fd5b809190121561014e57600080fd5b6020811061015b57600080fd5b600260c052602060c02001555b81516001018083528114156100a4575b505061123556600436101561000d576110b0565b600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a05260001561027f575b6101605261014052600061018052610140516101a0526101c060006008818352015b61018051600860008112156100e8578060000360020a82046100ef565b8060020a82025b905090506101805260ff6101a051166101e052610180516101e0516101805101101561011a57600080fd5b6101e0516101805101610180526101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff86000811215610163578060000360020a820461016a565b8060020a82025b905090506101a0525b81516001018083528114156100cb575b5050601860086020820661020001602082840111156101a157600080fd5b60208061022082610180600060045af15050818152809050905090508051602001806102c08284600060045af16101d757600080fd5b50506102c05160206001820306601f82010390506103206102c0516020818352015b826103205110151561020a57610226565b6000610320516102e001535b81516001018083528114156101f9575b50505060206102a05260406102c0510160206001820306601f8201039050610280525b60006102805111151561025b57610277565b602061028051036102a001516020610280510361028052610249565b610160515650005b63c5f2892f600051141561050e57341561029857600080fd5b6000610140526101405161016052600154610180526101a060006020818352015b600160016101805116141561033a5760006101a051602081106102db57600080fd5b600060c052602060c02001546020826102400101526020810190506101605160208261024001015260208101905080610240526102409050602060c0825160208401600060025af161032c57600080fd5b60c0519050610160526103a8565b6000610160516020826101c00101526020810190506101a0516020811061036057600080fd5b600260c052602060c02001546020826101c0010152602081019050806101c0526101c09050602060c0825160208401600060025af161039e57600080fd5b60c0519050610160525b61018060026103b657600080fd5b60028151048152505b81516001018083528114156102b9575b505060006101605160208261046001015260208101905061014051610160516101805163806732896102e0526001546103005261030051600658016100a9565b506103605260006103c0525b6103605160206001820306601f82010390506103c05110151561043d57610456565b6103c05161038001526103c0516020016103c05261041b565b61018052610160526101405261036060088060208461046001018260208501600060045af150508051820191505060006018602082066103e001602082840111156104a057600080fd5b60208061040082610140600060045af150508181528090509050905060188060208461046001018260208501600060045af150508051820191505080610460526104609050602060c0825160208401600060025af16104fe57600080fd5b60c051905060005260206000f350005b63621fd130600051141561061c57341561052757600080fd5b6380673289610140526001546101605261016051600658016100a9565b506101c0526000610220525b6101c05160206001820306601f8201039050610220511015156105725761058b565b610220516101e001526102205160200161022052610550565b6101c08051602001806102808284600060045af16105a857600080fd5b50506102805160206001820306601f82010390506102e0610280516020818352015b826102e0511015156105db576105f7565b60006102e0516102a001535b81516001018083528114156105ca575b5050506020610260526040610280510160206001820306601f8201039050610260f350005b632289511860005114156110af57605060043560040161014037603060043560040135111561064a57600080fd5b60406024356004016101c037602060243560040135111561066a57600080fd5b608060443560040161022037606060443560040135111561068a57600080fd5b63ffffffff6001541061069c57600080fd5b633b9aca006102e0526102e0516106b257600080fd5b6102e05134046102c052633b9aca006102c05110156106d057600080fd5b603061014051146106e057600080fd5b60206101c051146106f057600080fd5b6060610220511461070057600080fd5b610140610360525b6103605151602061036051016103605261036061036051101561072a57610708565b6380673289610380526102c0516103a0526103a051600658016100a9565b50610400526000610460525b6104005160206001820306601f8201039050610460511015156107765761078f565b6104605161042001526104605160200161046052610754565b610340610360525b61036051526020610360510361036052610140610360511015156107ba57610797565b6104008051602001806103008284600060045af16107d757600080fd5b5050610140610480525b61048051516020610480510161048052610480610480511015610803576107e1565b63806732896104a0526001546104c0526104c051600658016100a9565b50610520526000610580525b6105205160206001820306601f82010390506105805110151561084e57610867565b610580516105400152610580516020016105805261082c565b610460610480525b61048051526020610480510361048052610140610480511015156108925761086f565b6105208051602001806105a08284600060045af16108af57600080fd5b505060a061062052610620516106605261014080516020018061062051610660018284600060045af16108e157600080fd5b505061062051610660015160206001820306601f82010390506106006106205161066001516040818352015b826106005110151561091e5761093f565b600061060051610620516106800101535b815160010180835281141561090d575b505050602061062051610660015160206001820306601f82010390506106205101016106205261062051610680526101c080516020018061062051610660018284600060045af161098f57600080fd5b505061062051610660015160206001820306601f82010390506106006106205161066001516020818352015b82610600511015156109cc576109ed565b600061060051610620516106800101535b81516001018083528114156109bb575b505050602061062051610660015160206001820306601f820103905061062051010161062052610620516106a05261030080516020018061062051610660018284600060045af1610a3d57600080fd5b505061062051610660015160206001820306601f82010390506106006106205161066001516020818352015b8261060051101515610a7a57610a9b565b600061060051610620516106800101535b8151600101808352811415610a69575b505050602061062051610660015160206001820306601f820103905061062051010161062052610620516106c05261022080516020018061062051610660018284600060045af1610aeb57600080fd5b505061062051610660015160206001820306601f82010390506106006106205161066001516060818352015b8261060051101515610b2857610b49565b600061060051610620516106800101535b8151600101808352811415610b17575b505050602061062051610660015160206001820306601f820103905061062051010161062052610620516106e0526105a080516020018061062051610660018284600060045af1610b9957600080fd5b505061062051610660015160206001820306601f82010390506106006106205161066001516020818352015b8261060051101515610bd657610bf7565b600061060051610620516106800101535b8151600101808352811415610bc5575b505050602061062051610660015160206001820306601f8201039050610620510101610620527f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c561062051610660a160006107005260006101406030806020846107c001018260208501600060045af150508051820191505060006010602082066107400160208284011115610c8c57600080fd5b60208061076082610700600060045af15050818152809050905090506010806020846107c001018260208501600060045af1505080518201915050806107c0526107c09050602060c0825160208401600060025af1610cea57600080fd5b60c0519050610720526000600060406020820661086001610220518284011115610d1357600080fd5b6060806108808260206020880688030161022001600060045af1505081815280905090509050602060c0825160208401600060025af1610d5257600080fd5b60c0519050602082610a600101526020810190506000604060206020820661092001610220518284011115610d8657600080fd5b6060806109408260206020880688030161022001600060045af15050818152809050905090506020806020846109e001018260208501600060045af1505080518201915050610700516020826109e0010152602081019050806109e0526109e09050602060c0825160208401600060025af1610e0157600080fd5b60c0519050602082610a6001015260208101905080610a6052610a609050602060c0825160208401600060025af1610e3857600080fd5b60c0519050610840526000600061072051602082610b000101526020810190506101c0602080602084610b0001018260208501600060045af150508051820191505080610b0052610b009050602060c0825160208401600060025af1610e9d57600080fd5b60c0519050602082610c800101526020810190506000610300600880602084610c0001018260208501600060045af15050805182019150506000601860208206610b800160208284011115610ef157600080fd5b602080610ba082610700600060045af1505081815280905090509050601880602084610c0001018260208501600060045af150508051820191505061084051602082610c0001015260208101905080610c0052610c009050602060c0825160208401600060025af1610f6257600080fd5b60c0519050602082610c8001015260208101905080610c8052610c809050602060c0825160208401600060025af1610f9957600080fd5b60c0519050610ae052606435610ae05114610fb357600080fd5b6001805460018254011015610fc757600080fd5b6001815401815550600154610d0052610d2060006020818352015b60016001610d005116141561101757610ae051610d20516020811061100657600080fd5b600060c052602060c02001556110ab565b6000610d20516020811061102a57600080fd5b600060c052602060c0200154602082610d40010152602081019050610ae051602082610d4001015260208101905080610d4052610d409050602060c0825160208401600060025af161107b57600080fd5b60c0519050610ae052610d00600261109257600080fd5b60028151048152505b8151600101808352811415610fe2575b5050005b5b60006000fd5b61017f6112350361017f60003961017f611235036000f3"; function write(bytes memory _code) public returns (address target) { assembly { From adf869877892b48542a8e76465d55fd9913b457f Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Tue, 18 Aug 2020 00:51:03 +0800 Subject: [PATCH 56/69] Update the docs and remove unused code --- .gitattributes | 1 - Makefile | 2 -- solidity_deposit_contract/README.md | 17 +++++++++++------ specs/phase0/deposit-contract.md | 8 ++++---- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.gitattributes b/.gitattributes index 97437110d..52031de51 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1 @@ -*.vy linguist-language=Python *.sol linguist-language=Solidity diff --git a/Makefile b/Makefile index 1282401e8..3914b7b27 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,6 @@ TEST_LIBS_DIR = ./tests/core PY_SPEC_DIR = $(TEST_LIBS_DIR)/pyspec TEST_VECTOR_DIR = ../eth2.0-spec-tests/tests GENERATOR_DIR = ./tests/generators -DEPOSIT_CONTRACT_COMPILER_DIR = ./deposit_contract/compiler SOLIDITY_DEPOSIT_CONTRACT_DIR = ./solidity_deposit_contract SOLIDITY_DEPOSIT_CONTRACT_SOURCE = ${SOLIDITY_DEPOSIT_CONTRACT_DIR}/deposit_contract.sol SOLIDITY_FILE_NAME = deposit_contract.json @@ -46,7 +45,6 @@ partial_clean: rm -rf .pytest_cache rm -f .coverage rm -rf $(PY_SPEC_DIR)/.pytest_cache - rm -rf $(DEPOSIT_CONTRACT_COMPILER_DIR)/.pytest_cache rm -rf $(DEPOSIT_CONTRACT_TESTER_DIR)/.pytest_cache rm -rf $(PY_SPEC_DIR)/phase0 rm -rf $(PY_SPEC_DIR)/phase1 diff --git a/solidity_deposit_contract/README.md b/solidity_deposit_contract/README.md index 947eb0f19..88b626521 100644 --- a/solidity_deposit_contract/README.md +++ b/solidity_deposit_contract/README.md @@ -1,20 +1,25 @@ # eth2-deposit-contract -This is a port of the [Vyper Eth 2.0 deposit contract](https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/deposit_contract/contracts/validator_registration.vy) to Solidity. +## History + +This is a rewrite of the [Vyper Eth 2.0 deposit contract](https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/deposit_contract/contracts/validator_registration.vy) to Solidity. The original motivation was to run the SMTChecker and the new Yul IR generator option (`--ir`) in the compiler. -As of June 2020, this contract (the version tagged as `r1`) has been verified and is considered for adoption. +As of June 2020, this contract (the version tagged as [`r1`](https://github.com/axic/eth2-deposit-contract/tree/r1) in GitHub repository [axic/eth2-deposit-contract](https://github.com/axic/eth2-deposit-contract/tree/r1)) has been verified and is considered for adoption. See this [blog post](https://blog.ethereum.org/2020/06/23/eth2-quick-update-no-12/) for more information. +In August 2020, tag [`r2`](https://github.com/axic/eth2-deposit-contract/tree/r2) was released with metadata modifications and relicensed to CC0-1.0. Afterward, this contract has been ported back to `eth2.0-specs` repository and replaced the Vyper deposit contract. + ## Running web3 tests -1. In the `eth2.0-specs` directory run `make install_deposit_contract_web3_tester` to install the tools needed (make sure to have Python 3.7 and pip installed) -2. In the `eth2.0-specs` directory run `make test_deposit_contract_web3_tests` to execute the tests +1. In the `eth2.0-specs` directory run `make install_deposit_contract_web3_tester` to install the tools needed (make sure to have Python 3.7 and pip installed). +2. In the `eth2.0-specs` directory run `make test_deposit_contract_web3_tests` to execute the tests. ## Running randomized `dapp` tests: -Install the latest version of `dapp` by following the instructions at [dapp.tools](https://dapp.tools/). Then run +Install the latest version of `dapp` by following the instructions at [dapp.tools](https://dapp.tools/). Then in the `eth2.0-specs` directory run: + ```sh -make test +make test_deposit_contract ``` diff --git a/specs/phase0/deposit-contract.md b/specs/phase0/deposit-contract.md index b4f8d3036..89c5bb22b 100644 --- a/specs/phase0/deposit-contract.md +++ b/specs/phase0/deposit-contract.md @@ -16,7 +16,7 @@ - [Deposit amount](#deposit-amount) - [Withdrawal credentials](#withdrawal-credentials) - [`DepositEvent` log](#depositevent-log) -- [Vyper code](#vyper-code) +- [Solidity code](#solidity-code) @@ -53,7 +53,7 @@ _Note_: See [here](https://chainid.network/) for a comprehensive list of public ### `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], deposit_data_root: bytes32`. The first three arguments populate a [`DepositData`](./beacon-chain.md#depositdata) object, and `deposit_data_root` is the expected `DepositData` root as a protection against malformatted calldata. +The deposit contract has a public `deposit` function to make deposits. It takes as arguments `bytes calldata pubkey, bytes calldata withdrawal_credentials, bytes calldata signature, bytes32 deposit_data_root`. The first three arguments populate a [`DepositData`](./beacon-chain.md#depositdata) object, and `deposit_data_root` is the expected `DepositData` root as a protection against malformatted calldata. #### Deposit amount @@ -72,8 +72,8 @@ The private key corresponding to `withdrawal_pubkey` will be required to initiat Every Ethereum 1.0 deposit emits a `DepositEvent` log for consumption by the beacon chain. The deposit contract does little validation, pushing most of the validator onboarding logic to the beacon chain. In particular, the proof of possession (a BLS12-381 signature) is not verified by the deposit contract. -## Vyper code +## Solidity code -The deposit contract source code, written in Vyper, is available [here](../../deposit_contract/contracts/validator_registration.vy). +The deposit contract source code, written in Solidity, is available [here](../../solidity_deposit_contract/deposit_contract.sol). *Note*: To save on gas, the deposit contract uses a progressive Merkle root calculation algorithm that requires only O(log(n)) storage. See [here](https://github.com/ethereum/research/blob/master/beacon_chain_impl/progressive_merkle_tree.py) for a Python implementation, and [here](https://github.com/runtimeverification/verified-smart-contracts/blob/master/deposit/formal-incremental-merkle-tree-algorithm.pdf) for a formal correctness proof. From 585caa3dea87072b0e121da953fe8f33b2ff08fd Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Mon, 17 Aug 2020 18:44:03 -0600 Subject: [PATCH 57/69] update discord invite to go directly to the "welcome" channel --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 78ce5f31f..914e52f80 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Ethereum 2.0 Specifications -[![Join the chat at https://discord.gg/hpFs23p](https://img.shields.io/badge/chat-on%20discord-blue.svg)](https://discord.gg/hpFs23p) [![Join the chat at https://gitter.im/ethereum/sharding](https://badges.gitter.im/ethereum/sharding.svg)](https://gitter.im/ethereum/sharding?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Join the chat at https://discord.gg/qGpsxSA](https://img.shields.io/badge/chat-on%20discord-blue.svg)](https://discord.gg/hpFs23p) [![Join the chat at https://gitter.im/ethereum/sharding](https://badges.gitter.im/ethereum/sharding.svg)](https://gitter.im/ethereum/sharding?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) To learn more about sharding and Ethereum 2.0 (Serenity), see the [sharding FAQ](https://eth.wiki/sharding/Sharding-FAQs) and the [research compendium](https://notes.ethereum.org/s/H1PGqDhpm). From 9742b3a1571969a7dfe8bcb8e5fb604956deb9e7 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Wed, 19 Aug 2020 09:58:02 -0600 Subject: [PATCH 58/69] clarify what 'state' is for block proposals in validator guide --- specs/phase0/validator.md | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/specs/phase0/validator.md b/specs/phase0/validator.md index e379df03c..a18d07600 100644 --- a/specs/phase0/validator.md +++ b/specs/phase0/validator.md @@ -194,9 +194,14 @@ def is_proposer(state: BeaconState, validator_index: ValidatorIndex) -> bool: ### Lookahead -The beacon chain shufflings are designed to provide a minimum of 1 epoch lookahead on the validator's upcoming committee assignments for attesting dictated by the shuffling and slot. Note that this lookahead does not apply to proposing, which must be checked during the epoch in question. +The beacon chain shufflings are designed to provide a minimum of 1 epoch lookahead +on the validator's upcoming committee assignments for attesting dictated by the shuffling and slot. +Note that this lookahead does not apply to proposing, which must be checked during the epoch in question. -`get_committee_assignment` should be called at the start of each epoch to get the assignment for the next epoch (`current_epoch + 1`). A validator should plan for future assignments by noting at which future slot they will have to attest and joining the committee index attestation subnet related to their committee assignment. +`get_committee_assignment` should be called at the start of each epoch +to get the assignment for the next epoch (`current_epoch + 1`). +A validator should plan for future assignments by noting at which future slot +they will have to attest and joining the committee index attestation subnet related to their committee assignment. Specifically a validator should: * Call `get_committee_assignment(state, next_epoch, validator_index)` when checking for next epoch assignments. @@ -214,9 +219,18 @@ A validator has two primary responsibilities to the beacon chain: [proposing blo ### Block proposal -A validator is expected to propose a [`SignedBeaconBlock`](./beacon-chain.md#signedbeaconblock) at the beginning of any slot during which `is_proposer(state, validator_index)` returns `True`. To propose, the validator selects the `BeaconBlock`, `parent`, that in their view of the fork choice is the head of the chain during `slot - 1`. The validator creates, signs, and broadcasts a `block` that is a child of `parent` that satisfies a valid [beacon chain state transition](./beacon-chain.md#beacon-chain-state-transition-function). +A validator is expected to propose a [`SignedBeaconBlock`](./beacon-chain.md#signedbeaconblock) at +the beginning of any slot during which `is_proposer(state, validator_index)` returns `True`. +To propose, the validator selects the `BeaconBlock`, `parent`, +that in their view of the fork choice is the head of the chain during `slot - 1`. +The validator creates, signs, and broadcasts a `block` that is a child of `parent` +that satisfies a valid [beacon chain state transition](./beacon-chain.md#beacon-chain-state-transition-function). -There is one proposer per slot, so if there are N active validators any individual validator will on average be assigned to propose once per N slots (e.g. at 312,500 validators = 10 million ETH, that's once per ~6 weeks). +There is one proposer per slot, so if there are N active validators any individual validator +will on average be assigned to propose once per N slots (e.g. at 312,500 validators = 10 million ETH, that's once per ~6 weeks). + +*Note*: In this sectio, `state` is the state of the slot for the block proposal _without_ the block yet applied. +That is, `state` is the `previous_state` processed through any empty slots up to the assigned slot using `process_slots(previous_state, slot)`. #### Preparing for a `BeaconBlock` @@ -251,7 +265,13 @@ def get_epoch_signature(state: BeaconState, block: BeaconBlock, privkey: int) -> ##### Eth1 Data -The `block.body.eth1_data` field is for block proposers to vote on recent Eth1 data. This recent data contains an Eth1 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 Eth1 block. If over half of the block proposers in the current Eth1 voting period vote for the same `eth1_data` then `state.eth1_data` updates immediately allowing new deposits to be processed. Each deposit in `block.body.deposits` must verify against `state.eth1_data.eth1_deposit_root`. +The `block.body.eth1_data` field is for block proposers to vote on recent Eth1 data. +This recent data contains an Eth1 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 Eth1 block. +If over half of the block proposers in the current Eth1 voting period vote for the same +`eth1_data` then `state.eth1_data` updates immediately allowing new deposits to be processed. +Each deposit in `block.body.deposits` must verify against `state.eth1_data.eth1_deposit_root`. ###### `Eth1Block` From be208294586469cb3e59e5f439cba9240ba20cce Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 20 Aug 2020 20:56:55 +0800 Subject: [PATCH 59/69] Update README --- solidity_deposit_contract/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/solidity_deposit_contract/README.md b/solidity_deposit_contract/README.md index 88b626521..52519eccd 100644 --- a/solidity_deposit_contract/README.md +++ b/solidity_deposit_contract/README.md @@ -1,4 +1,4 @@ -# eth2-deposit-contract +# Deposit Contract ## History @@ -6,10 +6,10 @@ This is a rewrite of the [Vyper Eth 2.0 deposit contract](https://github.com/eth The original motivation was to run the SMTChecker and the new Yul IR generator option (`--ir`) in the compiler. -As of June 2020, this contract (the version tagged as [`r1`](https://github.com/axic/eth2-deposit-contract/tree/r1) in GitHub repository [axic/eth2-deposit-contract](https://github.com/axic/eth2-deposit-contract/tree/r1)) has been verified and is considered for adoption. +As of June 2020, version `r1` of the Solidity deposit contract has been verified and is considered for adoption. See this [blog post](https://blog.ethereum.org/2020/06/23/eth2-quick-update-no-12/) for more information. -In August 2020, tag [`r2`](https://github.com/axic/eth2-deposit-contract/tree/r2) was released with metadata modifications and relicensed to CC0-1.0. Afterward, this contract has been ported back to `eth2.0-specs` repository and replaced the Vyper deposit contract. +In August 2020, version `r2` was released with metadata modifications and relicensed to CC0-1.0. Afterward, this contract has been ported back to from [`axic/eth2-deposit-contract`](https://github.com/axic/eth2-deposit-contract) to this repository and replaced the Vyper deposit contract. ## Running web3 tests From 444cd0249a1f80e71278da68aadd168a81d8bfa1 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Thu, 20 Aug 2020 16:53:09 -0600 Subject: [PATCH 60/69] minot typo fix Co-authored-by: Alex Stokes --- specs/phase0/validator.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/phase0/validator.md b/specs/phase0/validator.md index a18d07600..e62187823 100644 --- a/specs/phase0/validator.md +++ b/specs/phase0/validator.md @@ -229,7 +229,7 @@ that satisfies a valid [beacon chain state transition](./beacon-chain.md#beacon- There is one proposer per slot, so if there are N active validators any individual validator will on average be assigned to propose once per N slots (e.g. at 312,500 validators = 10 million ETH, that's once per ~6 weeks). -*Note*: In this sectio, `state` is the state of the slot for the block proposal _without_ the block yet applied. +*Note*: In this section, `state` is the state of the slot for the block proposal _without_ the block yet applied. That is, `state` is the `previous_state` processed through any empty slots up to the assigned slot using `process_slots(previous_state, slot)`. #### Preparing for a `BeaconBlock` From e323260a4a312945c8dee9a47711926530fe3396 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Thu, 20 Aug 2020 17:03:49 -0600 Subject: [PATCH 61/69] fix some confusing language in validtor guide --- specs/phase0/validator.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/phase0/validator.md b/specs/phase0/validator.md index e62187823..86cb8ec1c 100644 --- a/specs/phase0/validator.md +++ b/specs/phase0/validator.md @@ -200,8 +200,8 @@ Note that this lookahead does not apply to proposing, which must be checked duri `get_committee_assignment` should be called at the start of each epoch to get the assignment for the next epoch (`current_epoch + 1`). -A validator should plan for future assignments by noting at which future slot -they will have to attest and joining the committee index attestation subnet related to their committee assignment. +A validator should plan for future assignments by noting their assigned attestation +slot and joining the committee index attestation subnet related to their committee assignment. Specifically a validator should: * Call `get_committee_assignment(state, next_epoch, validator_index)` when checking for next epoch assignments. From c3ff87461fb324551cbb5b0fbd2c1f9a9f9c1eed Mon Sep 17 00:00:00 2001 From: tintinweb Date: Fri, 21 Aug 2020 12:10:10 +0200 Subject: [PATCH 62/69] fix typo --- specs/phase0/p2p-interface.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/phase0/p2p-interface.md b/specs/phase0/p2p-interface.md index 76ff91eab..0dc243e52 100644 --- a/specs/phase0/p2p-interface.md +++ b/specs/phase0/p2p-interface.md @@ -728,7 +728,7 @@ The request MUST be encoded as an SSZ-container. The response MUST consist of zero or more `response_chunk`. Each _successful_ `response_chunk` MUST contain a single `SignedBeaconBlock` payload. -Clients MUST keep a record of signed blocks seen since the since the start of the weak subjectivity period +Clients MUST keep a record of signed blocks seen since the start of the weak subjectivity period and MUST support serving requests of blocks up to their own `head_block_root`. Clients MUST respond with at least the first block that exists in the range, if they have it, and no more than `MAX_REQUEST_BLOCKS` blocks. From a4acd38981d641fae6db4a58b2d113f647251dc9 Mon Sep 17 00:00:00 2001 From: lsankar4033 Date: Wed, 26 Aug 2020 16:11:42 -0700 Subject: [PATCH 63/69] fix typo --- specs/phase0/p2p-interface.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/phase0/p2p-interface.md b/specs/phase0/p2p-interface.md index 0dc243e52..5f591708e 100644 --- a/specs/phase0/p2p-interface.md +++ b/specs/phase0/p2p-interface.md @@ -394,7 +394,7 @@ The following validations MUST pass before forwarding the `attestation` on the s - _[REJECT]_ The attestation's epoch matches its target -- i.e. `attestation.data.target.epoch == compute_epoch_at_slot(attestation.data.slot)` - _[REJECT]_ The attestation is unaggregated -- - that is, it has exactly one participating validator (`len([bit in bit attestation.aggregation_bits if bit]) == 1`, i.e. exactly 1 bit is set). + that is, it has exactly one participating validator (`len([bit for bit in attestation.aggregation_bits if bit]) == 1`, i.e. exactly 1 bit is set). - _[IGNORE]_ There has been no other valid attestation seen on an attestation subnet that has an identical `attestation.data.target.epoch` and participating validator index. - _[REJECT]_ The signature of `attestation` is valid. From 6df35fc3b53f48cfb935057882319a48bd2e1ea2 Mon Sep 17 00:00:00 2001 From: ericsson Date: Mon, 31 Aug 2020 19:41:57 +0300 Subject: [PATCH 64/69] Make `cellog2` return `uint64` so that `CUSTODY_RESPONSE_DEPTH` has `uint64` type --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 427f08bc6..153888aae 100644 --- a/setup.py +++ b/setup.py @@ -152,8 +152,8 @@ GeneralizedIndex = NewType('GeneralizedIndex', int) SSZObject = TypeVar('SSZObject', bound=View) ''' SUNDRY_CONSTANTS_FUNCTIONS = ''' -def ceillog2(x: uint64) -> int: - return (x - 1).bit_length() +def ceillog2(x: uint64) -> uint64: + return uint64((x - 1).bit_length()) ''' PHASE0_SUNDRY_FUNCTIONS = ''' def get_eth1_data(block: Eth1Block) -> Eth1Data: From a380f3e1b193377e206f893cf80c061dff06e177 Mon Sep 17 00:00:00 2001 From: ericsson Date: Tue, 1 Sep 2020 11:07:44 +0300 Subject: [PATCH 65/69] `ceillog2` accepts positive integers now --- setup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 153888aae..c7f9470f7 100644 --- a/setup.py +++ b/setup.py @@ -152,7 +152,9 @@ GeneralizedIndex = NewType('GeneralizedIndex', int) SSZObject = TypeVar('SSZObject', bound=View) ''' SUNDRY_CONSTANTS_FUNCTIONS = ''' -def ceillog2(x: uint64) -> uint64: +def ceillog2(x: int) -> uint64: + if x < 1: + raise ValueError(f"ceillog2 accepts only positive values, x={x}") return uint64((x - 1).bit_length()) ''' PHASE0_SUNDRY_FUNCTIONS = ''' From b35f8fff7410d42b9af911d181569f3dfd66118f Mon Sep 17 00:00:00 2001 From: vbuterin Date: Wed, 2 Sep 2020 12:26:27 +0800 Subject: [PATCH 66/69] Add a constant for slash penalty multiplier Make the multipler on slashed penalties (if portion `p` of validators are slashed each one loses `k*p` an explicit constant). --- specs/phase0/beacon-chain.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/specs/phase0/beacon-chain.md b/specs/phase0/beacon-chain.md index ca7b0b858..c302e46c5 100644 --- a/specs/phase0/beacon-chain.md +++ b/specs/phase0/beacon-chain.md @@ -195,6 +195,7 @@ The following values are (non-configurable) constants used throughout the specif | `HYSTERESIS_QUOTIENT` | `uint64(4)` | | `HYSTERESIS_DOWNWARD_MULTIPLIER` | `uint64(1)` | | `HYSTERESIS_UPWARD_MULTIPLIER` | `uint64(5)` | +| `PROPORTIONAL_SLASHING_MULTIPLIER` | `uint64(3)` | - For the safety of committees, `TARGET_COMMITTEE_SIZE` exceeds [the recommended minimum committee size of 111](http://web.archive.org/web/20190504131341/https://vitalik.ca/files/Ithaca201807_Sharding.pdf); with sufficient active validators (at least `SLOTS_PER_EPOCH * TARGET_COMMITTEE_SIZE`), the shuffling algorithm ensures committee sizes of at least `TARGET_COMMITTEE_SIZE`. (Unbiasable randomness with a Verifiable Delay Function (VDF) will improve committee robustness and lower the safe minimum committee size.) @@ -1557,7 +1558,7 @@ def process_slashings(state: BeaconState) -> None: for index, validator in enumerate(state.validators): if validator.slashed and epoch + EPOCHS_PER_SLASHINGS_VECTOR // 2 == validator.withdrawable_epoch: increment = EFFECTIVE_BALANCE_INCREMENT # Factored out from penalty numerator to avoid uint64 overflow - penalty_numerator = validator.effective_balance // increment * min(sum(state.slashings) * 3, total_balance) + penalty_numerator = validator.effective_balance // increment * min(sum(state.slashings) * PROPORTIONAL_SLASHING_MULTIPLIER, total_balance) penalty = penalty_numerator // total_balance * increment decrease_balance(state, ValidatorIndex(index), penalty) ``` From eed2df37f422ac036e7470bfa1267fe5389e9b49 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 3 Sep 2020 17:27:20 +0800 Subject: [PATCH 67/69] Make linter happy --- specs/phase0/beacon-chain.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/specs/phase0/beacon-chain.md b/specs/phase0/beacon-chain.md index c302e46c5..62c75b045 100644 --- a/specs/phase0/beacon-chain.md +++ b/specs/phase0/beacon-chain.md @@ -1555,10 +1555,11 @@ def process_registry_updates(state: BeaconState) -> None: def process_slashings(state: BeaconState) -> None: epoch = get_current_epoch(state) total_balance = get_total_active_balance(state) + adjusted_total_slashing_balance = min(sum(state.slashings) * PROPORTIONAL_SLASHING_MULTIPLIER, total_balance) for index, validator in enumerate(state.validators): if validator.slashed and epoch + EPOCHS_PER_SLASHINGS_VECTOR // 2 == validator.withdrawable_epoch: increment = EFFECTIVE_BALANCE_INCREMENT # Factored out from penalty numerator to avoid uint64 overflow - penalty_numerator = validator.effective_balance // increment * min(sum(state.slashings) * PROPORTIONAL_SLASHING_MULTIPLIER, total_balance) + penalty_numerator = validator.effective_balance // increment * adjusted_total_slashing_balance penalty = penalty_numerator // total_balance * increment decrease_balance(state, ValidatorIndex(index), penalty) ``` From c995da420e1e73eda78894d31838eaff1fb947d2 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 3 Sep 2020 21:39:00 +0800 Subject: [PATCH 68/69] Update config files --- configs/mainnet/phase0.yaml | 2 ++ configs/minimal/phase0.yaml | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/configs/mainnet/phase0.yaml b/configs/mainnet/phase0.yaml index 616baaf34..48a479d80 100644 --- a/configs/mainnet/phase0.yaml +++ b/configs/mainnet/phase0.yaml @@ -27,6 +27,8 @@ HYSTERESIS_QUOTIENT: 4 HYSTERESIS_DOWNWARD_MULTIPLIER: 1 # 5 (plus 1.25) HYSTERESIS_UPWARD_MULTIPLIER: 5 +# 3 +PROPORTIONAL_SLASHING_MULTIPLIER: 3 # Fork Choice diff --git a/configs/minimal/phase0.yaml b/configs/minimal/phase0.yaml index 78cd60177..02afa369c 100644 --- a/configs/minimal/phase0.yaml +++ b/configs/minimal/phase0.yaml @@ -26,7 +26,8 @@ HYSTERESIS_QUOTIENT: 4 HYSTERESIS_DOWNWARD_MULTIPLIER: 1 # 5 (plus 1.25) HYSTERESIS_UPWARD_MULTIPLIER: 5 - +# 3 +PROPORTIONAL_SLASHING_MULTIPLIER: 3 # Fork Choice From 6c6f180e0e6136ee101db2c7502709b77710e64d Mon Sep 17 00:00:00 2001 From: protolambda Date: Wed, 9 Sep 2020 13:04:53 +0200 Subject: [PATCH 69/69] clarify offsets serialization, thanks @imnisen, fix #1963 --- ssz/simple-serialize.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ssz/simple-serialize.md b/ssz/simple-serialize.md index 4f0c5c9fa..607dd0946 100644 --- a/ssz/simple-serialize.md +++ b/ssz/simple-serialize.md @@ -165,7 +165,7 @@ variable_lengths = [len(part) for part in variable_parts] assert sum(fixed_lengths + variable_lengths) < 2**(BYTES_PER_LENGTH_OFFSET * BITS_PER_BYTE) # Interleave offsets of variable-size parts with fixed-size parts -variable_offsets = [serialize(sum(fixed_lengths + variable_lengths[:i])) for i in range(len(value))] +variable_offsets = [serialize(uint32(sum(fixed_lengths + variable_lengths[:i]))) for i in range(len(value))] fixed_parts = [part if part != None else variable_offsets[i] for i, part in enumerate(fixed_parts)] # Return the concatenation of the fixed-size parts (offsets interleaved) with the variable-size parts