@@ -102,3 +102,111 @@ describe.skip('AVM proven gadgets test', () => {
102102 expect ( result . revertCode . isOK ( ) ) . toBe ( true ) ;
103103 } , 300_000 ) ;
104104} ) ;
105+
106+ describe ( 'AVM proven gadgets test: test vectors' , ( ) => {
107+ let tester : AvmProvingTester ;
108+ let worldStateService : NativeWorldStateService ;
109+
110+ const sender = AztecAddress . fromNumber ( 42 ) ;
111+ let avmGadgetsTestContract : ContractInstanceWithAddress ;
112+
113+ beforeEach ( async ( ) => {
114+ worldStateService = await NativeWorldStateService . tmp ( ) ;
115+ tester = await AvmProvingTester . new ( worldStateService , /*checkCircuitOnly=*/ false , /*globals=*/ defaultGlobals ( ) ) ;
116+ avmGadgetsTestContract = await tester . registerAndDeployContract (
117+ /*constructorArgs=*/ [ ] ,
118+ sender ,
119+ /*contractArtifact=*/ AvmGadgetsTestContractArtifact ,
120+ ) ;
121+ } ) ;
122+
123+ afterEach ( async ( ) => {
124+ await worldStateService . close ( ) ;
125+ } ) ;
126+
127+ it ( 'keccak_hash_test_vector' , async ( ) => {
128+ // keccak256([0x00, 0x01, ..., 0x09]) = f0ae86a6257e615bce8b0fe73794934deda00c13d58f80b466a9354e306c9eb0
129+ const input = [ 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 ] ;
130+ const result = await tester . executeTxWithLabel (
131+ /*txLabel=*/ 'AvmGadgetsTest/keccak_hash' ,
132+ /*sender=*/ sender ,
133+ /*setupCalls=*/ [ ] ,
134+ /*appCalls=*/ [
135+ {
136+ address : avmGadgetsTestContract . address ,
137+ fnName : 'keccak_hash' ,
138+ args : [ input ] ,
139+ } ,
140+ ] ,
141+ ) ;
142+ expect ( result . revertCode . isOK ( ) ) . toBe ( true ) ;
143+ const outputBytes = result . getAppLogicReturnValues ( ) ?. [ 0 ] ?. values ?. map ( fr => Number ( fr . toBigInt ( ) ) ) ;
144+ const expected = [ ...Buffer . from ( 'f0ae86a6257e615bce8b0fe73794934deda00c13d58f80b466a9354e306c9eb0' , 'hex' ) ] ;
145+ expect ( outputBytes ) . toEqual ( expected ) ;
146+ } , 180_000 ) ;
147+
148+ it ( 'keccak_hash_test_vector_300bytes' , async ( ) => {
149+ // 300 bytes exceeds the keccak256 rate (136 bytes), triggering multi-block permutation.
150+ // keccak256([0x00, 0x01, ..., 0x2b, 0x00, 0x01, ..., 0x2b, ...]) for 300 bytes
151+ const input = Array . from ( { length : 300 } , ( _ , i ) => i % 256 ) ;
152+ const result = await tester . executeTxWithLabel (
153+ /*txLabel=*/ 'AvmGadgetsTest/keccak_hash_300' ,
154+ /*sender=*/ sender ,
155+ /*setupCalls=*/ [ ] ,
156+ /*appCalls=*/ [
157+ {
158+ address : avmGadgetsTestContract . address ,
159+ fnName : 'keccak_hash_300' ,
160+ args : [ input ] ,
161+ } ,
162+ ] ,
163+ ) ;
164+ expect ( result . revertCode . isOK ( ) ) . toBe ( true ) ;
165+ const outputBytes = result . getAppLogicReturnValues ( ) ?. [ 0 ] ?. values ?. map ( fr => Number ( fr . toBigInt ( ) ) ) ;
166+ const expected = [ ...Buffer . from ( 'a679e749a6af300c36e7ff2255d220864eab27b382f9cfdc5aa4d13563ba36ff' , 'hex' ) ] ;
167+ expect ( outputBytes ) . toEqual ( expected ) ;
168+ } , 180_000 ) ;
169+
170+ it ( 'sha256_hash_test_vector' , async ( ) => {
171+ // sha256([0x00, 0x01, ..., 0x09]) = 1f825aa2f0020ef7cf91dfa30da4668d791c5d4824fc8e41354b89ec05795ab3
172+ const input = [ 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 ] ;
173+ const result = await tester . executeTxWithLabel (
174+ /*txLabel=*/ 'AvmGadgetsTest/sha256_hash_10' ,
175+ /*sender=*/ sender ,
176+ /*setupCalls=*/ [ ] ,
177+ /*appCalls=*/ [
178+ {
179+ address : avmGadgetsTestContract . address ,
180+ fnName : 'sha256_hash_10' ,
181+ args : [ input ] ,
182+ } ,
183+ ] ,
184+ ) ;
185+ expect ( result . revertCode . isOK ( ) ) . toBe ( true ) ;
186+ const outputBytes = result . getAppLogicReturnValues ( ) ?. [ 0 ] ?. values ?. map ( fr => Number ( fr . toBigInt ( ) ) ) ;
187+ const expected = [ ...Buffer . from ( '1f825aa2f0020ef7cf91dfa30da4668d791c5d4824fc8e41354b89ec05795ab3' , 'hex' ) ] ;
188+ expect ( outputBytes ) . toEqual ( expected ) ;
189+ } , 180_000 ) ;
190+
191+ it ( 'sha256_hash_test_vector_255bytes' , async ( ) => {
192+ // 255 bytes exceeds the sha256 block size (64 bytes), triggering multi-block compression.
193+ // sha256([0x00, 0x01, ..., 0xfe]) = 3f8591112c6bbe5c963965954e293108b7208ed2af893e500d859368c654eabe
194+ const input = Array . from ( { length : 255 } , ( _ , i ) => i ) ;
195+ const result = await tester . executeTxWithLabel (
196+ /*txLabel=*/ 'AvmGadgetsTest/sha256_hash_255' ,
197+ /*sender=*/ sender ,
198+ /*setupCalls=*/ [ ] ,
199+ /*appCalls=*/ [
200+ {
201+ address : avmGadgetsTestContract . address ,
202+ fnName : 'sha256_hash_255' ,
203+ args : [ input ] ,
204+ } ,
205+ ] ,
206+ ) ;
207+ expect ( result . revertCode . isOK ( ) ) . toBe ( true ) ;
208+ const outputBytes = result . getAppLogicReturnValues ( ) ?. [ 0 ] ?. values ?. map ( fr => Number ( fr . toBigInt ( ) ) ) ;
209+ const expected = [ ...Buffer . from ( '3f8591112c6bbe5c963965954e293108b7208ed2af893e500d859368c654eabe' , 'hex' ) ] ;
210+ expect ( outputBytes ) . toEqual ( expected ) ;
211+ } , 180_000 ) ;
212+ } ) ;
0 commit comments