Skip to content

Commit

Permalink
fix getting witness
Browse files Browse the repository at this point in the history
  • Loading branch information
ToniRamirezM committed Jul 14, 2024
1 parent 4078e4e commit be09346
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
Expand All @@ -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{
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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) {
Expand All @@ -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")
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit be09346

Please sign in to comment.