Skip to content

Commit

Permalink
feat(taiko-client): submit batch proofs
Browse files Browse the repository at this point in the history
  • Loading branch information
YoGhurt111 committed Sep 23, 2024
1 parent 1b4e58c commit 92b8e7b
Show file tree
Hide file tree
Showing 23 changed files with 764 additions and 22 deletions.
1 change: 0 additions & 1 deletion packages/protocol/contracts/layer1/based/LibUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ library LibUtils {
error L1_INVALID_GENESIS_HASH();
error L1_TRANSITION_NOT_FOUND();
error L1_UNEXPECTED_TRANSITION_ID();
error L1_INVALID_PARAMS();

/// @notice Initializes the Taiko protocol state.
/// @param _state The state to initialize.
Expand Down
2 changes: 1 addition & 1 deletion packages/taiko-client/bindings/.githead
Original file line number Diff line number Diff line change
@@ -1 +1 @@
adc47f408282c25c7a50c26e31130fc495734dcc
1b4e58c8b457e69fafcb203de84f23d494804685
32 changes: 32 additions & 0 deletions packages/taiko-client/bindings/encoding/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ var (
{Name: "TaikoData.Transition", Type: transitionComponentsType},
{Name: "TaikoData.TierProof", Type: tierProofComponentsType},
}
proveBlocksInputArgs = abi.Arguments{
{Name: "TaikoData.BlockMetadata", Type: blockMetadataComponentsType},
{Name: "TaikoData.Transition", Type: transitionComponentsType},
}
)

// Contract ABIs.
Expand Down Expand Up @@ -423,6 +427,34 @@ func EncodeProveBlockInput(
return b, nil
}

// EncodeProveBlocksInput performs the solidity `abi.encode` for the given TaikoL1.proveBlocks input.
func EncodeProveBlocksInput(
metas []metadata.TaikoBlockMetaData,
transitions []bindings.TaikoDataTransition,
) ([][]byte, error) {
var (
b [][]byte
err error
)
if len(metas) != len(transitions) {
return nil, fmt.Errorf("both arrays of TaikoBlockMetaData and TaikoDataTransition must be equal in length , %w", err)
}

for i := range metas {
input, err := proveBlocksInputArgs.Pack(
metas[i].(*metadata.TaikoDataBlockMetadataOntake).InnerMetadata(),
transitions[i],
)
if err != nil {
return nil, fmt.Errorf("failed to abi.encode TaikoL1.proveBlocks input item after ontake fork, %w", err)
}

b = append(b, input)
}

return b, nil
}

// UnpackTxListBytes unpacks the input data of a TaikoL1.proposeBlock transaction, and returns the txList bytes.
func UnpackTxListBytes(txData []byte) ([]byte, error) {
method, err := TaikoL1ABI.MethodById(txData)
Expand Down
2 changes: 1 addition & 1 deletion packages/taiko-client/bindings/gen_lib_utils.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion packages/taiko-client/bindings/gen_prover_set.go

Large diffs are not rendered by default.

64 changes: 63 additions & 1 deletion packages/taiko-client/bindings/gen_taiko_l1.go

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions packages/taiko-client/cmd/flags/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,23 @@ var (
Category: proverCategory,
EnvVars: []string{"PROVER_BLOCK_CONFIRMATIONS"},
}
// Batch proof related flag
BatchSize = &cli.Uint64Flag{
Name: "prover.batchSize",
Usage: "The size of batch proof, when it arrives, submit a batch of proof immediately, " +
"this flag only works post Ontake fork",
Value: 1,
Category: proverCategory,
EnvVars: []string{"PROVER_BATCH_SIZE"},
}
ProveInterval = &cli.DurationFlag{
Name: "prover.interval",
Usage: "Time interval to prove blocks when the number of pending proof don not exceed prover.batchSize, " +
"this flag only works post Ontake fork",
Category: proposerCategory,
Value: 12 * time.Second,
EnvVars: []string{"PROVE_INTERVAL"},
}
)

// ProverFlags All prover flags.
Expand Down Expand Up @@ -227,4 +244,6 @@ var ProverFlags = MergeFlags(CommonFlags, []cli.Flag{
BlockConfirmations,
RaikoRequestTimeout,
RaikoZKVMHostEndpoint,
BatchSize,
ProveInterval,
}, TxmgrFlags)
6 changes: 6 additions & 0 deletions packages/taiko-client/internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ var (
ProverSubmissionErrorCounter = factory.NewCounter(prometheus.CounterOpts{
Name: "prover_proof_submission_error",
})
ProverAggregationSubmissionErrorCounter = factory.NewCounter(prometheus.CounterOpts{
Name: "prover_proof_aggregation_submission_error",
})
ProverSgxProofGeneratedCounter = factory.NewCounter(prometheus.CounterOpts{
Name: "prover_proof_sgx_generated",
})
ProverSgxProofAggregationGeneratedCounter = factory.NewCounter(prometheus.CounterOpts{
Name: "prover_proof_sgx_aggregation_generated",
})
ProverR0ProofGeneratedCounter = factory.NewCounter(prometheus.CounterOpts{
Name: "prover_proof_r0_generated",
})
Expand Down
4 changes: 4 additions & 0 deletions packages/taiko-client/prover/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type Config struct {
BlockConfirmations uint64
TxmgrConfigs *txmgr.CLIConfig
PrivateTxmgrConfigs *txmgr.CLIConfig
ProofBufferSize uint64
ProveInterval time.Duration
}

// NewConfigFromCliContext creates a new config instance from command line flags.
Expand Down Expand Up @@ -183,5 +185,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
l1ProverPrivKey,
c,
),
ProofBufferSize: c.Uint64(flags.BatchSize.Name),
ProveInterval: c.Duration(flags.ProveInterval.Name),
}, nil
}
15 changes: 12 additions & 3 deletions packages/taiko-client/prover/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ func (p *Prover) initProofSubmitters(
) error {
for _, tier := range p.sharedState.GetTiers() {
var (
producer proofProducer.ProofProducer
submitter proofSubmitter.Submitter
err error
producer proofProducer.ProofProducer
submitter proofSubmitter.Submitter
err error
bufferSize = p.cfg.ProofBufferSize
proveInterval = p.cfg.ProveInterval
)
switch tier.ID {
case encoding.TierOptimisticID:
Expand Down Expand Up @@ -131,8 +133,12 @@ func (p *Prover) initProofSubmitters(
}
case encoding.TierGuardianMinorityID:
producer = proofProducer.NewGuardianProofProducer(encoding.TierGuardianMinorityID, p.cfg.EnableLivenessBondProof)
bufferSize = 0
proveInterval = 0
case encoding.TierGuardianMajorityID:
producer = proofProducer.NewGuardianProofProducer(encoding.TierGuardianMajorityID, p.cfg.EnableLivenessBondProof)
bufferSize = 0
proveInterval = 0
default:
return fmt.Errorf("unsupported tier: %d", tier.ID)
}
Expand All @@ -141,6 +147,7 @@ func (p *Prover) initProofSubmitters(
p.rpc,
producer,
p.proofGenerationCh,
p.batchProofGenerationCh,
p.cfg.ProverSetAddress,
p.cfg.TaikoL2Address,
p.cfg.Graffiti,
Expand All @@ -151,6 +158,8 @@ func (p *Prover) initProofSubmitters(
tiers,
p.IsGuardianProver(),
p.cfg.GuardianProofSubmissionDelay,
bufferSize,
proveInterval,
); err != nil {
return err
}
Expand Down
11 changes: 11 additions & 0 deletions packages/taiko-client/prover/proof_producer/dummy_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,14 @@ func (o *DummyProofProducer) RequestProof(
Tier: tier,
}, nil
}

func (o *DummyProofProducer) RequestBatchProofs(
proofs []*ProofWithHeader,
tier uint16,
) (*BatchProofs, error) {
return &BatchProofs{
Proofs: proofs,
BatchProof: bytes.Repeat([]byte{0xbb}, 100),
Tier: tier,
}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ func (g *GuardianProofProducer) RequestCancel(
return nil
}

func (g *GuardianProofProducer) Aggregate(
_ context.Context,
_ []*ProofWithHeader,
_ time.Time,
) (*BatchProofs, error) {
return nil, nil
}

// Tier implements the ProofProducer interface.
func (g *GuardianProofProducer) Tier() uint16 {
return g.tier
Expand Down
15 changes: 15 additions & 0 deletions packages/taiko-client/prover/proof_producer/optimistic_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package producer

import (
"context"
"errors"
"math/big"
"time"

Expand Down Expand Up @@ -34,6 +35,20 @@ func (o *OptimisticProofProducer) RequestProof(

return o.DummyProofProducer.RequestProof(opts, blockID, meta, header, o.Tier(), requestAt)
}
func (o *OptimisticProofProducer) Aggregate(
_ context.Context,
items []*ProofWithHeader,
_ time.Time,
) (*BatchProofs, error) {
log.Info(
"Aggregate batch optimistic proof",
"proofs", items,
)
if len(items) == 0 {
return nil, errors.New("invalid items length")
}
return o.DummyProofProducer.RequestBatchProofs(items, o.Tier())
}

func (o *OptimisticProofProducer) RequestCancel(
_ context.Context,
Expand Down
11 changes: 11 additions & 0 deletions packages/taiko-client/prover/proof_producer/proof_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ type ProofWithHeader struct {
Tier uint16
}

type BatchProofs struct {
Proofs []*ProofWithHeader
BatchProof []byte
Tier uint16
}

type ProofProducer interface {
RequestProof(
ctx context.Context,
Expand All @@ -66,6 +72,11 @@ type ProofProducer interface {
header *types.Header,
requestAt time.Time,
) (*ProofWithHeader, error)
Aggregate(
ctx context.Context,
items []*ProofWithHeader,
requestAt time.Time,
) (*BatchProofs, error)
RequestCancel(
ctx context.Context,
opts *ProofRequestOptions,
Expand Down
Loading

0 comments on commit 92b8e7b

Please sign in to comment.