From b236ce7a9a5a409d91cb8f647b836062184e81f0 Mon Sep 17 00:00:00 2001 From: MrChico Date: Wed, 13 May 2020 15:46:58 +0200 Subject: [PATCH] Defensive handling of dead path (#13) --- deposit_contract.sol | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index 81c33a288..a94e8fbf0 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -121,11 +121,14 @@ contract DepositContract is IDepositContract { for (uint height = 0; height < DEPOSIT_CONTRACT_TREE_DEPTH; height++) { if ((size & 1) == 1) { branch[height] = node; - break; + return; } node = sha256(abi.encodePacked(branch[height], node)); size /= 2; } + // As the loop should always end prematurely with the `return` statement, + // this code should be unreachable. We assert `false` just to be safe. + assert(false); } function to_little_endian_64(uint64 value) internal pure returns (bytes memory ret) {