uint size = (_auditPath.length - off) / 33;
for example: _auditPath.length - off = 65.
before 33 is ok. after 32 data (65-33) is is arbitrary.
|
function merkleProve(bytes memory _auditPath, bytes32 _root) internal pure returns (bytes memory) { |
|
uint256 off = 0; |
|
bytes memory value; |
|
(value, off) = ZeroCopySource.NextVarBytes(_auditPath, off); |
|
|
|
bytes32 hash = Utils.hashLeaf(value); |
|
uint size = (_auditPath.length - off) / 33; |
|
bytes32 nodeHash; |
|
byte pos; |
|
for (uint i = 0; i < size; i++) { |
|
(pos, off) = ZeroCopySource.NextByte(_auditPath, off); |
|
(nodeHash, off) = ZeroCopySource.NextHash(_auditPath, off); |
|
if (pos == 0x00) { |
|
hash = Utils.hashChildren(nodeHash, hash); |
|
} else if (pos == 0x01) { |
|
hash = Utils.hashChildren(hash, nodeHash); |
|
} else { |
|
revert("merkleProve, NextByte for position info failed"); |
|
} |
|
} |
|
require(hash == _root, "merkleProve, expect root is not equal actual root"); |
|
return value; |
|
} |
uint size = (_auditPath.length - off) / 33;
for example: _auditPath.length - off = 65.
before 33 is ok. after 32 data (65-33) is is arbitrary.
eth-contracts/contracts/core/cross_chain_manager/libs/EthCrossChainUtils.sol
Lines 44 to 66 in d16252b