Skip to content

Commit

Permalink
helping with witness generation when moving from RPC to sequencer (#265)
Browse files Browse the repository at this point in the history
* helping with witness generation when moving from RPC to sequencer

* fixup test for verifier
  • Loading branch information
hexoscott authored Apr 5, 2024
1 parent b3e9160 commit 99deebe
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
12 changes: 10 additions & 2 deletions zk/legacy_executor_verifier/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (e *Executor) Close() {
}
}

func (e *Executor) Verify(p *Payload, request *VerifierRequest) (bool, error) {
func (e *Executor) Verify(p *Payload, request *VerifierRequest, oldStateRoot common.Hash) (bool, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

Expand Down Expand Up @@ -122,7 +122,15 @@ func (e *Executor) Verify(p *Payload, request *VerifierRequest) (bool, error) {
counters += fmt.Sprintf("[P: %v]", resp.CntPoseidonHashes)
counters += fmt.Sprintf("[S: %v]", resp.CntSteps)
counters += fmt.Sprintf("[D: %v]", resp.CntPoseidonPaddings)
log.Info("executor result", "batch", request.BatchNumber, "counters", counters, "root", common.BytesToHash(resp.NewStateRoot), "our-root", request.StateRoot)

log.Info("executor result",
"batch", request.BatchNumber,
"counters", counters,
"exec-root", common.BytesToHash(resp.NewStateRoot),
"our-root", request.StateRoot,
"exec-old-root", common.BytesToHash(resp.OldStateRoot),
"our-old-root", oldStateRoot)

log.Debug("Received response from executor", "grpcUrl", e.grpcUrl, "response", resp)

return responseCheck(resp, request.StateRoot)
Expand Down
2 changes: 1 addition & 1 deletion zk/legacy_executor_verifier/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestExecutor_Verify(t *testing.T) {
ContextId: "cdk-erigon-test",
}

_, err := executor.Verify(payload, &VerifierRequest{StateRoot: *tt.expectedStateRoot})
_, err := executor.Verify(payload, &VerifierRequest{StateRoot: *tt.expectedStateRoot}, common.Hash{})
if (err != nil) != tt.wantErr {
t.Errorf("Executor.Verify() error = %v, wantErr %v", err, tt.wantErr)
}
Expand Down
6 changes: 4 additions & 2 deletions zk/legacy_executor_verifier/legacy_executor_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type VerifierResponse struct {
}

type ILegacyExecutor interface {
Verify(*Payload, *VerifierRequest) (bool, error)
Verify(*Payload, *VerifierRequest, common.Hash) (bool, error)
}

type WitnessGenerator interface {
Expand Down Expand Up @@ -211,7 +211,9 @@ func (v *LegacyExecutorVerifier) handleRequest(ctx context.Context, request *Ver
ContextId: strconv.Itoa(int(request.BatchNumber)),
}

ok, err := execer.Verify(payload, request)
previousBlock, _ := rawdb.ReadBlockByNumber(tx, blocks[0]-1)

ok, err := execer.Verify(payload, request, previousBlock.Root())
if err != nil {
return err
}
Expand Down
6 changes: 6 additions & 0 deletions zk/stages/stage_batches.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,12 @@ func SpawnStageBatches(
return err
}

// save the latest verified batch number as well just in case this node is upgraded
// to a sequencer in the future
if err := stages.SaveStageProgress(tx, stages.SequenceExecutorVerify, highestSeenBatchNo); err != nil {
return fmt.Errorf("save stage progress error: %w", err)
}

// stop printing blocks written progress routine
elapsed := time.Since(startSyncTime)
log.Info(fmt.Sprintf("[%s] Finished writing blocks", logPrefix), "blocksWritten", blocksWritten, "elapsed", elapsed)
Expand Down

0 comments on commit 99deebe

Please sign in to comment.