Move ABI checks to be first in the code (#10)

This commit is contained in:
Alex Beregszaszi 2020-05-13 16:49:07 +01:00 committed by GitHub
parent 4d493e70af
commit d18c12b776
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -75,6 +75,11 @@ contract DepositContract is IDepositContract {
bytes calldata signature,
bytes32 deposit_data_root
) override external payable {
// Extended ABI length checks since dynamic types are used.
require(pubkey.length == PUBKEY_LENGTH);
require(withdrawal_credentials.length == WITHDRAWAL_CREDENTIALS_LENGTH);
require(signature.length == SIGNATURE_LENGTH);
// Avoid overflowing the Merkle tree (and prevent edge case in computing `branch`)
require(deposit_count < MAX_DEPOSIT_COUNT);
@ -84,11 +89,6 @@ contract DepositContract is IDepositContract {
uint deposit_amount = msg.value / GWEI;
require(deposit_amount < 2**64);
// Length checks for safety
require(pubkey.length == PUBKEY_LENGTH);
require(withdrawal_credentials.length == WITHDRAWAL_CREDENTIALS_LENGTH);
require(signature.length == SIGNATURE_LENGTH);
// Emit `DepositEvent` log
bytes memory amount = to_little_endian_64(uint64(deposit_amount));
emit DepositEvent(