@@ -44,137 +44,197 @@ describe("StateTransitionProver", () => {
44
44
} ) ;
45
45
}
46
46
47
- it . each ( [
48
- [ true , true ] ,
49
- [ true , false ] ,
50
- [ false , false ] ,
51
- ] ) (
52
- "should retain empty currentBatchHash for padded dummies" ,
53
- async ( applied , witnessRoot ) => {
47
+ function applyToTree (
48
+ tree : RollupMerkleTree ,
49
+ batches : StateTransitionProvableBatch [ ] ,
50
+ indizes : number [ ]
51
+ ) {
52
+ const flat = batches . flatMap ( ( batch ) => batch . batch ) ;
53
+ indizes . forEach ( ( index ) => {
54
+ const st = flat [ index ] . stateTransition ;
55
+ if ( st . to . isSome ) {
56
+ tree . setLeaf ( st . path . toBigInt ( ) , st . to . value ) ;
57
+ }
58
+ } ) ;
59
+ }
60
+
61
+ describe ( "currentBatchHash" , ( ) => {
62
+ it . each ( [
63
+ [ true , true ] ,
64
+ [ true , false ] ,
65
+ [ false , false ] ,
66
+ ] ) (
67
+ "should retain empty currentBatchHash for padded dummies" ,
68
+ async ( applied , witnessRoot ) => {
69
+ const batch = StateTransitionProvableBatch . fromBatches ( [
70
+ {
71
+ stateTransitions : [ createST ( Field ( 1 ) , Field ( 0 ) , Field ( 2 ) ) ] ,
72
+ applied : Bool ( applied ) ,
73
+ witnessRoot : Bool ( witnessRoot ) ,
74
+ } ,
75
+ ] ) ;
76
+
77
+ const tree = new RollupMerkleTree ( new InMemoryMerkleTreeStorage ( ) ) ;
78
+ const witness = tree . getWitness ( 1n ) ;
79
+
80
+ const result = await prover . proveBatch (
81
+ {
82
+ root : tree . getRoot ( ) ,
83
+ rootAccumulator : Field ( 0 ) ,
84
+ batchesHash : Field ( 0 ) ,
85
+ currentBatchStateHash : Field ( 0 ) ,
86
+ } ,
87
+ batch [ 0 ] ,
88
+ {
89
+ witnesses : padArray ( [ witness ] , 4 , ( ) =>
90
+ RollupMerkleTreeWitness . dummy ( )
91
+ ) ,
92
+ } ,
93
+ new AppliedStateTransitionBatchState ( {
94
+ root : tree . getRoot ( ) ,
95
+ batchHash : Field ( 0 ) ,
96
+ } )
97
+ ) ;
98
+
99
+ expect ( result . currentBatchStateHash . toString ( ) ) . toStrictEqual ( "0" ) ;
100
+ }
101
+ ) ;
102
+ } ) ;
103
+
104
+ describe ( "dummies" , ( ) => {
105
+ it ( "should fail if dummy is type close" , async ( ) => {
106
+ expect . assertions ( 1 ) ;
107
+
54
108
const batch = StateTransitionProvableBatch . fromBatches ( [
55
109
{
56
- stateTransitions : [ createST ( Field ( 1 ) , Field ( 0 ) , Field ( 2 ) ) ] ,
57
- applied : Bool ( applied ) ,
58
- witnessRoot : Bool ( witnessRoot ) ,
110
+ stateTransitions : [ ProvableStateTransition . dummy ( ) ] ,
111
+ applied : Bool ( true ) ,
112
+ witnessRoot : Bool ( true ) ,
59
113
} ,
60
114
] ) ;
61
115
62
- const tree = new RollupMerkleTree ( new InMemoryMerkleTreeStorage ( ) ) ;
116
+ const prove = async ( ) =>
117
+ await prover . proveBatch (
118
+ {
119
+ root : Field ( RollupMerkleTree . EMPTY_ROOT ) ,
120
+ rootAccumulator : Field ( 0 ) ,
121
+ batchesHash : Field ( 0 ) ,
122
+ currentBatchStateHash : Field ( 0 ) ,
123
+ } ,
124
+ batch [ 0 ] ,
125
+ {
126
+ witnesses : padArray ( [ ] , 4 , RollupMerkleTreeWitness . dummy ) ,
127
+ } ,
128
+ new AppliedStateTransitionBatchState ( {
129
+ root : Field ( RollupMerkleTree . EMPTY_ROOT ) ,
130
+ batchHash : Field ( 0 ) ,
131
+ } )
132
+ ) ;
133
+
134
+ await expect ( prove ) . rejects . toThrow (
135
+ / D u m m i e s h a v e t o b e o f t y p e ' n o t h i n g ' .* /
136
+ ) ;
137
+ } ) ;
63
138
64
- const witness = tree . getWitness ( 1n ) ;
139
+ it ( "should fail if dummy is in the middle" , async ( ) => {
140
+ expect . assertions ( 1 ) ;
65
141
66
- const result = await prover . proveBatch (
67
- {
68
- root : tree . getRoot ( ) ,
69
- rootAccumulator : Field ( 0 ) ,
70
- batchesHash : Field ( 0 ) ,
71
- currentBatchStateHash : Field ( 0 ) ,
72
- } ,
73
- batch [ 0 ] ,
142
+ const batch = StateTransitionProvableBatch . fromBatches ( [
74
143
{
75
- witnesses : padArray ( [ witness ] , 4 , ( ) =>
76
- RollupMerkleTreeWitness . dummy ( )
77
- ) ,
144
+ stateTransitions : [
145
+ createST ( Field ( 1 ) , Field ( 0 ) , Field ( 2 ) ) ,
146
+ ProvableStateTransition . dummy ( ) ,
147
+ createST ( Field ( 2 ) , Field ( 0 ) , Field ( 3 ) ) ,
148
+ ] ,
149
+ applied : Bool ( true ) ,
150
+ witnessRoot : Bool ( true ) ,
78
151
} ,
79
- new AppliedStateTransitionBatchState ( {
80
- root : tree . getRoot ( ) ,
81
- batchHash : Field ( 0 ) ,
82
- } )
83
- ) ;
84
-
85
- tree . setLeaf ( 1n , Field ( 2 ) ) ;
152
+ ] ) ;
86
153
87
- // expect(result.root.toString()).toStrictEqual(tree.getRoot().toString());
88
- expect ( result . currentBatchStateHash . toString ( ) ) . toStrictEqual ( "0" ) ;
89
- }
90
- ) ;
154
+ const tree = new RollupMerkleTree ( new InMemoryMerkleTreeStorage ( ) ) ;
91
155
92
- it ( "should fail if dummy is type close" , async ( ) => {
93
- expect . assertions ( 1 ) ;
156
+ const inputRoot = tree . getRoot ( ) ;
94
157
95
- const batch = StateTransitionProvableBatch . fromBatches ( [
96
- {
97
- stateTransitions : [ ProvableStateTransition . dummy ( ) ] ,
98
- applied : Bool ( true ) ,
99
- witnessRoot : Bool ( true ) ,
100
- } ,
101
- ] ) ;
158
+ const witness = tree . getWitness ( 1n ) ;
159
+ tree . setLeaf ( 1n , Field ( 2 ) ) ;
160
+ const witness2 = tree . getWitness ( 2n ) ;
161
+
162
+ const prove = async ( ) =>
163
+ await prover . proveBatch (
164
+ {
165
+ root : inputRoot ,
166
+ rootAccumulator : Field ( 0 ) ,
167
+ batchesHash : Field ( 0 ) ,
168
+ currentBatchStateHash : Field ( 0 ) ,
169
+ } ,
170
+ batch [ 0 ] ,
171
+ {
172
+ witnesses : [
173
+ witness ,
174
+ RollupMerkleTreeWitness . dummy ( ) ,
175
+ witness2 ,
176
+ RollupMerkleTreeWitness . dummy ( ) ,
177
+ ] ,
178
+ } ,
179
+ new AppliedStateTransitionBatchState ( {
180
+ root : inputRoot ,
181
+ batchHash : Field ( 0 ) ,
182
+ } )
183
+ ) ;
184
+
185
+ await expect ( prove ) . rejects . toThrow (
186
+ / D u m m i e s c a n o n l y b e p l a c e d o n c l o s e d b a t c h L i s t s .* /
187
+ ) ;
188
+ } ) ;
189
+ } ) ;
102
190
103
- const prove = async ( ) =>
104
- await prover . proveBatch (
191
+ describe ( "batch progression" , ( ) => {
192
+ it ( "should throw away non-applied batches" , async ( ) => {
193
+ const batch = StateTransitionProvableBatch . fromBatches ( [
105
194
{
106
- root : Field ( RollupMerkleTree . EMPTY_ROOT ) ,
107
- rootAccumulator : Field ( 0 ) ,
108
- batchesHash : Field ( 0 ) ,
109
- currentBatchStateHash : Field ( 0 ) ,
195
+ stateTransitions : [
196
+ createST ( Field ( 1 ) , Field ( 0 ) , Field ( 2 ) ) ,
197
+ createST ( Field ( 2 ) , Field ( 0 ) , Field ( 3 ) ) ,
198
+ ] ,
199
+ applied : Bool ( true ) ,
200
+ witnessRoot : Bool ( true ) ,
110
201
} ,
111
- batch [ 0 ] ,
112
202
{
113
- witnesses : padArray ( [ ] , 4 , RollupMerkleTreeWitness . dummy ) ,
203
+ stateTransitions : [
204
+ createST ( Field ( 2 ) , Field ( 3 ) , Field ( 4 ) ) ,
205
+ createST ( Field ( 2 ) , Field ( 4 ) , Field ( 5 ) ) ,
206
+ ] ,
207
+ applied : Bool ( false ) ,
208
+ witnessRoot : Bool ( true ) ,
114
209
} ,
115
- new AppliedStateTransitionBatchState ( {
116
- root : Field ( RollupMerkleTree . EMPTY_ROOT ) ,
117
- batchHash : Field ( 0 ) ,
118
- } )
119
- ) ;
120
-
121
- await expect ( prove ) . rejects . toThrow (
122
- / D u m m i e s h a v e t o b e o f t y p e ' n o t h i n g ' .* /
123
- ) ;
124
- } ) ;
125
-
126
- it ( "should fail if dummy is in the middle" , async ( ) => {
127
- expect . assertions ( 1 ) ;
128
-
129
- const batch = StateTransitionProvableBatch . fromBatches ( [
130
- {
131
- stateTransitions : [
132
- createST ( Field ( 1 ) , Field ( 0 ) , Field ( 2 ) ) ,
133
- ProvableStateTransition . dummy ( ) ,
134
- createST ( Field ( 2 ) , Field ( 0 ) , Field ( 3 ) ) ,
135
- ] ,
136
- applied : Bool ( true ) ,
137
- witnessRoot : Bool ( true ) ,
138
- } ,
139
- ] ) ;
140
-
141
- const tree = new RollupMerkleTree ( new InMemoryMerkleTreeStorage ( ) ) ;
210
+ ] ) ;
142
211
143
- const inputRoot = tree . getRoot ( ) ;
212
+ const tree = new RollupMerkleTree ( new InMemoryMerkleTreeStorage ( ) ) ;
144
213
145
- const witness = tree . getWitness ( 1n ) ;
146
- tree . setLeaf ( 1n , Field ( 2 ) ) ;
147
- const witness2 = tree . getWitness ( 2n ) ;
214
+ const witness1 = tree . getWitness ( 1n ) ;
215
+ tree . setLeaf ( 1n , Field ( 2 ) ) ;
216
+ const witness2 = tree . getWitness ( 2n ) ;
217
+ tree . setLeaf ( 2n , Field ( 3 ) ) ;
148
218
149
- const prove = async ( ) =>
150
- await prover . proveBatch (
219
+ const result = await prover . proveBatch (
151
220
{
152
- root : inputRoot ,
221
+ root : Field ( RollupMerkleTree . EMPTY_ROOT ) ,
153
222
rootAccumulator : Field ( 0 ) ,
154
223
batchesHash : Field ( 0 ) ,
155
224
currentBatchStateHash : Field ( 0 ) ,
156
225
} ,
157
226
batch [ 0 ] ,
158
227
{
159
- witnesses : [
160
- witness ,
161
- RollupMerkleTreeWitness . dummy ( ) ,
162
- witness2 ,
163
- RollupMerkleTreeWitness . dummy ( ) ,
164
- ] ,
228
+ witnesses : [ witness1 , witness2 , witness2 , witness2 ] ,
165
229
} ,
166
230
new AppliedStateTransitionBatchState ( {
167
- root : inputRoot ,
231
+ root : Field ( RollupMerkleTree . EMPTY_ROOT ) ,
168
232
batchHash : Field ( 0 ) ,
169
233
} )
170
234
) ;
171
235
172
- await expect ( prove ) . rejects . toThrow (
173
- / D u m m i e s c a n o n l y b e p l a c e d o n c l o s e d b a t c h L i s t s .* /
174
- ) ;
175
- } ) ;
176
-
177
- describe ( "batch progression" , ( ) => {
178
- it ( "should apply" , ( ) => { } ) ; // TODO
236
+ expect ( result . root . toString ( ) ) . toStrictEqual ( tree . getRoot ( ) . toString ( ) ) ;
237
+ expect ( result . currentBatchStateHash . toString ( ) ) . toStrictEqual ( "0" ) ;
238
+ } ) ;
179
239
} ) ;
180
240
} ) ;
0 commit comments