From 094dd1470f804f09f0767a574538a666ba2719b3 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Tue, 18 Aug 2020 00:20:20 +0800 Subject: [PATCH] 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 {