diff --git a/aggregator/aggregator.go b/aggregator/aggregator.go index 96215c3..6f92715 100644 --- a/aggregator/aggregator.go +++ b/aggregator/aggregator.go @@ -1164,7 +1164,7 @@ func (a *Aggregator) tryAggregateProofs(ctx context.Context, prover proverInterf log.Infof("Proof ID for aggregated proof: %v", *proof.ProofID) log = log.WithFields("proofId", *proof.ProofID) - recursiveProof, err := prover.WaitRecursiveProof(ctx, *proof.ProofID) + recursiveProof, _, err := prover.WaitRecursiveProof(ctx, *proof.ProofID) if err != nil { err = fmt.Errorf("failed to get aggregated proof from prover, %w", err) log.Error(FirstToUpper(err.Error())) @@ -1420,7 +1420,7 @@ func (a *Aggregator) tryGenerateBatchProof(ctx context.Context, prover proverInt log = log.WithFields("proofId", *proof.ProofID) - resGetProof, err := prover.WaitRecursiveProof(ctx, *proof.ProofID) + resGetProof, stateRoot, err := prover.WaitRecursiveProof(ctx, *proof.ProofID) if err != nil { err = fmt.Errorf("failed to get proof from prover, %w", err) log.Error(FirstToUpper(err.Error())) @@ -1429,6 +1429,16 @@ func (a *Aggregator) tryGenerateBatchProof(ctx context.Context, prover proverInt log.Info("Batch proof generated") + // Sanity Check: state root from the proof must match the one from the batch + if a.cfg.BatchProofSanityCheckEnabled && (stateRoot != common.Hash{}) && (stateRoot != batchToProve.StateRoot) { + for { + log.Errorf("State root from the proof does not match the expected for batch %d: Proof = [%s] Expected = [%s]", batchToProve.BatchNumber, stateRoot.String(), batchToProve.StateRoot.String()) + time.Sleep(a.cfg.RetryTime.Duration) + } + } else { + log.Infof("State root sanity check for batch %d passed", batchToProve.BatchNumber) + } + proof.Proof = resGetProof // NOTE(pg): the defer func is useless from now on, use a different variable diff --git a/aggregator/config.go b/aggregator/config.go index 3399cae..512b708 100644 --- a/aggregator/config.go +++ b/aggregator/config.go @@ -75,6 +75,9 @@ type Config struct { // IntervalAfterWhichBatchConsolidateAnyway this is interval for the main sequencer, that will check if there is no transactions IntervalAfterWhichBatchConsolidateAnyway types.Duration `mapstructure:"IntervalAfterWhichBatchConsolidateAnyway"` + // BatchProofSanityCheckEnabled is a flag to enable the sanity check of the batch proof + BatchProofSanityCheckEnabled bool `mapstructure:"BatchProofSanityCheckEnabled"` + // FinalProofSanityCheckEnabled is a flag to enable the sanity check of the final proof FinalProofSanityCheckEnabled bool `mapstructure:"FinalProofSanityCheckEnabled"` diff --git a/aggregator/interfaces.go b/aggregator/interfaces.go index 328957e..74415b5 100644 --- a/aggregator/interfaces.go +++ b/aggregator/interfaces.go @@ -22,7 +22,7 @@ type proverInterface interface { BatchProof(input *prover.StatelessInputProver) (*string, error) AggregatedProof(inputProof1, inputProof2 string) (*string, error) FinalProof(inputProof string, aggregatorAddr string) (*string, error) - WaitRecursiveProof(ctx context.Context, proofID string) (string, error) + WaitRecursiveProof(ctx context.Context, proofID string) (string, common.Hash, error) WaitFinalProof(ctx context.Context, proofID string) (*prover.FinalProof, error) } diff --git a/aggregator/prover/prover.go b/aggregator/prover/prover.go index d502561..d57fe9d 100644 --- a/aggregator/prover/prover.go +++ b/aggregator/prover/prover.go @@ -258,16 +258,19 @@ func (p *Prover) CancelProofRequest(proofID string) error { // WaitRecursiveProof waits for a recursive proof to be generated by the prover // and returns it. -func (p *Prover) WaitRecursiveProof(ctx context.Context, proofID string) (string, error) { +func (p *Prover) WaitRecursiveProof(ctx context.Context, proofID string) (string, common.Hash, error) { res, err := p.waitProof(ctx, proofID) if err != nil { - return "", err + return "", common.Hash{}, err } - resProof := res.Proof.(*GetProofResponse_RecursiveProof) - log.Infof("Received recursive proof: %s", resProof.RecursiveProof) + sr, err := GetStateRootFromProof(res.Proof.(*GetProofResponse_RecursiveProof).RecursiveProof) + if err != nil { + log.Info("Recursive proof does not contain state root. Possibly mock prover is in use.") + } - return resProof.RecursiveProof, nil + resProof := res.Proof.(*GetProofResponse_RecursiveProof) + return resProof.RecursiveProof, sr, nil } // WaitFinalProof waits for the final proof to be generated by the prover and diff --git a/config/default.go b/config/default.go index 3fbc10a..3d47616 100644 --- a/config/default.go +++ b/config/default.go @@ -13,6 +13,7 @@ ProofStatePollingInterval = "5s" SenderAddress = "" CleanupLockedProofsInterval = "2m" GeneratingProofCleanupThreshold = "10m" +BatchProofSanityCheckEnabled = true FinalProofSanityCheckEnabled = true ForkId = 9 GasOffset = 0