@@ -2,7 +2,8 @@ import fc from 'fast-check';
22import assert from 'assert/strict' ;
33import { equalsBytes } from 'ethereum-cryptography/utils' ;
44import { makeMerkleTree , getProof , processProof , getMultiProof , processMultiProof , isValidMerkleTree , renderMerkleTree } from './core' ;
5- import { hex } from './bytes' ;
5+ import { compareBytes , hex } from './bytes' ;
6+ import { keccak256 } from 'ethereum-cryptography/keccak' ;
67
78const zero = new Uint8Array ( 32 ) ;
89
@@ -72,6 +73,23 @@ describe('core error conditions', () => {
7273 / ^ E r r o r : E x p e c t e d n o n - z e r o n u m b e r o f n o d e s $ / ,
7374 ) ;
7475 } ) ;
76+
77+ it ( 'multiproof invariants' , ( ) => {
78+ const leaf = keccak256 ( Uint8Array . of ( 42 ) ) ;
79+ const tree = makeMerkleTree ( [ leaf , zero ] ) ;
80+
81+ const badMultiProof = {
82+ leaves : [ 128 , 129 ] . map ( n => keccak256 ( Uint8Array . of ( n ) ) ) . sort ( compareBytes ) ,
83+ proof : [ leaf , leaf ] ,
84+ proofFlags : [ true , true , false ] ,
85+ } ;
86+
87+ assert . throws (
88+ ( ) => processMultiProof ( badMultiProof ) ,
89+ / ^ E r r o r : B r o k e n i n v a r i a n t $ / ,
90+ ) ;
91+ } ) ;
92+
7593} ) ;
7694
7795class PrettyBytes extends Uint8Array {
0 commit comments