diff --git a/solidity/contracts/BTCUtils.sol b/solidity/contracts/BTCUtils.sol index c4e74e1a..975edfb3 100644 --- a/solidity/contracts/BTCUtils.sol +++ b/solidity/contracts/BTCUtils.sol @@ -802,7 +802,11 @@ library BTCUtils { // i moves in increments of 32 for (uint i = 0; i < _tree.length; i += 32) { if (_idx % 2 == 1) { - _current = _hash256MerkleStep(_tree.slice32(i), _current); + bytes32 _left = _tree.slice32(i); + if (_left == _current) { + return false; + } + _current = _hash256MerkleStep(_left, _current); } else { _current = _hash256MerkleStep(_current, _tree.slice32(i)); } diff --git a/testVectors.json b/testVectors.json index a1d3bc7f..b816ffcc 100644 --- a/testVectors.json +++ b/testVectors.json @@ -888,6 +888,20 @@ "index": 0 }, "output": false + }, + { + "input": { + "proof": "0x0D02210B9177CFC8193B95254473FF7BD986ED1179C276D12BAD5BDBA2403AD40D02210B9177CFC8193B95254473FF7BD986ED1179C276D12BAD5BDBA2403AD4D467A41E18243ABAB48B946D4E235092F87C3F1E1E2B87BC06D3BE1F29E13DCEF94B61259C7E9AF3455B277275800D0D6A58B929EEDF9E0153A6EF2278A5D534", + "index": 2 + }, + "output": true + }, + { + "input": { + "proof": "0x0D02210B9177CFC8193B95254473FF7BD986ED1179C276D12BAD5BDBA2403AD40D02210B9177CFC8193B95254473FF7BD986ED1179C276D12BAD5BDBA2403AD4D467A41E18243ABAB48B946D4E235092F87C3F1E1E2B87BC06D3BE1F29E13DCEF94B61259C7E9AF3455B277275800D0D6A58B929EEDF9E0153A6EF2278A5D534", + "index": 3 + }, + "output": false } ], "getErrBadLength": [