From fcb5f962d60d8c7fe62c5b66fbd98f7be9610fed Mon Sep 17 00:00:00 2001 From: David Date: Mon, 6 May 2024 17:50:36 +0800 Subject: [PATCH 1/5] feat(prover): make guardian provers connecting to their local `raiko` service --- prover/config.go | 5 ----- prover/init.go | 8 +++++++- prover/proof_producer/guardian_producer.go | 11 +++++++++-- prover/proof_producer/guardian_producer_test.go | 4 ++-- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/prover/config.go b/prover/config.go index fc3150a0f..7f78e4128 100644 --- a/prover/config.go +++ b/prover/config.go @@ -118,11 +118,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { } } - // If we are not running a guardian prover, a raiko host endpoint is required. - if !c.IsSet(flags.GuardianProver.Name) && !c.IsSet(flags.RaikoHostEndpoint.Name) { - return nil, errors.New("raiko host not provided") - } - var ( raikoL1Endpoint = c.String(flags.RaikoL1Endpoint.Name) raikoL1BeaconEndpoint = c.String(flags.RaikoL1BeaconEndpoint.Name) diff --git a/prover/init.go b/prover/init.go index 737b3f011..1406bff57 100644 --- a/prover/init.go +++ b/prover/init.go @@ -113,7 +113,13 @@ func (p *Prover) initProofSubmitters( Dummy: p.cfg.Dummy, } case encoding.TierGuardianID: - producer = proofProducer.NewGuardianProofProducer(p.cfg.EnableLivenessBondProof) + producer = proofProducer.NewGuardianProofProducer(&proofProducer.SGXProofProducer{ + RaikoHostEndpoint: p.cfg.RaikoHostEndpoint, + L1Endpoint: p.cfg.RaikoL1Endpoint, + L1BeaconEndpoint: p.cfg.RaikoL1BeaconEndpoint, + L2Endpoint: p.cfg.RaikoL2Endpoint, + Dummy: p.cfg.Dummy, + }, p.cfg.EnableLivenessBondProof) default: return fmt.Errorf("unsupported tier: %d", tier.ID) } diff --git a/prover/proof_producer/guardian_producer.go b/prover/proof_producer/guardian_producer.go index d638ef1da..0ab9b7217 100644 --- a/prover/proof_producer/guardian_producer.go +++ b/prover/proof_producer/guardian_producer.go @@ -15,11 +15,12 @@ import ( // GuardianProofProducer always returns an optimistic (dummy) proof. type GuardianProofProducer struct { returnLivenessBond bool - DummyProofProducer + *SGXProofProducer } -func NewGuardianProofProducer(returnLivenessBond bool) *GuardianProofProducer { +func NewGuardianProofProducer(sgxProofProducer *SGXProofProducer, returnLivenessBond bool) *GuardianProofProducer { return &GuardianProofProducer{ + SGXProofProducer: sgxProofProducer, returnLivenessBond: returnLivenessBond, } } @@ -51,6 +52,12 @@ func (g *GuardianProofProducer) RequestProof( }, nil } + // Each guardian prover should check the block hash with raiko at first, + // before submitting the guardian proof. + if _, err := g.SGXProofProducer.requestProof(opts); err != nil { + return nil, err + } + return g.DummyProofProducer.RequestProof(opts, blockID, meta, header, g.Tier()) } diff --git a/prover/proof_producer/guardian_producer_test.go b/prover/proof_producer/guardian_producer_test.go index a6e6b6d86..6188bd325 100644 --- a/prover/proof_producer/guardian_producer_test.go +++ b/prover/proof_producer/guardian_producer_test.go @@ -33,7 +33,7 @@ func TestGuardianProducerRequestProof(t *testing.T) { } var ( - producer = NewGuardianProofProducer(false) + producer = NewGuardianProofProducer(&SGXProofProducer{Dummy: true}, false) blockID = common.Big32 ) res, err := producer.RequestProof( @@ -70,7 +70,7 @@ func TestGuardianProducerRequestProofReturnLivenessBond(t *testing.T) { } var ( - producer = NewGuardianProofProducer(true) + producer = NewGuardianProofProducer(&SGXProofProducer{Dummy: true}, true) blockID = common.Big32 ) res, err := producer.RequestProof( From a2f9fcc3bcac317aa73e765bb54c40e962e8b5ac Mon Sep 17 00:00:00 2001 From: David Date: Mon, 6 May 2024 17:59:50 +0800 Subject: [PATCH 2/5] chore: update comments --- prover/proof_producer/guardian_producer.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/prover/proof_producer/guardian_producer.go b/prover/proof_producer/guardian_producer.go index 0ab9b7217..13770eac8 100644 --- a/prover/proof_producer/guardian_producer.go +++ b/prover/proof_producer/guardian_producer.go @@ -53,7 +53,8 @@ func (g *GuardianProofProducer) RequestProof( } // Each guardian prover should check the block hash with raiko at first, - // before submitting the guardian proof. + // before submitting the guardian proof, if raiko can return a proof without + // any error, which means the block hash is valid. if _, err := g.SGXProofProducer.requestProof(opts); err != nil { return nil, err } From 6137bcfb1fea44466fbbd0f8b4206a2f0538f240 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 6 May 2024 18:17:37 +0800 Subject: [PATCH 3/5] test: fix test error --- prover/proof_producer/guardian_producer.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prover/proof_producer/guardian_producer.go b/prover/proof_producer/guardian_producer.go index 13770eac8..6385a98d2 100644 --- a/prover/proof_producer/guardian_producer.go +++ b/prover/proof_producer/guardian_producer.go @@ -27,7 +27,7 @@ func NewGuardianProofProducer(sgxProofProducer *SGXProofProducer, returnLiveness // RequestProof implements the ProofProducer interface. func (g *GuardianProofProducer) RequestProof( - _ context.Context, + ctx context.Context, opts *ProofRequestOptions, blockID *big.Int, meta *bindings.TaikoDataBlockMetadata, @@ -55,7 +55,7 @@ func (g *GuardianProofProducer) RequestProof( // Each guardian prover should check the block hash with raiko at first, // before submitting the guardian proof, if raiko can return a proof without // any error, which means the block hash is valid. - if _, err := g.SGXProofProducer.requestProof(opts); err != nil { + if _, err := g.SGXProofProducer.RequestProof(ctx, opts, blockID, meta, header); err != nil { return nil, err } From 13e80f693eb7019d27d128fd02097801c65d0053 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 6 May 2024 18:21:17 +0800 Subject: [PATCH 4/5] feat: change proof type --- driver/txlist_decompressor/txlist_decompressor.go | 1 + driver/txlist_decompressor/txlist_decompressor_test.go | 1 + prover/init.go | 2 ++ prover/proof_producer/sgx_producer.go | 8 +++++++- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/driver/txlist_decompressor/txlist_decompressor.go b/driver/txlist_decompressor/txlist_decompressor.go index 9018af0ac..a26edc1d9 100644 --- a/driver/txlist_decompressor/txlist_decompressor.go +++ b/driver/txlist_decompressor/txlist_decompressor.go @@ -6,6 +6,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" + "github.com/taikoxyz/taiko-client/internal/utils" ) diff --git a/driver/txlist_decompressor/txlist_decompressor_test.go b/driver/txlist_decompressor/txlist_decompressor_test.go index a816b9e5f..a2d676f10 100644 --- a/driver/txlist_decompressor/txlist_decompressor_test.go +++ b/driver/txlist_decompressor/txlist_decompressor_test.go @@ -13,6 +13,7 @@ import ( "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" "github.com/stretchr/testify/require" + "github.com/taikoxyz/taiko-client/internal/utils" ) diff --git a/prover/init.go b/prover/init.go index 1406bff57..b1f05bf1e 100644 --- a/prover/init.go +++ b/prover/init.go @@ -110,6 +110,7 @@ func (p *Prover) initProofSubmitters( L1Endpoint: p.cfg.RaikoL1Endpoint, L1BeaconEndpoint: p.cfg.RaikoL1BeaconEndpoint, L2Endpoint: p.cfg.RaikoL2Endpoint, + ProofType: proofProducer.ProofTypeSgx, Dummy: p.cfg.Dummy, } case encoding.TierGuardianID: @@ -118,6 +119,7 @@ func (p *Prover) initProofSubmitters( L1Endpoint: p.cfg.RaikoL1Endpoint, L1BeaconEndpoint: p.cfg.RaikoL1BeaconEndpoint, L2Endpoint: p.cfg.RaikoL2Endpoint, + ProofType: proofProducer.ProofTypeCpu, Dummy: p.cfg.Dummy, }, p.cfg.EnableLivenessBondProof) default: diff --git a/prover/proof_producer/sgx_producer.go b/prover/proof_producer/sgx_producer.go index f306a8dfa..2113b1f6c 100644 --- a/prover/proof_producer/sgx_producer.go +++ b/prover/proof_producer/sgx_producer.go @@ -21,12 +21,18 @@ import ( "github.com/taikoxyz/taiko-client/internal/metrics" ) +const ( + ProofTypeSgx = "sgx" + ProofTypeCpu = "native" +) + // SGXProofProducer generates a SGX proof for the given block. type SGXProofProducer struct { RaikoHostEndpoint string // a proverd RPC endpoint L1Endpoint string // a L1 node RPC endpoint L1BeaconEndpoint string // a L1 beacon node RPC endpoint L2Endpoint string // a L2 execution engine's RPC endpoint + ProofType string // Proof type Dummy bool DummyProofProducer } @@ -161,7 +167,7 @@ func (s *SGXProofProducer) requestProof(opts *ProofRequestOptions) (*RaikoHostOu ID: common.Big1, Method: "proof", Params: []*SGXRequestProofBodyParam{{ - Type: "sgx", + Type: s.ProofType, Block: opts.BlockID, L2RPC: s.L2Endpoint, L1RPC: s.L1Endpoint, From d818145bb50fc5144d1a9666e567573f2891f2f4 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 6 May 2024 18:27:36 +0800 Subject: [PATCH 5/5] fix: fix lint errors --- prover/init.go | 2 +- prover/proof_producer/sgx_producer.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/prover/init.go b/prover/init.go index b1f05bf1e..5e8dec1e0 100644 --- a/prover/init.go +++ b/prover/init.go @@ -119,7 +119,7 @@ func (p *Prover) initProofSubmitters( L1Endpoint: p.cfg.RaikoL1Endpoint, L1BeaconEndpoint: p.cfg.RaikoL1BeaconEndpoint, L2Endpoint: p.cfg.RaikoL2Endpoint, - ProofType: proofProducer.ProofTypeCpu, + ProofType: proofProducer.ProofTypeCPU, Dummy: p.cfg.Dummy, }, p.cfg.EnableLivenessBondProof) default: diff --git a/prover/proof_producer/sgx_producer.go b/prover/proof_producer/sgx_producer.go index 2113b1f6c..a4068b8fa 100644 --- a/prover/proof_producer/sgx_producer.go +++ b/prover/proof_producer/sgx_producer.go @@ -23,7 +23,7 @@ import ( const ( ProofTypeSgx = "sgx" - ProofTypeCpu = "native" + ProofTypeCPU = "native" ) // SGXProofProducer generates a SGX proof for the given block.