Skip to content
This repository was archived by the owner on May 11, 2024. It is now read-only.

Commit da5ad24

Browse files
feat(prover): make guardian provers connecting to their local raiko service (#797)
1 parent c0a5ddd commit da5ad24

File tree

7 files changed

+31
-12
lines changed

7 files changed

+31
-12
lines changed

driver/txlist_decompressor/txlist_decompressor.go

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/ethereum/go-ethereum/core/types"
77
"github.com/ethereum/go-ethereum/log"
88
"github.com/ethereum/go-ethereum/rlp"
9+
910
"github.com/taikoxyz/taiko-client/internal/utils"
1011
)
1112

driver/txlist_decompressor/txlist_decompressor_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/ethereum/go-ethereum/params"
1414
"github.com/ethereum/go-ethereum/rlp"
1515
"github.com/stretchr/testify/require"
16+
1617
"github.com/taikoxyz/taiko-client/internal/utils"
1718
)
1819

prover/config.go

-5
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
118118
}
119119
}
120120

121-
// If we are not running a guardian prover, a raiko host endpoint is required.
122-
if !c.IsSet(flags.GuardianProver.Name) && !c.IsSet(flags.RaikoHostEndpoint.Name) {
123-
return nil, errors.New("raiko host not provided")
124-
}
125-
126121
var (
127122
raikoL1Endpoint = c.String(flags.RaikoL1Endpoint.Name)
128123
raikoL1BeaconEndpoint = c.String(flags.RaikoL1BeaconEndpoint.Name)

prover/init.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,18 @@ func (p *Prover) initProofSubmitters(
110110
L1Endpoint: p.cfg.RaikoL1Endpoint,
111111
L1BeaconEndpoint: p.cfg.RaikoL1BeaconEndpoint,
112112
L2Endpoint: p.cfg.RaikoL2Endpoint,
113+
ProofType: proofProducer.ProofTypeSgx,
113114
Dummy: p.cfg.Dummy,
114115
}
115116
case encoding.TierGuardianID:
116-
producer = proofProducer.NewGuardianProofProducer(p.cfg.EnableLivenessBondProof)
117+
producer = proofProducer.NewGuardianProofProducer(&proofProducer.SGXProofProducer{
118+
RaikoHostEndpoint: p.cfg.RaikoHostEndpoint,
119+
L1Endpoint: p.cfg.RaikoL1Endpoint,
120+
L1BeaconEndpoint: p.cfg.RaikoL1BeaconEndpoint,
121+
L2Endpoint: p.cfg.RaikoL2Endpoint,
122+
ProofType: proofProducer.ProofTypeCPU,
123+
Dummy: p.cfg.Dummy,
124+
}, p.cfg.EnableLivenessBondProof)
117125
default:
118126
return fmt.Errorf("unsupported tier: %d", tier.ID)
119127
}

prover/proof_producer/guardian_producer.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ import (
1515
// GuardianProofProducer always returns an optimistic (dummy) proof.
1616
type GuardianProofProducer struct {
1717
returnLivenessBond bool
18-
DummyProofProducer
18+
*SGXProofProducer
1919
}
2020

21-
func NewGuardianProofProducer(returnLivenessBond bool) *GuardianProofProducer {
21+
func NewGuardianProofProducer(sgxProofProducer *SGXProofProducer, returnLivenessBond bool) *GuardianProofProducer {
2222
return &GuardianProofProducer{
23+
SGXProofProducer: sgxProofProducer,
2324
returnLivenessBond: returnLivenessBond,
2425
}
2526
}
2627

2728
// RequestProof implements the ProofProducer interface.
2829
func (g *GuardianProofProducer) RequestProof(
29-
_ context.Context,
30+
ctx context.Context,
3031
opts *ProofRequestOptions,
3132
blockID *big.Int,
3233
meta *bindings.TaikoDataBlockMetadata,
@@ -51,6 +52,13 @@ func (g *GuardianProofProducer) RequestProof(
5152
}, nil
5253
}
5354

55+
// Each guardian prover should check the block hash with raiko at first,
56+
// before submitting the guardian proof, if raiko can return a proof without
57+
// any error, which means the block hash is valid.
58+
if _, err := g.SGXProofProducer.RequestProof(ctx, opts, blockID, meta, header); err != nil {
59+
return nil, err
60+
}
61+
5462
return g.DummyProofProducer.RequestProof(opts, blockID, meta, header, g.Tier())
5563
}
5664

prover/proof_producer/guardian_producer_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestGuardianProducerRequestProof(t *testing.T) {
3333
}
3434

3535
var (
36-
producer = NewGuardianProofProducer(false)
36+
producer = NewGuardianProofProducer(&SGXProofProducer{Dummy: true}, false)
3737
blockID = common.Big32
3838
)
3939
res, err := producer.RequestProof(
@@ -70,7 +70,7 @@ func TestGuardianProducerRequestProofReturnLivenessBond(t *testing.T) {
7070
}
7171

7272
var (
73-
producer = NewGuardianProofProducer(true)
73+
producer = NewGuardianProofProducer(&SGXProofProducer{Dummy: true}, true)
7474
blockID = common.Big32
7575
)
7676
res, err := producer.RequestProof(

prover/proof_producer/sgx_producer.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@ import (
2121
"github.com/taikoxyz/taiko-client/internal/metrics"
2222
)
2323

24+
const (
25+
ProofTypeSgx = "sgx"
26+
ProofTypeCPU = "native"
27+
)
28+
2429
// SGXProofProducer generates a SGX proof for the given block.
2530
type SGXProofProducer struct {
2631
RaikoHostEndpoint string // a proverd RPC endpoint
2732
L1Endpoint string // a L1 node RPC endpoint
2833
L1BeaconEndpoint string // a L1 beacon node RPC endpoint
2934
L2Endpoint string // a L2 execution engine's RPC endpoint
35+
ProofType string // Proof type
3036
Dummy bool
3137
DummyProofProducer
3238
}
@@ -161,7 +167,7 @@ func (s *SGXProofProducer) requestProof(opts *ProofRequestOptions) (*RaikoHostOu
161167
ID: common.Big1,
162168
Method: "proof",
163169
Params: []*SGXRequestProofBodyParam{{
164-
Type: "sgx",
170+
Type: s.ProofType,
165171
Block: opts.BlockID,
166172
L2RPC: s.L2Endpoint,
167173
L1RPC: s.L1Endpoint,

0 commit comments

Comments
 (0)