From a8ed83e08784d195980c5b517bf51ede3bb7e71c Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 12 May 2020 19:04:18 +0100 Subject: [PATCH] Inline bytesN(0) instead of custom zero_bytesN vars (#8) Co-authored-by: Martin Lundfall --- deposit_contract.sol | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index c68538974..0f751969e 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -50,7 +50,6 @@ contract DepositContract is IDepositContract { } function get_deposit_root() override external view returns (bytes32) { - bytes24 zero_bytes24; bytes32 node; uint size = deposit_count; for (uint height = 0; height < DEPOSIT_CONTRACT_TREE_DEPTH; height++) { @@ -63,7 +62,7 @@ contract DepositContract is IDepositContract { return sha256(abi.encodePacked( node, to_little_endian_64(uint64(deposit_count)), - zero_bytes24 + bytes24(0) )); } @@ -104,18 +103,14 @@ contract DepositContract is IDepositContract { ); // Compute deposit data root (`DepositData` hash tree root) - // These are helpers and are implicitly initialised to zero. - bytes16 zero_bytes16; - bytes24 zero_bytes24; - bytes32 zero_bytes32; - bytes32 pubkey_root = sha256(abi.encodePacked(pubkey, zero_bytes16)); + bytes32 pubkey_root = sha256(abi.encodePacked(pubkey, bytes16(0))); bytes32 signature_root = sha256(abi.encodePacked( sha256(abi.encodePacked(bytes(signature[:64]))), - sha256(abi.encodePacked(bytes(signature[64:]), zero_bytes32)) + sha256(abi.encodePacked(bytes(signature[64:]), bytes32(0))) )); bytes32 node = sha256(abi.encodePacked( sha256(abi.encodePacked(pubkey_root, withdrawal_credentials)), - sha256(abi.encodePacked(amount, zero_bytes24, signature_root)) + sha256(abi.encodePacked(amount, bytes24(0), signature_root)) )); // Verify computed and expected deposit data roots match require(node == deposit_data_root);