Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(taiko-client): enable proof aggregation (batch proofs) #18163

Merged
merged 131 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 128 commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
453d730
feat(protocol): introduce `getTransitions` in TaikoL1
YoGhurt111 Sep 20, 2024
5b802d3
Merge branch 'main' into feature/get-transitions
YoGhurt111 Sep 20, 2024
5dd741d
fix
YoGhurt111 Sep 20, 2024
937eeb6
Merge branch 'feature/get-transitions' into feature/batch-proof
YoGhurt111 Sep 20, 2024
1b4e58c
Merge branch 'main' into feature/batch-proof
YoGhurt111 Sep 23, 2024
92b8e7b
feat(taiko-client): submit batch proofs
YoGhurt111 Sep 23, 2024
45fa2a1
Update packages/protocol/contracts/layer1/based/LibUtils.sol
YoGhurt111 Sep 23, 2024
1f46ea9
Update packages/taiko-client/cmd/flags/prover.go
YoGhurt111 Sep 24, 2024
64b9de1
Update packages/taiko-client/cmd/flags/prover.go
YoGhurt111 Sep 24, 2024
66a3efb
Update packages/taiko-client/prover/proof_producer/sgx_producer.go
YoGhurt111 Sep 24, 2024
d1d2d55
Update packages/taiko-client/prover/proof_submitter/proof_submitter.go
YoGhurt111 Sep 24, 2024
88d7a43
Update packages/taiko-client/cmd/flags/prover.go
YoGhurt111 Sep 24, 2024
b5c5968
Update packages/taiko-client/prover/proof_producer/sgx_producer.go
YoGhurt111 Sep 25, 2024
236e660
Update packages/taiko-client/prover/proof_producer/sgx_producer.go
YoGhurt111 Sep 25, 2024
24add9c
Update packages/taiko-client/prover/proof_producer/sgx_producer.go
YoGhurt111 Sep 25, 2024
dd4e626
Merge branch 'main' into feature/batch-proof
YoGhurt111 Sep 25, 2024
e20e064
changes based on comments
YoGhurt111 Sep 25, 2024
948c55d
Merge branches 'feature/batch-proof' and 'feature/batch-proof' of git…
YoGhurt111 Sep 25, 2024
73fc040
add optional flag for zk batch
YoGhurt111 Sep 26, 2024
54124c8
Merge branch 'main' into feature/batch-proof
YoGhurt111 Sep 26, 2024
f4a9ac8
temp
YoGhurt111 Sep 26, 2024
62ac02b
temp
YoGhurt111 Sep 26, 2024
a1818e4
temp
YoGhurt111 Sep 26, 2024
e29ba96
feat(taiko-client): update contract bingdings
YoGhurt111 Sep 27, 2024
0834514
Merge branch 'main' into feature/batch-proof
YoGhurt111 Sep 27, 2024
d505ebe
changes based on pr-18181
YoGhurt111 Sep 27, 2024
008ac1d
fix
YoGhurt111 Sep 27, 2024
804428e
fix
YoGhurt111 Sep 27, 2024
b25ed1c
fix
YoGhurt111 Sep 28, 2024
1a5014b
add log
YoGhurt111 Sep 28, 2024
a385f99
build image
YoGhurt111 Sep 28, 2024
0f86de8
Revert "build image"
YoGhurt111 Sep 29, 2024
603bc1a
fix
YoGhurt111 Sep 29, 2024
023ff02
fix
YoGhurt111 Sep 29, 2024
9e82059
fix
YoGhurt111 Sep 29, 2024
b0b17c4
fix
YoGhurt111 Sep 29, 2024
1afd4fe
fix
YoGhurt111 Sep 29, 2024
9222d1c
fix
YoGhurt111 Sep 29, 2024
f776a63
fix
YoGhurt111 Sep 29, 2024
e35e7a6
upgrade
YoGhurt111 Sep 29, 2024
f6d0ee2
fix
YoGhurt111 Sep 29, 2024
56db4ce
fix
YoGhurt111 Sep 30, 2024
04250f9
refactor
YoGhurt111 Sep 30, 2024
49c2972
add zk support
YoGhurt111 Sep 30, 2024
fc667be
temp
YoGhurt111 Sep 30, 2024
9c2271c
fix
YoGhurt111 Sep 30, 2024
fd5c6ee
fix
YoGhurt111 Sep 30, 2024
82cff3c
fix
YoGhurt111 Oct 8, 2024
e52775c
fix
YoGhurt111 Oct 8, 2024
51b885c
fix
YoGhurt111 Oct 9, 2024
a2fe08d
fix
YoGhurt111 Oct 9, 2024
2328487
fix
YoGhurt111 Oct 9, 2024
4360b2a
fix
YoGhurt111 Oct 9, 2024
af76a29
fix
YoGhurt111 Oct 9, 2024
2ffe93a
fix
YoGhurt111 Oct 9, 2024
209574e
Merge branch 'main' into feature/batch-proof
YoGhurt111 Oct 10, 2024
b742583
fix
YoGhurt111 Oct 11, 2024
d53c504
debug
YoGhurt111 Oct 11, 2024
87be364
fix
YoGhurt111 Oct 11, 2024
2cc63f0
log optimisation
YoGhurt111 Oct 11, 2024
11190cc
fix
YoGhurt111 Oct 11, 2024
928363e
fix
YoGhurt111 Oct 11, 2024
eb4ea5c
Merge branch 'main' into feature/batch-proof
davidtaikocha Oct 13, 2024
b60ce73
Revert "debug"
YoGhurt111 Oct 16, 2024
6f7736b
Merge branch 'main' into feature/batch-proof
YoGhurt111 Oct 16, 2024
5409ad4
Revert "temp"
YoGhurt111 Oct 16, 2024
7cd5ee2
Merge branch 'feature/batch-proof' of github.com:taikoxyz/taiko-mono …
YoGhurt111 Oct 16, 2024
94d3787
Update DevnetTierProvider.sol
YoGhurt111 Oct 16, 2024
83e9dce
Update DevnetTierProvider.sol
YoGhurt111 Oct 16, 2024
6753450
Update Risc0Verifier.sol
YoGhurt111 Oct 16, 2024
9c0f5a5
Update SgxVerifier.sol
YoGhurt111 Oct 16, 2024
1b3b961
Update SgxVerifier.sol
YoGhurt111 Oct 16, 2024
98e5b6f
Update packages/protocol/contracts/layer2/based/TaikoL2.sol
YoGhurt111 Oct 16, 2024
19cd84c
fix
YoGhurt111 Oct 16, 2024
6e658d7
Update packages/taiko-client/bindings/encoding/input.go
YoGhurt111 Oct 16, 2024
8c9bdca
changes based on comments
YoGhurt111 Oct 16, 2024
6138b8b
feat(taiko-client): improve `BlobTransactionBuilder` to support `Blob…
davidtaikocha Oct 14, 2024
1b7240f
temp
YoGhurt111 Oct 16, 2024
ac19d34
debug
YoGhurt111 Oct 17, 2024
3844048
debug
YoGhurt111 Oct 17, 2024
1e68832
debug
YoGhurt111 Oct 17, 2024
bd6482d
zk
YoGhurt111 Oct 17, 2024
9d3ad02
temp
YoGhurt111 Oct 17, 2024
c9f32fe
Revert "temp"
YoGhurt111 Oct 17, 2024
78cf58d
Revert "debug"
YoGhurt111 Oct 17, 2024
3681c38
Revert "debug"
YoGhurt111 Oct 17, 2024
26b2619
Revert "debug"
YoGhurt111 Oct 17, 2024
1b3123b
Revert "temp"
YoGhurt111 Oct 17, 2024
7e31f03
Revert "feat(taiko-client): improve `BlobTransactionBuilder` to suppo…
YoGhurt111 Oct 17, 2024
348a96d
Merge branch 'main' into feature/batch-proof
davidtaikocha Oct 25, 2024
99000b2
Update packages/taiko-client/prover/init.go
YoGhurt111 Oct 25, 2024
6441d62
Update packages/taiko-client/cmd/flags/prover.go
YoGhurt111 Oct 25, 2024
095392b
Update packages/taiko-client/cmd/flags/prover.go
YoGhurt111 Oct 25, 2024
25ecc2c
fix based on comments
YoGhurt111 Oct 25, 2024
237b501
Merge branch 'main' into feature/batch-proof
davidtaikocha Nov 4, 2024
de53a2a
Merge branch 'main' into feature/batch-proof
YoGhurt111 Nov 4, 2024
45890cd
Merge branch 'main' into feature/batch-proof
YoGhurt111 Nov 5, 2024
80260a3
Merge branch 'main' into feature/batch-proof
YoGhurt111 Nov 6, 2024
dd1bb5d
temp
YoGhurt111 Nov 6, 2024
1e9d376
fix
YoGhurt111 Nov 6, 2024
0eacfdf
Merge branch 'main' into feature/batch-proof
davidtaikocha Nov 8, 2024
8046b9f
Update packages/taiko-client/pkg/rpc/utils.go
YoGhurt111 Nov 8, 2024
f0f0a46
Update packages/taiko-client/prover/proof_submitter/proof_submitter.go
YoGhurt111 Nov 8, 2024
bcd1542
Update packages/taiko-client/prover/proof_submitter/transaction/build…
YoGhurt111 Nov 8, 2024
7c2b509
Update packages/taiko-client/prover/proof_submitter/proof_submitter.go
YoGhurt111 Nov 8, 2024
cf5dfe8
add log
YoGhurt111 Nov 8, 2024
4f47f42
fix based on comments
YoGhurt111 Nov 18, 2024
54ce66c
fix lint
YoGhurt111 Nov 18, 2024
d704e13
Merge branch 'main' into feature/batch-proof
YoGhurt111 Nov 18, 2024
50a71d4
chore: cleanup some code
davidtaikocha Nov 20, 2024
0876fc1
fix metrics
YoGhurt111 Nov 20, 2024
8fe2889
Update packages/taiko-client/prover/proof_submitter/transaction/sende…
YoGhurt111 Nov 20, 2024
d3cb491
Update packages/taiko-client/prover/proof_submitter/transaction/sende…
YoGhurt111 Nov 20, 2024
4ce2d56
Update packages/taiko-client/prover/proof_submitter/transaction/sende…
davidtaikocha Nov 20, 2024
bd68a89
Update packages/taiko-client/prover/proof_submitter/proof_submitter.go
YoGhurt111 Nov 20, 2024
00bda1e
Update packages/taiko-client/prover/proof_submitter/proof_submitter.go
YoGhurt111 Nov 20, 2024
ff2228b
Update proof_submitter.go
YoGhurt111 Nov 20, 2024
b9a719d
Revert "Update proof_submitter.go"
YoGhurt111 Nov 20, 2024
8d99968
Merge branch 'main' into feature/batch-proof
davidtaikocha Nov 25, 2024
90c75a6
batch request
YoGhurt111 Nov 25, 2024
a8a915c
Merge branches 'feature/batch-proof' and 'feature/batch-proof' of git…
YoGhurt111 Nov 25, 2024
b763965
Merge branch 'main' into feature/batch-proof
davidtaikocha Nov 26, 2024
4d65a7a
Merge branch 'main' into feature/batch-proof
davidtaikocha Nov 28, 2024
ccc34f5
add tw0 unit test for proofs agg and fix
YoGhurt111 Nov 29, 2024
e87d57c
Merge branch 'feature/batch-proof' of github.com:taikoxyz/taiko-mono …
YoGhurt111 Nov 29, 2024
350a651
Merge branch 'main' into feature/batch-proof
YoGhurt111 Nov 29, 2024
2fc4f97
fix lint
YoGhurt111 Nov 29, 2024
23aefa7
revert pushing docker image
YoGhurt111 Nov 29, 2024
92b1f11
fix test
YoGhurt111 Dec 5, 2024
09928c4
Merge branch 'main' into feature/batch-proof
YoGhurt111 Dec 5, 2024
2802e6b
fix lint
YoGhurt111 Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 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,13 @@ var (
{Name: "TaikoData.Transition", Type: transitionComponentsType},
{Name: "TaikoData.TierProof", Type: tierProofComponentsType},
}
proveBlocksInputArgs = abi.Arguments{
{Name: "TaikoData.BlockMetadata", Type: blockMetadataV2ComponentsType},
{Name: "TaikoData.Transition", Type: transitionComponentsType},
}
proveBlocksBatchProofArgs = abi.Arguments{
{Name: "TaikoData.TierProof", Type: tierProofComponentsType},
}
)

// Contract ABIs.
Expand Down Expand Up @@ -423,6 +430,43 @@ 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) {
if len(metas) != len(transitions) {
YoGhurt111 marked this conversation as resolved.
Show resolved Hide resolved
return nil, fmt.Errorf("both arrays of TaikoBlockMetaData and TaikoDataTransition must be equal in length")
}
b := make([][]byte, 0, len(metas))
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
}

// EncodeProveBlocksBatchProof performs the solidity `abi.encode` for the given TaikoL1.proveBlocks batchProof.
func EncodeProveBlocksBatchProof(
tierProof *bindings.TaikoDataTierProof,
) ([]byte, error) {
input, err := proveBlocksBatchProofArgs.Pack(
tierProof,
)
if err != nil {
return nil, fmt.Errorf("failed to abi.encode TaikoL1.proveBlocks input item after ontake fork, %w", err)
}
return input, 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
28 changes: 28 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,31 @@ var (
Category: proverCategory,
EnvVars: []string{"PROVER_BLOCK_CONFIRMATIONS"},
}
// Batch proof related flag
SGXBatchSize = &cli.Uint64Flag{
Name: "prover.sgx.batchSize",
Usage: "The default size of batch sgx proofs, when it arrives, submit a batch of proof immediately, " +
"this flag only works post Ontake fork",
Value: 1,
Category: proverCategory,
EnvVars: []string{"PROVER_SGX_BATCH_SIZE"},
}
ZKVMBatchSize = &cli.Uint64Flag{
Name: "prover.zkvm.batchSize",
Usage: "The size of batch ZKVM proof, when it arrives, submit a batch of proof immediately, " +
"this flag only works post Ontake fork",
Value: 1,
Category: proverCategory,
EnvVars: []string{"PROVER_ZKVM_BATCH_SIZE"},
}
ForceProveInterval = &cli.DurationFlag{
Name: "prover.forceBatchProvingInterval",
Usage: "Time interval to prove blocks even the number of pending proof do not exceed prover.batchSize, " +
"this flag only works post Ontake fork",
Category: proverCategory,
Value: 30 * time.Minute,
EnvVars: []string{"PROVER_FORCE_BATCH_PROVING_INTERVAL"},
}
)

// ProverFlags All prover flags.
Expand Down Expand Up @@ -227,4 +252,7 @@ var ProverFlags = MergeFlags(CommonFlags, []cli.Flag{
BlockConfirmations,
RaikoRequestTimeout,
RaikoZKVMHostEndpoint,
SGXBatchSize,
ZKVMBatchSize,
ForceProveInterval,
}, TxmgrFlags)
12 changes: 12 additions & 0 deletions packages/taiko-client/internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,27 @@ 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",
})
ProverR0ProofAggregationGeneratedCounter = factory.NewCounter(prometheus.CounterOpts{
Name: "prover_proof_r0_aggregation_generated",
})
ProverSp1ProofGeneratedCounter = factory.NewCounter(prometheus.CounterOpts{
Name: "prover_proof_sp1_generated",
})
ProverSp1ProofAggregationGeneratedCounter = factory.NewCounter(prometheus.CounterOpts{
Name: "prover_proof_sp1_aggregation_generated",
})
ProverSubmissionRevertedCounter = factory.NewCounter(prometheus.CounterOpts{
Name: "prover_proof_submission_reverted",
})
Expand Down
61 changes: 61 additions & 0 deletions packages/taiko-client/pkg/rpc/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rpc

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

Expand All @@ -14,6 +15,10 @@ import (
"github.com/ethereum/go-ethereum/rpc"
)

var (
ErrInvalidLenOfParams = errors.New("invalid length of parameters")
)

// gethClient is a wrapper for go-ethereum geth client.
type gethClient struct {
*gethclient.Client
Expand Down Expand Up @@ -74,6 +79,34 @@ func (c *EthClient) BlockByHash(ctx context.Context, hash common.Hash) (*types.B
return c.ethClient.BlockByHash(ctxWithTimeout, hash)
}

func (c *EthClient) BatchBlocksByHashes(ctx context.Context, hashes []common.Hash) ([]*types.Block, error) {
if len(hashes) < 1 {
return nil, ErrInvalidLenOfParams
}
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

reqs := make([]rpc.BatchElem, len(hashes))
results := make([]*types.Block, len(hashes))
for i, hash := range hashes {
reqs[i] = rpc.BatchElem{
Method: "eth_getBlockByHash",
Args: []interface{}{hash, true},
Result: &results[i],
}
}
if err := c.BatchCallContext(ctxWithTimeout, reqs); err != nil {
return nil, err
}
for i := range reqs {
if reqs[i].Error != nil {
return nil, reqs[i].Error
}
}

return results, nil
}

// BlockByNumber returns a block from the current canonical chain. If number is nil, the
// latest known block is returned.
//
Expand Down Expand Up @@ -119,6 +152,34 @@ func (c *EthClient) HeaderByNumber(ctx context.Context, number *big.Int) (*types
return c.ethClient.HeaderByNumber(ctxWithTimeout, number)
}

func (c *EthClient) BatchHeadersByNumbers(ctx context.Context, numbers []*big.Int) ([]*types.Header, error) {
if len(numbers) < 1 {
return nil, ErrInvalidLenOfParams
}
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

reqs := make([]rpc.BatchElem, len(numbers))
results := make([]*types.Header, len(numbers))
for i, blockNum := range numbers {
reqs[i] = rpc.BatchElem{
Method: "eth_getBlockByNumber",
Args: []interface{}{blockNum, false},
Result: &results[i],
}
}
if err := c.BatchCallContext(ctxWithTimeout, reqs); err != nil {
return nil, err
}
for i := range reqs {
if reqs[i].Error != nil {
return nil, reqs[i].Error
}
}

return results, nil
}

// TransactionByHash returns the transaction with the given hash.
func (c *EthClient) TransactionByHash(
ctx context.Context,
Expand Down
26 changes: 26 additions & 0 deletions packages/taiko-client/pkg/rpc/ethclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rpc

import (
"context"
"math/big"
"testing"

"github.com/ethereum/go-ethereum"
Expand Down Expand Up @@ -168,3 +169,28 @@ func TestEstimateGas(t *testing.T) {
_, err := client.L1.EstimateGas(context.Background(), ethereum.CallMsg{})
require.Nil(t, err)
}

func TestBatchBlocksByNumbers(t *testing.T) {
client := newTestClientWithTimeout(t)

headers, err := client.L1.BatchHeadersByNumbers(context.Background(), []*big.Int{big.NewInt(0), big.NewInt(1)})
require.Nil(t, err)
require.Len(t, headers, 2)
}

func TestBatchBlocksByHashes(t *testing.T) {
client := newTestClientWithTimeout(t)

headers, err := client.L1.BatchHeadersByNumbers(context.Background(), []*big.Int{big.NewInt(0), big.NewInt(1)})
require.Nil(t, err)
require.Len(t, headers, 2)

hashes := make([]common.Hash, len(headers))
for i, header := range headers {
hashes[i] = header.Hash()
}

blocks, err := client.L1.BatchBlocksByHashes(context.Background(), hashes)
require.Nil(t, err)
require.Len(t, blocks, 2)
}
Loading
Loading