@@ -4,7 +4,10 @@ import { Spec, boolean, equivalentAsync, fieldWithRng } from '../../testing/equi
44import { Random } from '../../testing/property.js' ;
55import { assert } from '../gadgets/common.js' ;
66import { Gadgets } from '../gadgets/gadgets.js' ;
7+ import { Gates } from '../gates.js' ;
78import { constraintSystem , contains } from '../../testing/constraint-system.js' ;
9+ import { FeatureFlags } from '../../proof-system/feature-flags.js' ;
10+ import { Cache } from '../../proof-system/cache.js' ;
811
912let uint = ( n : number | bigint ) : Spec < bigint , Field > => {
1013 return fieldWithRng ( Random . bignat ( ( 1n << BigInt ( n ) ) - 1n ) ) ;
@@ -45,3 +48,56 @@ let uint = (n: number | bigint): Spec<bigint, Field> => {
4548 }
4649 ) ;
4750}
51+
52+ // Runtime table tests
53+ {
54+ let RuntimeTable = ZkProgram ( {
55+ name : 'runtime-table' ,
56+ methods : {
57+ runtimeTable : {
58+ privateInputs : [ Field , Field , Field ] ,
59+ async method ( v0 : Field , v1 : Field , v2 : Field ) {
60+ let tableId = 2 ;
61+ let indices = [ 0n , 1n , 2n , 3n , 4n , 5n , 6n , 7n , 8n , 9n ] ;
62+ Gates . addRuntimeTableConfig ( tableId , indices ) ;
63+ // values are inserted into the table in the given positions
64+ Gadgets . inTable ( tableId , [ 5n , v0 ] , [ 6n , v1 ] , [ 7n , v2 ] ) ;
65+ // a second time can be used to check more values in more positions
66+ Gadgets . inTable ( tableId , [ 2n , v0 ] ) ;
67+ // can ask for the same index asked previously
68+ Gadgets . inTable ( tableId , [ 6n , v1 ] ) ;
69+ // even multiple times in the same call
70+ Gadgets . inTable ( tableId , [ 6n , v1 ] , [ 6n , v1 ] ) ;
71+ } ,
72+ } ,
73+ } ,
74+ } ) ;
75+
76+ // constraint system sanity check
77+
78+ constraintSystem . fromZkProgram ( RuntimeTable , 'runtimeTable' , contains ( [ 'Lookup' ] ) ) ;
79+
80+ // check feature flags are set up correctly
81+ const featureFlags = await FeatureFlags . fromZkProgram ( RuntimeTable , true ) ;
82+ assert ( featureFlags . lookup === true ) ;
83+ assert ( featureFlags . runtimeTables === true ) ;
84+
85+ await RuntimeTable . compile ( {
86+ cache : Cache . None ,
87+ forceRecompile : true ,
88+ withRuntimeTables : true ,
89+ } ) ;
90+
91+ await equivalentAsync ( { from : [ uint ( 12 ) , uint ( 12 ) , uint ( 12 ) ] , to : boolean } , { runs : 1 } ) (
92+ ( x , y , z ) => {
93+ assert ( x < 1n << 12n ) ;
94+ assert ( y < 1n << 12n ) ;
95+ assert ( z < 1n << 12n ) ;
96+ return true ;
97+ } ,
98+ async ( x , y , z ) => {
99+ let { proof } = await RuntimeTable . runtimeTable ( x , y , z ) ;
100+ return await RuntimeTable . verify ( proof ) ;
101+ }
102+ ) ;
103+ }
0 commit comments