Skip to content

Commit

Permalink
feat(taiko-client): remove useless flags about raiko (#17302)
Browse files Browse the repository at this point in the history
Co-authored-by: David <[email protected]>
  • Loading branch information
YoGhurt111 and davidtaikocha authored May 24, 2024
1 parent e007150 commit 7945142
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 63 deletions.
24 changes: 5 additions & 19 deletions packages/taiko-client/cmd/flags/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,11 @@ var (
Category: proverCategory,
EnvVars: []string{"RAIKO_HOST"},
}
RaikoL1Endpoint = &cli.StringFlag{
Name: "raiko.l1",
Usage: "L1 RPC endpoint which will be sent to the Raiko service",
RaikoJWTPath = &cli.StringFlag{
Name: "raiko.jwtPath",
Usage: "Path to a JWT secret for the Raiko service",
Category: proverCategory,
EnvVars: []string{"RAIKO_L1"},
}
RaikoL1BeaconEndpoint = &cli.StringFlag{
Name: "raiko.l1Beacon",
Usage: "L1 beacon RPC endpoint which will be sent to the Raiko service",
Category: proverCategory,
EnvVars: []string{"RAIKO_L1_BEACON"},
}
RaikoL2Endpoint = &cli.StringFlag{
Name: "raiko.l2",
Usage: "L2 RPC endpoint which will be sent to the Raiko service",
Category: proverCategory,
EnvVars: []string{"RAIKO_L2"},
EnvVars: []string{"RAIKO_JWT_PATH"},
}
StartingBlockID = &cli.Uint64Flag{
Name: "prover.startingBlockID",
Expand Down Expand Up @@ -230,9 +218,7 @@ var ProverFlags = MergeFlags(CommonFlags, []cli.Flag{
L2HTTPEndpoint,
ProverSetAddress,
RaikoHostEndpoint,
RaikoL1Endpoint,
RaikoL1BeaconEndpoint,
RaikoL2Endpoint,
RaikoJWTPath,
L1ProverPrivKey,
MinOptimisticTierFee,
MinSgxTierFee,
Expand Down
34 changes: 13 additions & 21 deletions packages/taiko-client/prover/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

"github.com/taikoxyz/taiko-mono/packages/taiko-client/cmd/flags"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/internal/utils"

pkgFlags "github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/flags"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/jwt"
)

// Config contains the configurations to initialize a Taiko prover.
Expand Down Expand Up @@ -58,9 +58,7 @@ type Config struct {
Allowance *big.Int
GuardianProverHealthCheckServerEndpoint *url.URL
RaikoHostEndpoint string
RaikoL1Endpoint string
RaikoL1BeaconEndpoint string
RaikoL2Endpoint string
RaikoJWT string
L1NodeVersion string
L2NodeVersion string
BlockConfirmations uint64
Expand All @@ -69,6 +67,9 @@ type Config struct {

// NewConfigFromCliContext creates a new config instance from command line flags.
func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
var (
jwtSecret []byte
)
l1ProverPrivKey, err := crypto.ToECDSA(common.FromHex(c.String(flags.L1ProverPrivKey.Name)))
if err != nil {
return nil, fmt.Errorf("invalid L1 prover private key: %w", err)
Expand Down Expand Up @@ -119,20 +120,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
return nil, errors.New("--prover.l2NodeVersion flag is required if guardian prover is set")
}
}
var (
raikoL1Endpoint = c.String(flags.RaikoL1Endpoint.Name)
raikoL1BeaconEndpoint = c.String(flags.RaikoL1BeaconEndpoint.Name)
raikoL2Endpoint = c.String(flags.RaikoL2Endpoint.Name)
)
if raikoL1Endpoint == "" {
raikoL1Endpoint = c.String(flags.L1HTTPEndpoint.Name)
}
if raikoL1BeaconEndpoint == "" {
raikoL1BeaconEndpoint = c.String(flags.L1BeaconEndpoint.Name)
}
if raikoL2Endpoint == "" {
raikoL2Endpoint = c.String(flags.L2HTTPEndpoint.Name)
}

minOptimisticTierFee, err := utils.GWeiToWei(c.Float64(flags.MinOptimisticTierFee.Name))
if err != nil {
Expand Down Expand Up @@ -163,6 +150,13 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
return nil, errors.New("empty raiko host endpoint")
}

if c.IsSet(flags.RaikoJWTPath.Name) {
jwtSecret, err = jwt.ParseSecretFromFile(c.String(flags.RaikoJWTPath.Name))
if err != nil {
return nil, fmt.Errorf("invalid JWT secret file: %w", err)
}
}

return &Config{
L1WsEndpoint: c.String(flags.L1WSEndpoint.Name),
L1HttpEndpoint: c.String(flags.L1HTTPEndpoint.Name),
Expand All @@ -176,9 +170,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
ProverSetAddress: common.HexToAddress(c.String(flags.ProverSetAddress.Name)),
L1ProverPrivKey: l1ProverPrivKey,
RaikoHostEndpoint: c.String(flags.RaikoHostEndpoint.Name),
RaikoL1Endpoint: raikoL1Endpoint,
RaikoL1BeaconEndpoint: raikoL1BeaconEndpoint,
RaikoL2Endpoint: raikoL2Endpoint,
RaikoJWT: string(jwtSecret),
StartingBlockID: startingBlockID,
Dummy: c.Bool(flags.Dummy.Name),
GuardianProverMinorityAddress: common.HexToAddress(c.String(flags.GuardianProverMinority.Name)),
Expand Down
4 changes: 1 addition & 3 deletions packages/taiko-client/prover/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ func (p *Prover) initProofSubmitters(
case encoding.TierSgxID:
producer = &proofProducer.SGXProofProducer{
RaikoHostEndpoint: p.cfg.RaikoHostEndpoint,
L1Endpoint: p.cfg.RaikoL1Endpoint,
L1BeaconEndpoint: p.cfg.RaikoL1BeaconEndpoint,
L2Endpoint: p.cfg.RaikoL2Endpoint,
JWT: p.cfg.RaikoJWT,
ProofType: proofProducer.ProofTypeSgx,
Dummy: p.cfg.Dummy,
}
Expand Down
44 changes: 24 additions & 20 deletions packages/taiko-client/prover/proof_producer/sgx_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package producer
import (
"bytes"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io"
Expand All @@ -28,25 +29,20 @@ const (
// 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
JWT string // JWT provided by Raiko
Dummy bool
DummyProofProducer
}

// RaikoRequestProofBody represents the JSON body for requesting the proof.
type RaikoRequestProofBody struct {
L2RPC string `json:"rpc"`
L1RPC string `json:"l1_rpc"`
L1BeaconRPC string `json:"beacon_rpc"`
Block *big.Int `json:"block_number"`
Prover string `json:"prover"`
Graffiti string `json:"graffiti"`
Type string `json:"proof_type"`
SGX *SGXRequestProofBodyParam `json:"sgx"`
RISC0 RISC0RequestProofBodyParam `json:"risc0"`
Block *big.Int `json:"block_number"`
Prover string `json:"prover"`
Graffiti string `json:"graffiti"`
Type string `json:"proof_type"`
SGX *SGXRequestProofBodyParam `json:"sgx"`
RISC0 RISC0RequestProofBodyParam `json:"risc0"`
}

// SGXRequestProofBodyParam represents the JSON body of RaikoRequestProofBody's `sgx` field.
Expand Down Expand Up @@ -164,26 +160,34 @@ func (s *SGXProofProducer) callProverDaemon(ctx context.Context, opts *ProofRequ
// requestProof sends a RPC request to proverd to try to get the requested proof.
func (s *SGXProofProducer) requestProof(opts *ProofRequestOptions) (*RaikoRequestProofBodyResponse, error) {
reqBody := RaikoRequestProofBody{
Type: s.ProofType,
Block: opts.BlockID,
L2RPC: s.L2Endpoint,
L1RPC: s.L1Endpoint,
L1BeaconRPC: s.L1BeaconEndpoint,
Prover: opts.ProverAddress.Hex()[2:],
Graffiti: opts.Graffiti,
Type: s.ProofType,
Block: opts.BlockID,
Prover: opts.ProverAddress.Hex()[2:],
Graffiti: opts.Graffiti,
SGX: &SGXRequestProofBodyParam{
Setup: false,
Bootstrap: false,
Prove: true,
},
}

client := &http.Client{}

jsonValue, err := json.Marshal(reqBody)
if err != nil {
return nil, err
}

res, err := http.Post(s.RaikoHostEndpoint+"/v1/proof", "application/json", bytes.NewBuffer(jsonValue))
req, err := http.NewRequest("POST", s.RaikoHostEndpoint+"/v1/proof", bytes.NewBuffer(jsonValue))
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
if len(s.JWT) > 0 {
req.Header.Set("Authorization", "Bearer "+base64.StdEncoding.EncodeToString([]byte(s.JWT)))
}

res, err := client.Do(req)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 7945142

Please sign in to comment.