Use less constants and fold the expressions into require statements (#24)

This commit is contained in:
MrChico 2020-05-15 18:46:38 +02:00 committed by GitHub
parent d1a5556a74
commit 8f2c64485e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 9 deletions

View File

@ -8,7 +8,7 @@ The motivation is to run the SMTChecker and the new Yul IR generator option (`--
## Using this with the tests ## Using this with the tests
1. Create the `deposit_contract.json` with running `make` (this requires `solc` to be in the path) 1. Create the `deposit_contract.json` by running `make` (this requires `solc` to be in the path)
2. Download [eth2.0-specs](https://github.com/ethereum/eth2.0-specs) 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` 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) 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)

View File

@ -40,13 +40,9 @@ interface ERC165 {
contract DepositContract is IDepositContract, ERC165 { contract DepositContract is IDepositContract, ERC165 {
uint constant GWEI = 1e9; uint constant GWEI = 1e9;
uint constant MIN_DEPOSIT_AMOUNT = 1 ether;
uint constant DEPOSIT_CONTRACT_TREE_DEPTH = 32; uint constant DEPOSIT_CONTRACT_TREE_DEPTH = 32;
// NOTE: this also ensures `deposit_count` will fit into 64-bits // NOTE: this also ensures `deposit_count` will fit into 64-bits
uint constant MAX_DEPOSIT_COUNT = 2**DEPOSIT_CONTRACT_TREE_DEPTH - 1; uint constant MAX_DEPOSIT_COUNT = 2**DEPOSIT_CONTRACT_TREE_DEPTH - 1;
uint constant PUBKEY_LENGTH = 48; // bytes
uint constant WITHDRAWAL_CREDENTIALS_LENGTH = 32; // bytes
uint constant SIGNATURE_LENGTH = 96; // bytes
bytes32[DEPOSIT_CONTRACT_TREE_DEPTH] branch; bytes32[DEPOSIT_CONTRACT_TREE_DEPTH] branch;
uint256 deposit_count; uint256 deposit_count;
@ -87,12 +83,12 @@ contract DepositContract is IDepositContract, ERC165 {
bytes32 deposit_data_root bytes32 deposit_data_root
) override external payable { ) override external payable {
// Extended ABI length checks since dynamic types are used. // Extended ABI length checks since dynamic types are used.
require(pubkey.length == PUBKEY_LENGTH, "DepositContract: invalid pubkey length"); require(pubkey.length == 48, "DepositContract: invalid pubkey length");
require(withdrawal_credentials.length == WITHDRAWAL_CREDENTIALS_LENGTH, "DepositContract: invalid withdrawal_credentials length"); require(withdrawal_credentials.length == 32, "DepositContract: invalid withdrawal_credentials length");
require(signature.length == SIGNATURE_LENGTH, "DepositContract: invalid signature length"); require(signature.length == 96, "DepositContract: invalid signature length");
// Check deposit amount // Check deposit amount
require(msg.value >= MIN_DEPOSIT_AMOUNT, "DepositContract: deposit value too low"); require(msg.value >= 1 ether, "DepositContract: deposit value too low");
require(msg.value % GWEI == 0, "DepositContract: deposit value not multiple of gwei"); require(msg.value % GWEI == 0, "DepositContract: deposit value not multiple of gwei");
uint deposit_amount = msg.value / GWEI; uint deposit_amount = msg.value / GWEI;
require(deposit_amount <= type(uint64).max, "DepositContract: deposit value too high"); require(deposit_amount <= type(uint64).max, "DepositContract: deposit value too high");