diff --git a/aggregator/aggregator.go b/aggregator/aggregator.go index 695f6a8..f3598a5 100644 --- a/aggregator/aggregator.go +++ b/aggregator/aggregator.go @@ -1178,7 +1178,7 @@ func (a *Aggregator) getVerifiedBatchAccInputHash(ctx context.Context, batchNumb return &accInputHash, nil } -func (a *Aggregator) getAndLockBatchToProve(ctx context.Context, prover proverInterface) (*state.Batch, *state.Proof, error) { +func (a *Aggregator) getAndLockBatchToProve(ctx context.Context, prover proverInterface) (*state.Batch, []byte, *state.Proof, error) { proverID := prover.ID() proverName := prover.Name() @@ -1194,7 +1194,7 @@ func (a *Aggregator) getAndLockBatchToProve(ctx context.Context, prover proverIn // Get last virtual batch number from L1 lastVerifiedBatchNumber, err := a.etherman.GetLatestVerifiedBatchNum() if err != nil { - return nil, nil, err + return nil, nil, nil, err } proofExists := true @@ -1206,20 +1206,20 @@ func (a *Aggregator) getAndLockBatchToProve(ctx context.Context, prover proverIn proofExists, err = a.state.CheckProofExistsForBatch(ctx, batchNumberToVerify, nil) if err != nil { log.Infof("Error checking proof exists for batch %d", batchNumberToVerify) - return nil, nil, err + return nil, nil, nil, err } } // Check if the batch has been sequenced sequence, err := a.l1Syncr.GetSequenceByBatchNumber(ctx, batchNumberToVerify) if err != nil && !errors.Is(err, entities.ErrNotFound) { - return nil, nil, err + return nil, nil, nil, err } // Not found, so it it not possible to verify the batch yet if sequence == nil || errors.Is(err, entities.ErrNotFound) { log.Infof("No sequence found for batch %d", batchNumberToVerify) - return nil, nil, state.ErrNotFound + return nil, nil, nil, state.ErrNotFound } stateSequence := state.Sequence{ @@ -1230,12 +1230,12 @@ func (a *Aggregator) getAndLockBatchToProve(ctx context.Context, prover proverIn err = a.state.AddSequence(ctx, stateSequence, nil) if err != nil { log.Infof("Error storing sequence for batch %d", batchNumberToVerify) - return nil, nil, err + return nil, nil, nil, err } - batch, _, _, err := a.state.GetBatch(ctx, batchNumberToVerify, nil) + batch, _, witness, err := a.state.GetBatch(ctx, batchNumberToVerify, nil) if err != nil { - return batch, nil, err + return batch, witness, nil, err } // All the data required to generate a proof is ready @@ -1248,12 +1248,12 @@ func (a *Aggregator) getAndLockBatchToProve(ctx context.Context, prover proverIn isProfitable, err := a.profitabilityChecker.IsProfitable(ctx, big.NewInt(0)) if err != nil { log.Errorf("Failed to check aggregator profitability, err: %v", err) - return nil, nil, err + return nil, nil, nil, err } if !isProfitable { log.Infof("Batch is not profitable, pol collateral %d", big.NewInt(0)) - return nil, nil, err + return nil, nil, nil, err } now := time.Now().Round(time.Microsecond) @@ -1269,10 +1269,10 @@ func (a *Aggregator) getAndLockBatchToProve(ctx context.Context, prover proverIn err = a.state.AddGeneratedProof(ctx, proof, nil) if err != nil { log.Errorf("Failed to add batch proof, err: %v", err) - return nil, nil, err + return nil, nil, nil, err } - return batch, proof, nil + return batch, witness, proof, nil } func (a *Aggregator) tryGenerateBatchProof(ctx context.Context, prover proverInterface) (bool, error) { @@ -1283,7 +1283,7 @@ func (a *Aggregator) tryGenerateBatchProof(ctx context.Context, prover proverInt ) log.Debug("tryGenerateBatchProof start") - batchToProve, proof, err0 := a.getAndLockBatchToProve(ctx, prover) + batchToProve, witness, proof, err0 := a.getAndLockBatchToProve(ctx, prover) if errors.Is(err0, state.ErrNotFound) { // nothing to proof, swallow the error log.Debug("Nothing to generate proof") @@ -1312,7 +1312,7 @@ func (a *Aggregator) tryGenerateBatchProof(ctx context.Context, prover proverInt }() log.Infof("Sending zki + batch to the prover, batchNumber [%d]", batchToProve.BatchNumber) - inputProver, err := a.buildInputProver(ctx, batchToProve) + inputProver, err := a.buildInputProver(ctx, batchToProve, witness) if err != nil { err = fmt.Errorf("failed to build input prover, %w", err) log.Error(FirstToUpper(err.Error())) @@ -1404,7 +1404,7 @@ func (a *Aggregator) resetVerifyProofTime() { a.timeSendFinalProof = time.Now().Add(a.cfg.VerifyProofInterval.Duration) } -func (a *Aggregator) buildInputProver(ctx context.Context, batchToVerify *state.Batch) (*prover.StatelessInputProver, error) { +func (a *Aggregator) buildInputProver(ctx context.Context, batchToVerify *state.Batch, witness []byte) (*prover.StatelessInputProver, error) { isForcedBatch := false batchRawData := &state.BatchRawV2{} var err error @@ -1498,8 +1498,8 @@ func (a *Aggregator) buildInputProver(ctx context.Context, batchToVerify *state. }*/ } - // Get Old Acc Input Hash and witness - oldBatch, _, witness, err := a.state.GetBatch(ctx, batchToVerify.BatchNumber-1, nil) + // Get Old Acc Input Hash + oldBatch, _, _, err := a.state.GetBatch(ctx, batchToVerify.BatchNumber-1, nil) if err != nil { return nil, err }