From 005b7aee67c2fe2909cc2132bfd955fa0a6761f0 Mon Sep 17 00:00:00 2001 From: GagziW Date: Thu, 31 May 2018 16:49:18 -0700 Subject: [PATCH 01/10] updated the README to deploy a casper contract using eth-tester --- README.md | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 154 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2c4f476..0d804f2 100644 --- a/README.md +++ b/README.md @@ -37,16 +37,164 @@ NOTE: we suggest using virtualenv to sandbox your setup. - [VALIDATOR_GUIDE.md](https://github.com/ethereum/casper/blob/master/VALIDATOR_GUIDE.md): information about implementing a Casper FFG validator. -## Contribute +## Tests -Feel free to ask questions in our [Gitter room](https://gitter.im/ethereum/casper) or open an [issue](https://github.com/ethereum/casper/issues) for feature requests or bug reports. Feel free to make a PR! +```bash +pytest tests +``` -## License +## Version of Vyper to Compile Casper +We recommend using the vyper version installed as a dependency from requirements.txt. +NOTE: The latest version of Vyper throws an error (line 16) when compiling the Casper contract due to a syntax change of "units". +NOTE: this not needed if steps above followed +```bash +git clone https://github.com/ethereum/vyper.git@248c723288e84899908048efff4c3e0b12f0b3dc +``` +[follow all other directions from](https://github.com/ethereum/vyper#installation) -[UNLICENSE](LICENSE) -## Tests +## How to Build and Deploy Casper Contract + +In this example we will be using eth-tester + +### Imports ```bash -pytest tests +import os +import rlp + +from decimal import ( + Decimal, +) + +import eth_tester + +from eth_tester import ( + EthereumTester, + PyEVMBackend +) +from web3.providers.eth_tester import ( + EthereumTesterProvider, +) + +from web3 import ( + Web3, +) + +from vyper import ( + compiler, + utils as vyper_utils, +) + +``` + +### Step 1: Set Your web3 Provider + +```bash +setattr(eth_tester.backends.pyevm.main, 'GENESIS_GAS_LIMIT', 10**9) ## it costs a lot of gas to deploy the casper contract, so set a high gas limit +setattr(eth_tester.backends.pyevm.main, 'GENESIS_DIFFICULTY', 1) + +base_tester = EthereumTester(PyEVMBackend()) ## instantiates the eth-test suite +w3 = Web3(EthereumTesterProvider(base_tester)) ## Create an instance of the web3 object +w3.eth.setGasPriceStrategy(0) +``` +[Link to the web3.py documentation](https://github.com/ethereum/web3.py) + +### Step 2: Deploy Helper Contracts +NOTE: In addition to the two helper contracts `msg_hasher` and `purity_checker` you also need to deploy the `rlp_decoder` Contract. On a production chain, an `rlp_decoder` contract is already deployed and vyper’s standard internal library knows it’s address and gives vyper contracts access to some functionality at that address. +**when using a test chain, these helper contract must be deployed before the casper contract** + +NOTE: these helper contracts are currently written in serpenat, so until they are converted to Vyper it is best to use the hardcoded transaction hex below. + +#### Define Address & Transaction Hex +```bash +VYPER_RLP_DECODER_TX_SENDER = "0x39ba083c30fCe59883775Fc729bBE1f9dE4DEe11" + +VYPER_RLP_DECODER_TX_HEX = "0xf9035b808506fc23ac0083045f788080b903486103305660006109ac5260006109cc527f0100000000000000000000000000000000000000000000000000000000000000600035046109ec526000610a0c5260006109005260c06109ec51101515585760f86109ec51101561006e5760bf6109ec510336141558576001610a0c52610098565b60013560f76109ec51036020035260005160f66109ec510301361415585760f66109ec5103610a0c525b61022060016064818352015b36610a0c511015156100b557610291565b7f0100000000000000000000000000000000000000000000000000000000000000610a0c5135046109ec526109cc5160206109ac51026040015260016109ac51016109ac5260806109ec51101561013b5760016109cc5161044001526001610a0c516109cc5161046001376001610a0c5101610a0c5260216109cc51016109cc52610281565b60b86109ec5110156101d15760806109ec51036109cc51610440015260806109ec51036001610a0c51016109cc51610460013760816109ec5114156101ac5760807f01000000000000000000000000000000000000000000000000000000000000006001610a0c5101350410151558575b607f6109ec5103610a0c5101610a0c5260606109ec51036109cc51016109cc52610280565b60c06109ec51101561027d576001610a0c51013560b76109ec510360200352600051610a2c526038610a2c5110157f01000000000000000000000000000000000000000000000000000000000000006001610a0c5101350402155857610a2c516109cc516104400152610a2c5160b66109ec5103610a0c51016109cc516104600137610a2c5160b66109ec5103610a0c510101610a0c526020610a2c51016109cc51016109cc5261027f565bfe5b5b5b81516001018083528114156100a4575b5050601f6109ac511115155857602060206109ac5102016109005260206109005103610a0c5261022060016064818352015b6000610a0c5112156102d45761030a565b61090051610a0c516040015101610a0c51610900516104400301526020610a0c5103610a0c5281516001018083528114156102c3575b50506109cc516109005101610420526109cc5161090051016109005161044003f35b61000461033003610004600039610004610330036000f31b2d4f" +``` +```bash +MSG_HASHER_TX_SENDER = "0xD7a3BD6C9eA32efF147d067f907AE6b22d436F91" + +MSG_HASHER_TX_HEX = "0xf9016d808506fc23ac0083026a508080b9015a6101488061000e6000396101565660007f01000000000000000000000000000000000000000000000000000000000000006000350460f8811215610038576001915061003f565b60f6810391505b508060005b368312156100c8577f01000000000000000000000000000000000000000000000000000000000000008335048391506080811215610087576001840193506100c2565b60b881121561009d57607f8103840193506100c1565b60c08112156100c05760b68103600185013560b783036020035260005101840193505b5b5b50610044565b81810360388112156100f4578060c00160005380836001378060010160002060e052602060e0f3610143565b61010081121561010557600161011b565b6201000081121561011757600261011a565b60035b5b8160005280601f038160f701815382856020378282600101018120610140526020610140f350505b505050505b6000f31b2d4f" +``` +```bash +PURITY_CHECKER_TX_SENDER = "0xeA0f0D55EE82Edf248eD648A9A8d213FBa8b5081" + +PURITY_CHECKER_TX_HEX = "0xf90467808506fc23ac00830583c88080b904546104428061000e60003961045056600061033f537c0100000000000000000000000000000000000000000000000000000000600035047f80010000000000000000000000000000000000000030ffff1c0e00000000000060205263a1903eab8114156103f7573659905901600090523660048237600435608052506080513b806020015990590160009052818152602081019050905060a0526080513b600060a0516080513c6080513b8060200260200159905901600090528181526020810190509050610100526080513b806020026020015990590160009052818152602081019050905061016052600060005b602060a05103518212156103c957610100601f8360a051010351066020518160020a161561010a57fe5b80606013151561011e57607f811315610121565b60005b1561014f5780607f036101000a60018460a0510101510482602002610160510152605e8103830192506103b2565b60f18114801561015f5780610164565b60f282145b905080156101725780610177565b60f482145b9050156103aa5760028212151561019e5760606001830360200261010051015112156101a1565b60005b156101bc57607f6001830360200261010051015113156101bf565b60005b156101d157600282036102605261031e565b6004821215156101f057600360018303602002610100510151146101f3565b60005b1561020d57605a6002830360200261010051015114610210565b60005b1561022b57606060038303602002610100510151121561022e565b60005b1561024957607f60038303602002610100510151131561024c565b60005b1561025e57600482036102605261031d565b60028212151561027d57605a6001830360200261010051015114610280565b60005b1561029257600282036102605261031c565b6002821215156102b157609060018303602002610100510151146102b4565b60005b156102c657600282036102605261031b565b6002821215156102e65760806001830360200261010051015112156102e9565b60005b156103035760906001830360200261010051015112610306565b60005b1561031857600282036102605261031a565bfe5b5b5b5b5b604060405990590160009052600081526102605160200261016051015181602001528090502054156103555760016102a052610393565b60306102605160200261010051015114156103755760016102a052610392565b60606102605160200261010051015114156103915760016102a0525b5b5b6102a051151561039f57fe5b6001830192506103b1565b6001830192505b5b8082602002610100510152600182019150506100e0565b50506001604060405990590160009052600081526080518160200152809050205560016102e05260206102e0f35b63c23697a8811415610440573659905901600090523660048237600435608052506040604059905901600090526000815260805181602001528090502054610300526020610300f35b505b6000f31b2d4f" ``` + +#### Fund Senders of Contract With 0.1 Ether to Deploy TXs +```bash +w3.eth.sendTransaction({'to': VYPER_RLP_DECODER_TX_SENDER, 'value': 10**17}) +w3.eth.sendTransaction({'to': PURITY_CHECKER_TX_SENDER, 'value': 10**17}) +w3.eth.sendTransaction({'to': MSG_HASHER_TX_SENDER, 'value': 10**17}) +``` + +#### Deploy Dependency Contracts +```bash +rlp_tx_hash = w3.eth.sendRawTransaction(VYPER_RLP_DECODER_TX_HEX) +rlp_receipt = w3.eth.getTransactionReceipt(rlp_tx_hash) +rlp_decoder_address = rlp_receipt.contractAddress + +msg_tx_hash = w3.eth.sendRawTransaction(MSG_HASHER_TX_HEX) +msg_receipt = w3.eth.getTransactionReceipt(msg_tx_hash) +msg_hasher_address = msg_receipt.contractAddress + +purity_tx_hash = w3.eth.sendRawTransaction(PURITY_CHECKER_TX_HEX) +purity_receipt = w3.eth.getTransactionReceipt(purity_tx_hash) +purity_checker_address = purity_receipt.contractAddress +``` + +#### Casper Parameters +[Detailed Explaination of Casper Parameters](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1011.md#casper-contract-params) + +```bash +EPOCH_LENGTH = 10 +WARM_UP_PERIOD = 20 +WITHDRAWAL_DELAY = 8 +DYNASTY_LOGOUT_DELAY = 5 +BASE_INTEREST_FACTOR = Decimal('0.02') +BASE_PENALTY_FACTOR = Decimal('0.002') +MIN_DEPOSIT_SIZE = 1000 * 10**18 # 1000 ether + + +casper_args = [EPOCH_LENGTH, WARM_UP_PERIOD, WITHDRAWAL_DELAY, DYNASTY_LOGOUT_DELAY, msg_hasher_address, purity_checker_address, BASE_INTEREST_FACTOR, BASE_PENALTY_FACTOR, MIN_DEPOSIT_SIZE] +``` + +#### Compiling and Deploying Casper +```bash + +file = open(os.getcwd()+('/casper/contracts/simple_casper.v.py')) #this will change depending on where the casper contract is located relative to your current working directory +casper_code = file.read() + +casper_bytecode = compiler.compile(casper_code) +casper_abi = compiler.mk_full_signature(casper_code) +base_sender = base_tester.get_accounts()[-1] # make sure it has a lot of ether :) + + +Casper = w3.eth.contract(abi=casper_abi, bytecode=casper_bytecode) +tx_hash = Casper.constructor().transact({'from': base_sender}) +tx_receipt = w3.eth.getTransactionReceipt(tx_hash) + +casper_address = tx_receipt.contractAddress + +w3.eth.sendTransaction({'to': casper_address, 'value': 10**21}) + +casper_contract = w3.eth.contract(address=casper_address, abi=casper_abi) +casper_contract.functions.init(*casper_args).transact() +``` + +#### Interacting with the Casper Contract + +As an exampe that the deployment was successfull, we can check EPOCH_LENGTH. If you didn't change the initial parameters above, the following command should return 10. +```bash +casper_contract.functions.EPOCH_LENGTH().call() +``` + +## Contribute + +Feel free to ask questions in our [Gitter room](https://gitter.im/ethereum/casper) or open an [issue](https://github.com/ethereum/casper/issues) for feature requests or bug reports. Feel free to make a PR! + +## License + +[UNLICENSE](LICENSE) \ No newline at end of file From 9da4b7eabd6e15c7d82292af5b0dbc1eb32195b6 Mon Sep 17 00:00:00 2001 From: GagziW Date: Thu, 31 May 2018 17:11:07 -0700 Subject: [PATCH 02/10] fixed format and typos --- README.md | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 0d804f2..faf2d7d 100644 --- a/README.md +++ b/README.md @@ -50,15 +50,15 @@ NOTE: this not needed if steps above followed ```bash git clone https://github.com/ethereum/vyper.git@248c723288e84899908048efff4c3e0b12f0b3dc ``` -[follow all other directions from](https://github.com/ethereum/vyper#installation) +The guide on how to install Vyper can be found [here](https://github.com/ethereum/vyper#installation). ## How to Build and Deploy Casper Contract -In this example we will be using eth-tester +In this example we will be using [eth-tester](https://github.com/ethereum/eth-tester). -### Imports +### Step 1: Imports ```bash import os import rlp @@ -88,19 +88,21 @@ from vyper import ( ``` -### Step 1: Set Your web3 Provider +### Step 2: Raise the gas limit ```bash setattr(eth_tester.backends.pyevm.main, 'GENESIS_GAS_LIMIT', 10**9) ## it costs a lot of gas to deploy the casper contract, so set a high gas limit -setattr(eth_tester.backends.pyevm.main, 'GENESIS_DIFFICULTY', 1) +``` +### Step 3: Create an instance of Web3 (eth-tester) +[Link to the web3.py documentation.](https://github.com/ethereum/web3.py) +```bash base_tester = EthereumTester(PyEVMBackend()) ## instantiates the eth-test suite w3 = Web3(EthereumTesterProvider(base_tester)) ## Create an instance of the web3 object w3.eth.setGasPriceStrategy(0) ``` -[Link to the web3.py documentation](https://github.com/ethereum/web3.py) -### Step 2: Deploy Helper Contracts +### Step 4: Deploy Helper Contracts NOTE: In addition to the two helper contracts `msg_hasher` and `purity_checker` you also need to deploy the `rlp_decoder` Contract. On a production chain, an `rlp_decoder` contract is already deployed and vyper’s standard internal library knows it’s address and gives vyper contracts access to some functionality at that address. **when using a test chain, these helper contract must be deployed before the casper contract** @@ -145,7 +147,7 @@ purity_receipt = w3.eth.getTransactionReceipt(purity_tx_hash) purity_checker_address = purity_receipt.contractAddress ``` -#### Casper Parameters +### Step 5: Casper Parameters [Detailed Explaination of Casper Parameters](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1011.md#casper-contract-params) ```bash @@ -157,23 +159,22 @@ BASE_INTEREST_FACTOR = Decimal('0.02') BASE_PENALTY_FACTOR = Decimal('0.002') MIN_DEPOSIT_SIZE = 1000 * 10**18 # 1000 ether - casper_args = [EPOCH_LENGTH, WARM_UP_PERIOD, WITHDRAWAL_DELAY, DYNASTY_LOGOUT_DELAY, msg_hasher_address, purity_checker_address, BASE_INTEREST_FACTOR, BASE_PENALTY_FACTOR, MIN_DEPOSIT_SIZE] ``` -#### Compiling and Deploying Casper +### Step 6: Compiling and Deploying Casper ```bash file = open(os.getcwd()+('/casper/contracts/simple_casper.v.py')) #this will change depending on where the casper contract is located relative to your current working directory casper_code = file.read() -casper_bytecode = compiler.compile(casper_code) -casper_abi = compiler.mk_full_signature(casper_code) -base_sender = base_tester.get_accounts()[-1] # make sure it has a lot of ether :) +casper_bytecode = compiler.compile(casper_code) #using vyper +casper_abi = compiler.mk_full_signature(casper_code) #using vyper +base_sender = base_tester.get_accounts()[-1] #account created by eth-tester containing 1 million eth -Casper = w3.eth.contract(abi=casper_abi, bytecode=casper_bytecode) -tx_hash = Casper.constructor().transact({'from': base_sender}) +Casper = w3.eth.contract(abi=casper_abi, bytecode=casper_bytecode) #cteates casper contract object +tx_hash = Casper.constructor().transact({'from': base_sender}) #deploy casper contract tx_receipt = w3.eth.getTransactionReceipt(tx_hash) casper_address = tx_receipt.contractAddress @@ -184,9 +185,10 @@ casper_contract = w3.eth.contract(address=casper_address, abi=casper_abi) casper_contract.functions.init(*casper_args).transact() ``` -#### Interacting with the Casper Contract +### Step 7: Interacting with the Casper Contract As an exampe that the deployment was successfull, we can check EPOCH_LENGTH. If you didn't change the initial parameters above, the following command should return 10. + ```bash casper_contract.functions.EPOCH_LENGTH().call() ``` From 96087ddc0078cd541cb1e15234272fe68b8cf825 Mon Sep 17 00:00:00 2001 From: GagziW Date: Thu, 31 May 2018 17:15:36 -0700 Subject: [PATCH 03/10] fixed more typos --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index faf2d7d..5be76d6 100644 --- a/README.md +++ b/README.md @@ -88,12 +88,12 @@ from vyper import ( ``` -### Step 2: Raise the gas limit +### Step 2: Raise the Gas Limit ```bash setattr(eth_tester.backends.pyevm.main, 'GENESIS_GAS_LIMIT', 10**9) ## it costs a lot of gas to deploy the casper contract, so set a high gas limit ``` -### Step 3: Create an instance of Web3 (eth-tester) +### Step 3: Create an Instance of Web3 (eth-tester) [Link to the web3.py documentation.](https://github.com/ethereum/web3.py) ```bash @@ -104,7 +104,7 @@ w3.eth.setGasPriceStrategy(0) ### Step 4: Deploy Helper Contracts NOTE: In addition to the two helper contracts `msg_hasher` and `purity_checker` you also need to deploy the `rlp_decoder` Contract. On a production chain, an `rlp_decoder` contract is already deployed and vyper’s standard internal library knows it’s address and gives vyper contracts access to some functionality at that address. -**when using a test chain, these helper contract must be deployed before the casper contract** +**When using a test chain, these helper contract must be deployed before the casper contract.** NOTE: these helper contracts are currently written in serpenat, so until they are converted to Vyper it is best to use the hardcoded transaction hex below. @@ -187,7 +187,7 @@ casper_contract.functions.init(*casper_args).transact() ### Step 7: Interacting with the Casper Contract -As an exampe that the deployment was successfull, we can check EPOCH_LENGTH. If you didn't change the initial parameters above, the following command should return 10. +As an exampe that the deployment was successful, we can check EPOCH_LENGTH. If you didn't change the initial parameters above, the following command should return 10. ```bash casper_contract.functions.EPOCH_LENGTH().call() From 40ecc01b2b6251a41de389ec38ff4eec70248110 Mon Sep 17 00:00:00 2001 From: Tomoya Ishizaki Date: Thu, 7 Jun 2018 09:05:57 +0900 Subject: [PATCH 04/10] Add params to --- README.md | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5be76d6..cf82c13 100644 --- a/README.md +++ b/README.md @@ -30,12 +30,12 @@ pip3 install -r requirements.txt ``` NOTE: pip3 is a version of pip using python version 3. + NOTE: we suggest using virtualenv to sandbox your setup. ## Usage -- [VALIDATOR_GUIDE.md](https://github.com/ethereum/casper/blob/master/VALIDATOR_GUIDE.md): -information about implementing a Casper FFG validator. +- [VALIDATOR_GUIDE.md](https://github.com/ethereum/casper/blob/master/VALIDATOR_GUIDE.md) : Information about implementing a Casper FFG validator. ## Tests @@ -44,21 +44,25 @@ pytest tests ``` ## Version of Vyper to Compile Casper + We recommend using the vyper version installed as a dependency from requirements.txt. + NOTE: The latest version of Vyper throws an error (line 16) when compiling the Casper contract due to a syntax change of "units". -NOTE: this not needed if steps above followed + +NOTE: This not needed if steps above followed + ```bash git clone https://github.com/ethereum/vyper.git@248c723288e84899908048efff4c3e0b12f0b3dc ``` -The guide on how to install Vyper can be found [here](https://github.com/ethereum/vyper#installation). +The guide on how to install Vyper can be found [here](https://github.com/ethereum/vyper#installation). ## How to Build and Deploy Casper Contract In this example we will be using [eth-tester](https://github.com/ethereum/eth-tester). - ### Step 1: Imports + ```bash import os import rlp @@ -90,12 +94,15 @@ from vyper import ( ### Step 2: Raise the Gas Limit +It costs a lot of gas to deploy the casper contract, so set a high gas limit. + ```bash -setattr(eth_tester.backends.pyevm.main, 'GENESIS_GAS_LIMIT', 10**9) ## it costs a lot of gas to deploy the casper contract, so set a high gas limit +setattr(eth_tester.backends.pyevm.main, 'GENESIS_GAS_LIMIT', 10**9) ``` ### Step 3: Create an Instance of Web3 (eth-tester) [Link to the web3.py documentation.](https://github.com/ethereum/web3.py) + ```bash base_tester = EthereumTester(PyEVMBackend()) ## instantiates the eth-test suite w3 = Web3(EthereumTesterProvider(base_tester)) ## Create an instance of the web3 object @@ -103,12 +110,15 @@ w3.eth.setGasPriceStrategy(0) ``` ### Step 4: Deploy Helper Contracts + NOTE: In addition to the two helper contracts `msg_hasher` and `purity_checker` you also need to deploy the `rlp_decoder` Contract. On a production chain, an `rlp_decoder` contract is already deployed and vyper’s standard internal library knows it’s address and gives vyper contracts access to some functionality at that address. + **When using a test chain, these helper contract must be deployed before the casper contract.** NOTE: these helper contracts are currently written in serpenat, so until they are converted to Vyper it is best to use the hardcoded transaction hex below. #### Define Address & Transaction Hex + ```bash VYPER_RLP_DECODER_TX_SENDER = "0x39ba083c30fCe59883775Fc729bBE1f9dE4DEe11" @@ -126,6 +136,7 @@ PURITY_CHECKER_TX_HEX = "0xf90467808506fc23ac00830583c88080b904546104428061000e6 ``` #### Fund Senders of Contract With 0.1 Ether to Deploy TXs + ```bash w3.eth.sendTransaction({'to': VYPER_RLP_DECODER_TX_SENDER, 'value': 10**17}) w3.eth.sendTransaction({'to': PURITY_CHECKER_TX_SENDER, 'value': 10**17}) @@ -133,6 +144,7 @@ w3.eth.sendTransaction({'to': MSG_HASHER_TX_SENDER, 'value': 10**17}) ``` #### Deploy Dependency Contracts + ```bash rlp_tx_hash = w3.eth.sendRawTransaction(VYPER_RLP_DECODER_TX_HEX) rlp_receipt = w3.eth.getTransactionReceipt(rlp_tx_hash) @@ -148,6 +160,7 @@ purity_checker_address = purity_receipt.contractAddress ``` ### Step 5: Casper Parameters + [Detailed Explaination of Casper Parameters](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1011.md#casper-contract-params) ```bash @@ -158,11 +171,10 @@ DYNASTY_LOGOUT_DELAY = 5 BASE_INTEREST_FACTOR = Decimal('0.02') BASE_PENALTY_FACTOR = Decimal('0.002') MIN_DEPOSIT_SIZE = 1000 * 10**18 # 1000 ether - -casper_args = [EPOCH_LENGTH, WARM_UP_PERIOD, WITHDRAWAL_DELAY, DYNASTY_LOGOUT_DELAY, msg_hasher_address, purity_checker_address, BASE_INTEREST_FACTOR, BASE_PENALTY_FACTOR, MIN_DEPOSIT_SIZE] ``` ### Step 6: Compiling and Deploying Casper + ```bash file = open(os.getcwd()+('/casper/contracts/simple_casper.v.py')) #this will change depending on where the casper contract is located relative to your current working directory @@ -171,7 +183,7 @@ casper_code = file.read() casper_bytecode = compiler.compile(casper_code) #using vyper casper_abi = compiler.mk_full_signature(casper_code) #using vyper base_sender = base_tester.get_accounts()[-1] #account created by eth-tester containing 1 million eth - +null_sender = base_tester.get_accounts()[-2] Casper = w3.eth.contract(abi=casper_abi, bytecode=casper_bytecode) #cteates casper contract object tx_hash = Casper.constructor().transact({'from': base_sender}) #deploy casper contract @@ -182,6 +194,9 @@ casper_address = tx_receipt.contractAddress w3.eth.sendTransaction({'to': casper_address, 'value': 10**21}) casper_contract = w3.eth.contract(address=casper_address, abi=casper_abi) + +casper_args = [EPOCH_LENGTH, WARM_UP_PERIOD, WITHDRAWAL_DELAY, DYNASTY_LOGOUT_DELAY, msg_hasher_address, purity_checker_address, null_sender, BASE_INTEREST_FACTOR, BASE_PENALTY_FACTOR, MIN_DEPOSIT_SIZE] + casper_contract.functions.init(*casper_args).transact() ``` @@ -199,4 +214,4 @@ Feel free to ask questions in our [Gitter room](https://gitter.im/ethereum/caspe ## License -[UNLICENSE](LICENSE) \ No newline at end of file +[UNLICENSE](LICENSE) From 7591940eac1ded17eea8bd656efb47fd1acb06d1 Mon Sep 17 00:00:00 2001 From: GagziW Date: Thu, 7 Jun 2018 19:29:51 -0700 Subject: [PATCH 05/10] part 1 modification --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5be76d6..adaecde 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,9 @@ from vyper import ( ### Step 2: Raise the Gas Limit +The casper contract costs alot of gas for all its tasks. When you deploy the contract via a normal create transaction, make sure that the block gas limit is high enough. + + ```bash setattr(eth_tester.backends.pyevm.main, 'GENESIS_GAS_LIMIT', 10**9) ## it costs a lot of gas to deploy the casper contract, so set a high gas limit ``` @@ -106,7 +109,7 @@ w3.eth.setGasPriceStrategy(0) NOTE: In addition to the two helper contracts `msg_hasher` and `purity_checker` you also need to deploy the `rlp_decoder` Contract. On a production chain, an `rlp_decoder` contract is already deployed and vyper’s standard internal library knows it’s address and gives vyper contracts access to some functionality at that address. **When using a test chain, these helper contract must be deployed before the casper contract.** -NOTE: these helper contracts are currently written in serpenat, so until they are converted to Vyper it is best to use the hardcoded transaction hex below. +NOTE: These helper contracts can be deployed via the below pre-signed txs. Instructions for compiling and deploying via other methods will soon be available. #### Define Address & Transaction Hex ```bash From 370af00817c4cf79a149713818dfca2403a90efc Mon Sep 17 00:00:00 2001 From: GagziW Date: Mon, 11 Jun 2018 12:29:34 -0700 Subject: [PATCH 06/10] Rewriting the contract less verbose --- README.md | 89 +++++++++++++++++++++++++------------------------------ 1 file changed, 40 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index cc4c0f6..12ff57c 100644 --- a/README.md +++ b/README.md @@ -61,60 +61,32 @@ The guide on how to install Vyper can be found [here](https://github.com/ethereu In this example we will be using [eth-tester](https://github.com/ethereum/eth-tester). -### Step 1: Imports +#### Step 1: Requirements -```bash -import os -import rlp - -from decimal import ( - Decimal, -) +Specifics (imports, web3 Instance) Deploying the contract depends on the framework. Make sure to import all necessary packages (decimal, web3, vyper, eth_tester, ...). -import eth_tester +We assume, you already set-up the environment and that you are able to connect to a runnning node via web3. -from eth_tester import ( - EthereumTester, - PyEVMBackend -) -from web3.providers.eth_tester import ( - EthereumTesterProvider, -) +#### Create an Instance of Web3 (eth-tester) -from web3 import ( - Web3, -) - -from vyper import ( - compiler, - utils as vyper_utils, -) +You need a running web3 instance to connect to the Ethereum network. The web3 object is required to interact with the network. More information: +[Link to the web3.py documentation.](https://github.com/ethereum/web3.py) +We will later refer to the Web3 instance `w3`: +```bash +w3 = Web3(PUT_YOUR_PROVIDER_HERE) ## Create an instance of the web3 object ``` ### Step 2: Raise the Gas Limit -The casper contract costs alot of gas for all its tasks. When you deploy the contract via a normal create transaction, make sure that the block gas limit is high enough. - - -```bash -setattr(eth_tester.backends.pyevm.main, 'GENESIS_GAS_LIMIT', 10**9) -``` -### Step 3: Create an Instance of Web3 (eth-tester) - -[Link to the web3.py documentation.](https://github.com/ethereum/web3.py) +The casper contract costs alot of gas for all its tasks. When you deploy the contract via a normal create transaction, make sure that the block gas limit is high enough. We initially set the limit to 1GW(`10**9 wei`) -```bash -base_tester = EthereumTester(PyEVMBackend()) ## instantiates the eth-test suite -w3 = Web3(EthereumTesterProvider(base_tester)) ## Create an instance of the web3 object -w3.eth.setGasPriceStrategy(0) -``` ### Step 4: Deploy Helper Contracts -NOTE: In addition to the two helper contracts `msg_hasher` and `purity_checker` you also need to deploy the `rlp_decoder` Contract. On a production chain, an `rlp_decoder` contract is already deployed and vyper’s standard internal library knows it’s address and gives vyper contracts access to some functionality at that address. +NOTE: In addition to the two helper contracts `msg_hasher` and `purity_checker` you also need to deploy the `rlp_decoder` Contract. On a production chain, an `rlp_decoder` contract is already deployed and vyper’s standard internal library knows it’s address and gives vyper contracts access to some functionality at that address. -**When using a test chain, these helper contract must be deployed before the casper contract.** +**When using a test chain, these helper contract must be deployed before the casper contract. `rlp_decoder` must be deployed before compiling the casper contract** NOTE: These helper contracts can be deployed via the below pre-signed txs. Instructions for compiling and deploying via other methods will soon be available. @@ -162,6 +134,7 @@ purity_checker_address = purity_receipt.contractAddress ### Step 5: Casper Parameters + [Detailed Explaination of Casper Parameters](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1011.md#casper-contract-params) ```bash @@ -176,10 +149,35 @@ MIN_DEPOSIT_SIZE = 1000 * 10**18 # 1000 ether ### Step 6: Compiling and Deploying Casper +Before deploying the contract, we need to compile it and retrieve the bytecode as well as the abi. + +NOTE: You need the specific version of vyper in order to compile the current contract without errors (see above) + +move to the directory where the `simple_casper` contract is stored. + +Command to get the `casper_bytecode` +```console +vyper simple_casper.v.py +``` +Command to get the `casper_abi` + +```console +vyper -f abi simple_casper.v.py +``` + +Now you can create the Casper contract + ```bash +Casper = w3.eth.contract(abi=casper_abi, bytecode=casper_bytecode) +``` -file = open(os.getcwd()+('/casper/contracts/simple_casper.v.py')) #this will change depending on where the casper contract is located relative to your current working directory -casper_code = file.read() +Deploy the contract and make sure you send enough gas along. We recommend to set the gas limit to `10**7` gas. Make sure that your `base_sender` address has enough ether. + +```console +Casper.constructor().transact({'from': base_sender, 'gas': 10**7}) #deploy casper contract +``` + +```bash casper_bytecode = compiler.compile(casper_code) #using vyper casper_abi = compiler.mk_full_signature(casper_code) #using vyper @@ -201,13 +199,6 @@ casper_args = [EPOCH_LENGTH, WARM_UP_PERIOD, WITHDRAWAL_DELAY, DYNASTY_LOGOUT_DE casper_contract.functions.init(*casper_args).transact() ``` -### Step 7: Interacting with the Casper Contract - -As an exampe that the deployment was successful, we can check EPOCH_LENGTH. If you didn't change the initial parameters above, the following command should return 10. - -```bash -casper_contract.functions.EPOCH_LENGTH().call() -``` ## Contribute From 681fe952a99c8f682209d5198e728f8fa15d05b3 Mon Sep 17 00:00:00 2001 From: William Schwartz Date: Mon, 11 Jun 2018 14:22:25 -0700 Subject: [PATCH 07/10] modified readme --- README.md | 117 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 68 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 12ff57c..1296a94 100644 --- a/README.md +++ b/README.md @@ -23,15 +23,20 @@ For macOS, with [brew](https://brew.sh/) installed: brew install pandoc # required for a python dependency ``` -For all systems: +NOTE: pip3 is a version of pip using python version 3. + +NOTE: we suggest using virtualenv to sandbox your setup. ```bash -pip3 install -r requirements.txt +virtualenv venv +. /venv/bin/activate ``` -NOTE: pip3 is a version of pip using python version 3. +For all systems: -NOTE: we suggest using virtualenv to sandbox your setup. +```bash +pip3 install -r requirements.txt +``` ## Usage @@ -45,9 +50,9 @@ pytest tests ## Version of Vyper to Compile Casper -We recommend using the vyper version installed as a dependency from requirements.txt. +We recommend using the vyper version installed as a dependency from requirements.txt. -NOTE: The latest version of Vyper throws an error (line 16) when compiling the Casper contract due to a syntax change of "units". +NOTE: The latest version of Vyper throws an error when compiling the Casper contract due to a syntax changes NOTE: This not needed if steps above followed @@ -59,36 +64,24 @@ The guide on how to install Vyper can be found [here](https://github.com/ethereu ## How to Build and Deploy Casper Contract -In this example we will be using [eth-tester](https://github.com/ethereum/eth-tester). - -#### Step 1: Requirements - -Specifics (imports, web3 Instance) Deploying the contract depends on the framework. Make sure to import all necessary packages (decimal, web3, vyper, eth_tester, ...). - -We assume, you already set-up the environment and that you are able to connect to a runnning node via web3. - -#### Create an Instance of Web3 (eth-tester) - You need a running web3 instance to connect to the Ethereum network. The web3 object is required to interact with the network. More information: [Link to the web3.py documentation.](https://github.com/ethereum/web3.py) -We will later refer to the Web3 instance `w3`: -```bash -w3 = Web3(PUT_YOUR_PROVIDER_HERE) ## Create an instance of the web3 object -``` +We will later refer to the Web3 instance `w3`. -### Step 2: Raise the Gas Limit +NOTE: the Examples are given using web3.py, so some commands will be slightly different in other web3 versions. -The casper contract costs alot of gas for all its tasks. When you deploy the contract via a normal create transaction, make sure that the block gas limit is high enough. We initially set the limit to 1GW(`10**9 wei`) +### Step 1: Raise the Gas Limit +The Casper contract costs a lot of gas. When you deploy the contract via a normal create transaction, make sure that the block gas limit is high enough. We initially set the limit to 1GW(`10**9 wei`). -### Step 4: Deploy Helper Contracts +### Step 2: Deploy Helper Contracts -NOTE: In addition to the two helper contracts `msg_hasher` and `purity_checker` you also need to deploy the `rlp_decoder` Contract. On a production chain, an `rlp_decoder` contract is already deployed and vyper’s standard internal library knows it’s address and gives vyper contracts access to some functionality at that address. +NOTE: In addition to the two helper contracts `msg_hasher` and `purity_checker` you also need to deploy the `rlp_decoder` Contract. On a production chain, the `rlp_decoder` contract is already deployed and vyper’s standard internal library knows it’s address and gives Vyper contracts access to some functionality at that address. -**When using a test chain, these helper contract must be deployed before the casper contract. `rlp_decoder` must be deployed before compiling the casper contract** +**When using a test chain, these helper contract must ALL be deployed before the Casper contract. `rlp_decoder` should be deployed first** -NOTE: These helper contracts can be deployed via the below pre-signed txs. Instructions for compiling and deploying via other methods will soon be available. +NOTE: These helper contracts can be deployed via the below pre-signed txs. Instructions for compiling and deploying via other methods will soon be available, as these contracts are currently written in Serpent and are in the process of being rewritten in Vyper LLL. #### Define Address & Transaction Hex @@ -110,6 +103,8 @@ PURITY_CHECKER_TX_HEX = "0xf90467808506fc23ac00830583c88080b904546104428061000e6 #### Fund Senders of Contract With 0.1 Ether to Deploy TXs +You need to fund these accounts to deploy the helper contracts, because the transactions are already signed. + ```bash w3.eth.sendTransaction({'to': VYPER_RLP_DECODER_TX_SENDER, 'value': 10**17}) w3.eth.sendTransaction({'to': PURITY_CHECKER_TX_SENDER, 'value': 10**17}) @@ -118,6 +113,9 @@ w3.eth.sendTransaction({'to': MSG_HASHER_TX_SENDER, 'value': 10**17}) #### Deploy Dependency Contracts +Once the accounts are funded, the transactions are deployed as follows: +first you *sendRawTransaction*, then *getTransactionReceipt*, and finally get the contract address. + ```bash rlp_tx_hash = w3.eth.sendRawTransaction(VYPER_RLP_DECODER_TX_HEX) rlp_receipt = w3.eth.getTransactionReceipt(rlp_tx_hash) @@ -132,8 +130,7 @@ purity_receipt = w3.eth.getTransactionReceipt(purity_tx_hash) purity_checker_address = purity_receipt.contractAddress ``` -### Step 5: Casper Parameters - +### Step 3: Defining Casper Parameters [Detailed Explaination of Casper Parameters](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1011.md#casper-contract-params) @@ -147,59 +144,81 @@ BASE_PENALTY_FACTOR = Decimal('0.002') MIN_DEPOSIT_SIZE = 1000 * 10**18 # 1000 ether ``` -### Step 6: Compiling and Deploying Casper +### Step 4: Compile the Capser Contract + +Before deploying the contract, we need to compile it and retrieve the byte-code as well as the abi. -Before deploying the contract, we need to compile it and retrieve the bytecode as well as the abi. +NOTE: You need the specific version of vyper in order to compile the current contract without errors (see above). -NOTE: You need the specific version of vyper in order to compile the current contract without errors (see above) +Navigate to the directory where the `simple_casper.v.py` contract is stored (inside /casper/casper/contracts). -move to the directory where the `simple_casper` contract is stored. +Generate the `casper_bytecode`: -Command to get the `casper_bytecode` ```console vyper simple_casper.v.py ``` -Command to get the `casper_abi` +Generate the `casper_abi`: ```console vyper -f abi simple_casper.v.py ``` -Now you can create the Casper contract +NOTE: the output from these commands should be saved so they can be deployed. + +### Step 5: Deploy the Capser Contract + +First you need to make sure you have sufficient funds on your `base_sender` account to deploy the Casper contract. + +You must also define the null_sender. In [EIP1011](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1011.md) null_sender is defined as 2^(160)-1 converted into HEX. But for testing purposes it may be sufficient to use a preexisting known address as the null_sender. + +```bash +base_sender = ADDRESS_TO_DEPLOY_CASPER_CONTRACT #ensure account has enough Ether +null_sender = '0xffffffffffffffffffffffffffffffffffffffff' +#for testing purposes you may need to set the null_sender address to one of your addresses +``` +Create the contract object, supplying the abi, and the bytecode. ```bash Casper = w3.eth.contract(abi=casper_abi, bytecode=casper_bytecode) ``` -Deploy the contract and make sure you send enough gas along. We recommend to set the gas limit to `10**7` gas. Make sure that your `base_sender` address has enough ether. +Deploy the contract and make sure you send enough gas along. We recommend to set the gas limit to `10**7` gas. Make sure that your `base_sender` address has enough ether. This will return return the transaction hash of the Casper contract. -```console -Casper.constructor().transact({'from': base_sender, 'gas': 10**7}) #deploy casper contract +```bash +tx_hash = Casper.constructor().transact({'from': base_sender, 'gas': 10**7}) #deploy Casper contract ``` +Use the transaction hash to retrieve the Casper transaction receipt. ```bash +tx_receipt = w3.eth.getTransactionReceipt(tx_hash) #gets the tx_reciept of the contract +``` +Use the transaction receipt object to get the address of the deployed Casper contract. -casper_bytecode = compiler.compile(casper_code) #using vyper -casper_abi = compiler.mk_full_signature(casper_code) #using vyper -base_sender = base_tester.get_accounts()[-1] #account created by eth-tester containing 1 million eth -null_sender = base_tester.get_accounts()[-2] +```bash +casper_address = tx_receipt.contractAddress #gets the address of the Casper contract +``` -Casper = w3.eth.contract(abi=casper_abi, bytecode=casper_bytecode) #cteates casper contract object -tx_hash = Casper.constructor().transact({'from': base_sender}) #deploy casper contract -tx_receipt = w3.eth.getTransactionReceipt(tx_hash) +### Step 6: Init Capser Contract -casper_address = tx_receipt.contractAddress +Fund the Casper Contract. -w3.eth.sendTransaction({'to': casper_address, 'value': 10**21}) +```bash +w3.eth.sendTransaction({'to': casper_address, 'value': 10**21}) # funds the Casper contract with 1000 Ether +``` +Retrieve the deployed Casper contract object from your network. +```bash casper_contract = w3.eth.contract(address=casper_address, abi=casper_abi) +``` + +Pass in the casper parameters and call the init function. +```bash casper_args = [EPOCH_LENGTH, WARM_UP_PERIOD, WITHDRAWAL_DELAY, DYNASTY_LOGOUT_DELAY, msg_hasher_address, purity_checker_address, null_sender, BASE_INTEREST_FACTOR, BASE_PENALTY_FACTOR, MIN_DEPOSIT_SIZE] -casper_contract.functions.init(*casper_args).transact() +casper_contract.functions.init(*casper_args).transact() # initialize the Casper contract with the previously defined Casper parameters ``` - ## Contribute Feel free to ask questions in our [Gitter room](https://gitter.im/ethereum/casper) or open an [issue](https://github.com/ethereum/casper/issues) for feature requests or bug reports. Feel free to make a PR! From cd9e8d11282bb728e1e2876a80897d16a6caa97f Mon Sep 17 00:00:00 2001 From: William Schwartz Date: Mon, 11 Jun 2018 14:35:48 -0700 Subject: [PATCH 08/10] minor syntax fixes --- README.md | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 1296a94..50d0e1e 100644 --- a/README.md +++ b/README.md @@ -69,19 +69,19 @@ You need a running web3 instance to connect to the Ethereum network. The web3 ob We will later refer to the Web3 instance `w3`. -NOTE: the Examples are given using web3.py, so some commands will be slightly different in other web3 versions. +NOTE: The Examples are given using web3.py, so some commands will be slightly different in other web3 versions. ### Step 1: Raise the Gas Limit -The Casper contract costs a lot of gas. When you deploy the contract via a normal create transaction, make sure that the block gas limit is high enough. We initially set the limit to 1GW(`10**9 wei`). +The Casper contract costs a lot of gas. When you deploy the contract via a normal create transaction, make sure that the block gas limit is high enough. It is recommended to set the block gas limit to `10**9 wei`. ### Step 2: Deploy Helper Contracts -NOTE: In addition to the two helper contracts `msg_hasher` and `purity_checker` you also need to deploy the `rlp_decoder` Contract. On a production chain, the `rlp_decoder` contract is already deployed and vyper’s standard internal library knows it’s address and gives Vyper contracts access to some functionality at that address. +NOTE: In addition to the two helper contracts `msg_hasher` and `purity_checker` you also need to deploy the `rlp_decoder` Contract. On a production chain, the `rlp_decoder` contract is already deployed and Vyper’s standard internal library knows it’s address and gives Vyper contracts access to some functionality at that address. -**When using a test chain, these helper contract must ALL be deployed before the Casper contract. `rlp_decoder` should be deployed first** +**When using a test chain, these helper contract must ALL be deployed before the Casper contract. `rlp_decoder` should be deployed first.** -NOTE: These helper contracts can be deployed via the below pre-signed txs. Instructions for compiling and deploying via other methods will soon be available, as these contracts are currently written in Serpent and are in the process of being rewritten in Vyper LLL. +NOTE: These helper contracts can be deployed via the pre-signed txs below. Instructions for compiling and deploying via other methods will soon be available, as these contracts are currently written in Serpent and are in the process of being rewritten in Vyper LLL. #### Define Address & Transaction Hex @@ -103,7 +103,7 @@ PURITY_CHECKER_TX_HEX = "0xf90467808506fc23ac00830583c88080b904546104428061000e6 #### Fund Senders of Contract With 0.1 Ether to Deploy TXs -You need to fund these accounts to deploy the helper contracts, because the transactions are already signed. +You need to fund these accounts to deploy the helper contracts because the transactions are already signed. ```bash w3.eth.sendTransaction({'to': VYPER_RLP_DECODER_TX_SENDER, 'value': 10**17}) @@ -114,7 +114,7 @@ w3.eth.sendTransaction({'to': MSG_HASHER_TX_SENDER, 'value': 10**17}) #### Deploy Dependency Contracts Once the accounts are funded, the transactions are deployed as follows: -first you *sendRawTransaction*, then *getTransactionReceipt*, and finally get the contract address. +First you *sendRawTransaction*, then *getTransactionReceipt*, and finally get the contract address. Theses addresses are necessary for the Casper contract. ```bash rlp_tx_hash = w3.eth.sendRawTransaction(VYPER_RLP_DECODER_TX_HEX) @@ -148,33 +148,33 @@ MIN_DEPOSIT_SIZE = 1000 * 10**18 # 1000 ether Before deploying the contract, we need to compile it and retrieve the byte-code as well as the abi. -NOTE: You need the specific version of vyper in order to compile the current contract without errors (see above). +NOTE: You need the specific version of Vyper in order to compile the current contract without errors (see above). Navigate to the directory where the `simple_casper.v.py` contract is stored (inside /casper/casper/contracts). Generate the `casper_bytecode`: ```console -vyper simple_casper.v.py +$ vyper simple_casper.v.py ``` Generate the `casper_abi`: ```console -vyper -f abi simple_casper.v.py +$ vyper -f abi simple_casper.v.py ``` -NOTE: the output from these commands should be saved so they can be deployed. +NOTE: The output from these commands should be saved to be deployed. -### Step 5: Deploy the Capser Contract +### Step 5: Deploy the Casper Contract First you need to make sure you have sufficient funds on your `base_sender` account to deploy the Casper contract. -You must also define the null_sender. In [EIP1011](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1011.md) null_sender is defined as 2^(160)-1 converted into HEX. But for testing purposes it may be sufficient to use a preexisting known address as the null_sender. +You must also define the null_sender. In [EIP1011](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1011.md) null_sender is defined as `2**160-1` converted into HEX. But for testing purposes it may be sufficient to use a preexisting known address as the null_sender. ```bash base_sender = ADDRESS_TO_DEPLOY_CASPER_CONTRACT #ensure account has enough Ether null_sender = '0xffffffffffffffffffffffffffffffffffffffff' -#for testing purposes you may need to set the null_sender address to one of your addresses +#for testing purposes you may need to set the null_sender address to one of your own addresses ``` Create the contract object, supplying the abi, and the bytecode. @@ -182,30 +182,30 @@ Create the contract object, supplying the abi, and the bytecode. Casper = w3.eth.contract(abi=casper_abi, bytecode=casper_bytecode) ``` -Deploy the contract and make sure you send enough gas along. We recommend to set the gas limit to `10**7` gas. Make sure that your `base_sender` address has enough ether. This will return return the transaction hash of the Casper contract. +Deploy the contract and make sure you send enough gas. We recommend to set the gas limit to `10**7` gas. This will return the transaction hash of the Casper contract. ```bash tx_hash = Casper.constructor().transact({'from': base_sender, 'gas': 10**7}) #deploy Casper contract ``` -Use the transaction hash to retrieve the Casper transaction receipt. +Use the transaction hash to retrieve the transaction receipt. ```bash -tx_receipt = w3.eth.getTransactionReceipt(tx_hash) #gets the tx_reciept of the contract +tx_receipt = w3.eth.getTransactionReceipt(tx_hash) ``` Use the transaction receipt object to get the address of the deployed Casper contract. ```bash -casper_address = tx_receipt.contractAddress #gets the address of the Casper contract +casper_address = tx_receipt.contractAddress ``` -### Step 6: Init Capser Contract +### Step 6: Init Casper Contract Fund the Casper Contract. ```bash w3.eth.sendTransaction({'to': casper_address, 'value': 10**21}) # funds the Casper contract with 1000 Ether ``` -Retrieve the deployed Casper contract object from your network. +Retrieve the deployed Casper object from your network. ```bash casper_contract = w3.eth.contract(address=casper_address, abi=casper_abi) From 62c84b92cac582b564a4101d47ba2c24472d2095 Mon Sep 17 00:00:00 2001 From: William Schwartz Date: Mon, 11 Jun 2018 15:50:24 -0700 Subject: [PATCH 09/10] a few more minor semantic fixes --- README.md | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 50d0e1e..45e6514 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,6 @@ For macOS, with [brew](https://brew.sh/) installed: brew install pandoc # required for a python dependency ``` -NOTE: pip3 is a version of pip using python version 3. - NOTE: we suggest using virtualenv to sandbox your setup. ```bash @@ -37,6 +35,7 @@ For all systems: ```bash pip3 install -r requirements.txt ``` +NOTE: pip3 is a version of pip using python version 3. ## Usage @@ -48,13 +47,13 @@ pip3 install -r requirements.txt pytest tests ``` -## Version of Vyper to Compile Casper +## Vyper Version to Compile Casper -We recommend using the vyper version installed as a dependency from requirements.txt. +We recommend using the Vyper version installed as a dependency from requirements.txt. NOTE: The latest version of Vyper throws an error when compiling the Casper contract due to a syntax changes -NOTE: This not needed if steps above followed +Installing this version separately is not necessary if the steps above are followed. ```bash git clone https://github.com/ethereum/vyper.git@248c723288e84899908048efff4c3e0b12f0b3dc @@ -67,21 +66,21 @@ The guide on how to install Vyper can be found [here](https://github.com/ethereu You need a running web3 instance to connect to the Ethereum network. The web3 object is required to interact with the network. More information: [Link to the web3.py documentation.](https://github.com/ethereum/web3.py) -We will later refer to the Web3 instance `w3`. +We will later refer to the Web3 instance as `w3`. NOTE: The Examples are given using web3.py, so some commands will be slightly different in other web3 versions. ### Step 1: Raise the Gas Limit -The Casper contract costs a lot of gas. When you deploy the contract via a normal create transaction, make sure that the block gas limit is high enough. It is recommended to set the block gas limit to `10**9 wei`. +The Casper contract is very large and uses a lot of gas to be deployed. When you deploy the contract via a normal create transaction, make sure that the block gas limit is high enough. It is recommended to set the block gas limit to `10**9 wei`. ### Step 2: Deploy Helper Contracts -NOTE: In addition to the two helper contracts `msg_hasher` and `purity_checker` you also need to deploy the `rlp_decoder` Contract. On a production chain, the `rlp_decoder` contract is already deployed and Vyper’s standard internal library knows it’s address and gives Vyper contracts access to some functionality at that address. +NOTE: In addition to the two helper contracts `msg_hasher` and `purity_checker` you also need to deploy the `rlp_decoder` contract. On a production chain, the `rlp_decoder` contract is already deployed and Vyper’s standard internal library knows it’s address and gives Vyper contracts access to some functionality at that address. -**When using a test chain, these helper contract must ALL be deployed before the Casper contract. `rlp_decoder` should be deployed first.** +**When using a test chain, these helper contract must ALL be deployed before the Casper contract. The `rlp_decoder` should be deployed first.** -NOTE: These helper contracts can be deployed via the pre-signed txs below. Instructions for compiling and deploying via other methods will soon be available, as these contracts are currently written in Serpent and are in the process of being rewritten in Vyper LLL. +NOTE: These helper contracts can be deployed via the pre-signed txs below. Instructions for compiling and deploying via other methods will soon be available, as these contracts are currently written in Serpent, and are in the process of being rewritten in Vyper LLL. #### Define Address & Transaction Hex @@ -103,7 +102,7 @@ PURITY_CHECKER_TX_HEX = "0xf90467808506fc23ac00830583c88080b904546104428061000e6 #### Fund Senders of Contract With 0.1 Ether to Deploy TXs -You need to fund these accounts to deploy the helper contracts because the transactions are already signed. +You need to fund these accounts to deploy the helper contracts because the transactions are signed by theses accounts, you may also choose to resign the contracts with your own account(s). ```bash w3.eth.sendTransaction({'to': VYPER_RLP_DECODER_TX_SENDER, 'value': 10**17}) @@ -114,7 +113,7 @@ w3.eth.sendTransaction({'to': MSG_HASHER_TX_SENDER, 'value': 10**17}) #### Deploy Dependency Contracts Once the accounts are funded, the transactions are deployed as follows: -First you *sendRawTransaction*, then *getTransactionReceipt*, and finally get the contract address. Theses addresses are necessary for the Casper contract. +First you *sendRawTransaction*, then *getTransactionReceipt*, and finally get the addresses the contracts are deployed at. Theses addresses are necessary for the Casper contract. ```bash rlp_tx_hash = w3.eth.sendRawTransaction(VYPER_RLP_DECODER_TX_HEX) @@ -163,11 +162,11 @@ Generate the `casper_abi`: $ vyper -f abi simple_casper.v.py ``` -NOTE: The output from these commands should be saved to be deployed. +NOTE: The output from these commands must be stored somewhere in order to deploy. ### Step 5: Deploy the Casper Contract -First you need to make sure you have sufficient funds on your `base_sender` account to deploy the Casper contract. +First you need to make sure you have sufficient funds in your `base_sender` account to deploy the Casper contract. You must also define the null_sender. In [EIP1011](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1011.md) null_sender is defined as `2**160-1` converted into HEX. But for testing purposes it may be sufficient to use a preexisting known address as the null_sender. @@ -176,13 +175,13 @@ base_sender = ADDRESS_TO_DEPLOY_CASPER_CONTRACT #ensure account has enough Ether null_sender = '0xffffffffffffffffffffffffffffffffffffffff' #for testing purposes you may need to set the null_sender address to one of your own addresses ``` -Create the contract object, supplying the abi, and the bytecode. +Create the contract object with the abi, and the byte-code generated in step 4. ```bash Casper = w3.eth.contract(abi=casper_abi, bytecode=casper_bytecode) ``` -Deploy the contract and make sure you send enough gas. We recommend to set the gas limit to `10**7` gas. This will return the transaction hash of the Casper contract. +Deploy the contract and make sure you send enough gas. We recommend to set the gas limit to `10**7`. This will return the transaction hash of the Casper contract. ```bash tx_hash = Casper.constructor().transact({'from': base_sender, 'gas': 10**7}) #deploy Casper contract @@ -211,7 +210,7 @@ Retrieve the deployed Casper object from your network. casper_contract = w3.eth.contract(address=casper_address, abi=casper_abi) ``` -Pass in the casper parameters and call the init function. +Pass in the Casper parameters and call the init function. ```bash casper_args = [EPOCH_LENGTH, WARM_UP_PERIOD, WITHDRAWAL_DELAY, DYNASTY_LOGOUT_DELAY, msg_hasher_address, purity_checker_address, null_sender, BASE_INTEREST_FACTOR, BASE_PENALTY_FACTOR, MIN_DEPOSIT_SIZE] From ee0462d8dbb9712c0d1b0287a7aff7d4e9c63260 Mon Sep 17 00:00:00 2001 From: William Schwartz Date: Mon, 11 Jun 2018 16:04:14 -0700 Subject: [PATCH 10/10] on last read over found a few more mistakes --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 45e6514..2bcfe3f 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ pytest tests We recommend using the Vyper version installed as a dependency from requirements.txt. -NOTE: The latest version of Vyper throws an error when compiling the Casper contract due to a syntax changes +NOTE: The latest version of Vyper throws an error when compiling the Casper contract due to syntax changes. Installing this version separately is not necessary if the steps above are followed. @@ -76,9 +76,9 @@ The Casper contract is very large and uses a lot of gas to be deployed. When you ### Step 2: Deploy Helper Contracts -NOTE: In addition to the two helper contracts `msg_hasher` and `purity_checker` you also need to deploy the `rlp_decoder` contract. On a production chain, the `rlp_decoder` contract is already deployed and Vyper’s standard internal library knows it’s address and gives Vyper contracts access to some functionality at that address. +NOTE: In addition to the two helper contracts `msg_hasher` and `purity_checker` you also need to deploy the `rlp_decoder` contract. On a production chain, the `rlp_decoder` contract is already deployed and Vyper’s standard internal library knows its address and gives Vyper contracts access to some functionality at that address. -**When using a test chain, these helper contract must ALL be deployed before the Casper contract. The `rlp_decoder` should be deployed first.** +**When using a test chain, these helper contracts must ALL be deployed before the Casper contract. The `rlp_decoder` should be deployed first.** NOTE: These helper contracts can be deployed via the pre-signed txs below. Instructions for compiling and deploying via other methods will soon be available, as these contracts are currently written in Serpent, and are in the process of being rewritten in Vyper LLL. @@ -102,7 +102,7 @@ PURITY_CHECKER_TX_HEX = "0xf90467808506fc23ac00830583c88080b904546104428061000e6 #### Fund Senders of Contract With 0.1 Ether to Deploy TXs -You need to fund these accounts to deploy the helper contracts because the transactions are signed by theses accounts, you may also choose to resign the contracts with your own account(s). +You need to fund the accounts defined above to deploy the helper contracts byte-code, as the transactions are already signed by those accounts defined above. You may also choose to re-sign the contracts with your own account(s). ```bash w3.eth.sendTransaction({'to': VYPER_RLP_DECODER_TX_SENDER, 'value': 10**17})