@@ -37,6 +37,7 @@ import {
37
37
EMPTY_LEVEL_1_TREE ,
38
38
ValueStorage ,
39
39
RequestIdStorage ,
40
+ TotalFundStorage ,
40
41
} from './FundingStorage.js' ;
41
42
42
43
const DefaultLevel1Root = EMPTY_LEVEL_1_TREE ( ) . getRoot ( ) ;
@@ -53,6 +54,7 @@ export class RequestSent extends Struct({
53
54
requestId : Field ,
54
55
sumR : DKG_Contracts . Request . RequestVector ,
55
56
sumM : DKG_Contracts . Request . RequestVector ,
57
+ totalFundAmount : Field ,
56
58
} ) {
57
59
static fromFields ( action : Field [ ] ) : RequestSent {
58
60
return super . fromFields ( action ) as RequestSent ;
@@ -77,6 +79,7 @@ export class FundingAction extends Struct({
77
79
campaignId : Field ,
78
80
R : DKG_Contracts . Request . RequestVector ,
79
81
M : DKG_Contracts . Request . RequestVector ,
82
+ fundAmount : Field ,
80
83
} ) {
81
84
hash ( ) : Field {
82
85
return Poseidon . hash ( FundingAction . toFields ( this ) ) ;
@@ -171,9 +174,8 @@ export class RollupActionsOutput extends Struct({
171
174
campaignId : Field ,
172
175
sum_R : DKG_Contracts . Request . RequestVector ,
173
176
sum_M : DKG_Contracts . Request . RequestVector ,
174
- // TODO: make that we can increase number of investor
177
+ totalFundAmount : Field ,
175
178
initialStatusRoot : Field ,
176
- finalStatusRoot : Field ,
177
179
} ) {
178
180
hash ( ) : Field {
179
181
return Poseidon . hash ( RollupActionsOutput . toFields ( this ) ) ;
@@ -211,12 +213,7 @@ export const CreateRollupProof = ZkProgram({
211
213
Field ( ActionStatus . REDUCED )
212
214
) ;
213
215
key . assertEquals ( actionState ) ;
214
- root . assertEquals ( preProof . publicOutput . finalStatusRoot ) ;
215
-
216
- // Update satus to ROLL_UPED
217
- let [ newRoot ] = rollupStatusWitness . computeRootAndKey (
218
- Field ( ActionStatus . ROLL_UPED )
219
- ) ;
216
+ root . assertEquals ( preProof . publicOutput . initialStatusRoot ) ;
220
217
221
218
let sum_R = preProof . publicOutput . sum_R ;
222
219
let sum_M = preProof . publicOutput . sum_M ;
@@ -232,12 +229,16 @@ export const CreateRollupProof = ZkProgram({
232
229
) ;
233
230
}
234
231
232
+ let newTotalFund = preProof . publicOutput . totalFundAmount . add (
233
+ action . fundAmount
234
+ ) ;
235
+
235
236
return new RollupActionsOutput ( {
236
237
campaignId : campaignId ,
237
238
sum_R,
238
239
sum_M,
240
+ totalFundAmount : newTotalFund ,
239
241
initialStatusRoot : preProof . publicOutput . initialStatusRoot ,
240
- finalStatusRoot : newRoot ,
241
242
} ) ;
242
243
} ,
243
244
} ,
@@ -258,8 +259,8 @@ export const CreateRollupProof = ZkProgram({
258
259
sum_M : DKG_Contracts . Request . RequestVector . empty (
259
260
maxInvestorSize
260
261
) ,
262
+ totalFundAmount : Field ( 0 ) ,
261
263
initialStatusRoot,
262
- finalStatusRoot : initialStatusRoot ,
263
264
} ) ;
264
265
} ,
265
266
} ,
@@ -273,6 +274,7 @@ export class FundingContract extends SmartContract {
273
274
@state ( Field ) actionStatus = State < Field > ( ) ;
274
275
@state ( Field ) R_root = State < Field > ( ) ; // campaignId -> sum R
275
276
@state ( Field ) M_root = State < Field > ( ) ; // campaignId -> sum M
277
+ @state ( Field ) totalFundAmount_root = State < Field > ( ) ; // campaignId -> total fubnd amount
276
278
@state ( Field ) requestId_root = State < Field > ( ) ; // campaignId -> requestId
277
279
@state ( Field ) zkApps = State < Field > ( ) ;
278
280
@@ -288,6 +290,7 @@ export class FundingContract extends SmartContract {
288
290
this . actionStatus . set ( EMPTY_REDUCE_MT ( ) . getRoot ( ) ) ;
289
291
this . R_root . set ( DefaultLevel1Root ) ;
290
292
this . M_root . set ( DefaultLevel1Root ) ;
293
+ this . totalFundAmount_root . set ( DefaultLevel1Root ) ;
291
294
this . requestId_root . set ( DefaultLevel1Root ) ;
292
295
}
293
296
@@ -387,6 +390,7 @@ export class FundingContract extends SmartContract {
387
390
campaignId : fundingInput . campaignId ,
388
391
R,
389
392
M,
393
+ fundAmount : totalMinaInvest ,
390
394
} )
391
395
) ;
392
396
@@ -416,14 +420,16 @@ export class FundingContract extends SmartContract {
416
420
this . emitEvent ( EventEnum . ACTIONS_REDUCED , lastActionState ) ;
417
421
}
418
422
419
- // TODO: adding N, T to check REQUEST_MAX_SIZE by interact with Committee contract
420
- // TODO: checking Campaign contract config -> committeeId and keyId
423
+ // TODO: add time condition to check rollup
424
+ // TODO: adding N, T to check REQUEST_MAX_SIZE by interact with Committee contract (???)
425
+ // TODO: checking Campaign contract config -> committeeId and keyId is valid
421
426
@method rollupRequest (
422
427
proof : ProofRollupAction ,
423
428
committeeId : Field ,
424
429
keyId : Field ,
425
430
R_witness : Level1Witness ,
426
431
M_witness : Level1Witness ,
432
+ totalFundAmount_witness : Level1Witness ,
427
433
requestId_witness : Level1Witness ,
428
434
requestZkAppRef : ZkAppRef
429
435
) {
@@ -440,26 +446,34 @@ export class FundingContract extends SmartContract {
440
446
let R_root = this . R_root . getAndRequireEquals ( ) ;
441
447
let M_root = this . M_root . getAndRequireEquals ( ) ;
442
448
let requestId_root = this . requestId_root . getAndRequireEquals ( ) ;
449
+ let totalFundAmount_root =
450
+ this . totalFundAmount_root . getAndRequireEquals ( ) ;
443
451
let actionStatus = this . actionStatus . getAndRequireEquals ( ) ;
444
452
445
453
actionStatus . assertEquals ( proof . publicOutput . initialStatusRoot ) ;
454
+
446
455
let R_key = R_witness . calculateIndex ( ) ;
447
456
let old_R_root = R_witness . calculateRoot ( Field ( 0 ) ) ;
448
457
let M_key = M_witness . calculateIndex ( ) ;
449
458
let old_M_root = M_witness . calculateRoot ( Field ( 0 ) ) ;
450
459
let requestId_key = requestId_witness . calculateIndex ( ) ;
451
460
let old_requestId_root = requestId_witness . calculateRoot ( Field ( 0 ) ) ;
461
+ let totalFundAmount_key = totalFundAmount_witness . calculateIndex ( ) ;
462
+ let old_totalFundAmount_root = totalFundAmount_witness . calculateRoot (
463
+ Field ( 0 )
464
+ ) ;
452
465
453
466
R_key . assertEquals ( proof . publicOutput . campaignId ) ;
454
467
M_key . assertEquals ( proof . publicOutput . campaignId ) ;
455
468
requestId_key . assertEquals ( proof . publicOutput . campaignId ) ;
469
+ totalFundAmount_key . assertEquals ( proof . publicOutput . campaignId ) ;
456
470
457
471
R_root . assertEquals ( old_R_root ) ;
458
472
M_root . assertEquals ( old_M_root ) ;
459
473
requestId_root . assertEquals ( old_requestId_root ) ;
474
+ totalFundAmount_root . assertEquals ( old_totalFundAmount_root ) ;
460
475
461
476
// TODO: check number of investor
462
- // maybe add time in the future
463
477
let new_R_root = R_witness . calculateRoot (
464
478
ValueStorage . calculateLeaf ( proof . publicOutput . sum_R )
465
479
) ;
@@ -469,14 +483,17 @@ export class FundingContract extends SmartContract {
469
483
let new_requestId_root = requestId_witness . calculateRoot (
470
484
RequestIdStorage . calculateLeaf ( requestId )
471
485
) ;
486
+ let new_totalFundAmount_root = totalFundAmount_witness . calculateRoot (
487
+ TotalFundStorage . calculateLeaf ( proof . publicOutput . totalFundAmount )
488
+ ) ;
472
489
473
490
// update on-chain state
474
491
this . R_root . set ( new_R_root ) ;
475
492
this . M_root . set ( new_M_root ) ;
476
493
this . requestId_root . set ( new_requestId_root ) ;
477
- this . actionStatus . set ( proof . publicOutput . finalStatusRoot ) ;
494
+ this . totalFundAmount_root . set ( new_totalFundAmount_root ) ;
478
495
479
- // TODO: request to Request contract
496
+ // Request to Request contract
480
497
// Verify zkApp references
481
498
let zkApps = this . zkApps . getAndRequireEquals ( ) ;
482
499
@@ -506,6 +523,7 @@ export class FundingContract extends SmartContract {
506
523
requestId,
507
524
sumR : proof . publicOutput . sum_R ,
508
525
sumM : proof . publicOutput . sum_M ,
526
+ totalFundAmount : proof . publicOutput . totalFundAmount ,
509
527
} )
510
528
) ;
511
529
}
0 commit comments