From 794514227afee296e1e2fed82e85769cc5efe1d0 Mon Sep 17 00:00:00 2001 From: Gavin Yu Date: Fri, 24 May 2024 22:59:41 +0800 Subject: [PATCH] feat(taiko-client): remove useless flags about raiko (#17302) Co-authored-by: David --- packages/taiko-client/cmd/flags/prover.go | 24 +++------- packages/taiko-client/prover/config.go | 34 ++++++-------- packages/taiko-client/prover/init.go | 4 +- .../prover/proof_producer/sgx_producer.go | 44 ++++++++++--------- 4 files changed, 43 insertions(+), 63 deletions(-) diff --git a/packages/taiko-client/cmd/flags/prover.go b/packages/taiko-client/cmd/flags/prover.go index 0917306131..b1766659b4 100644 --- a/packages/taiko-client/cmd/flags/prover.go +++ b/packages/taiko-client/cmd/flags/prover.go @@ -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", @@ -230,9 +218,7 @@ var ProverFlags = MergeFlags(CommonFlags, []cli.Flag{ L2HTTPEndpoint, ProverSetAddress, RaikoHostEndpoint, - RaikoL1Endpoint, - RaikoL1BeaconEndpoint, - RaikoL2Endpoint, + RaikoJWTPath, L1ProverPrivKey, MinOptimisticTierFee, MinSgxTierFee, diff --git a/packages/taiko-client/prover/config.go b/packages/taiko-client/prover/config.go index 732f2503b8..b57a7a6f07 100644 --- a/packages/taiko-client/prover/config.go +++ b/packages/taiko-client/prover/config.go @@ -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. @@ -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 @@ -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) @@ -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 { @@ -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), @@ -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)), diff --git a/packages/taiko-client/prover/init.go b/packages/taiko-client/prover/init.go index 26b8a4454f..2e5fdb8064 100644 --- a/packages/taiko-client/prover/init.go +++ b/packages/taiko-client/prover/init.go @@ -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, } diff --git a/packages/taiko-client/prover/proof_producer/sgx_producer.go b/packages/taiko-client/prover/proof_producer/sgx_producer.go index 0e00254746..96cf6572d7 100644 --- a/packages/taiko-client/prover/proof_producer/sgx_producer.go +++ b/packages/taiko-client/prover/proof_producer/sgx_producer.go @@ -3,6 +3,7 @@ package producer import ( "bytes" "context" + "encoding/base64" "encoding/json" "fmt" "io" @@ -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. @@ -164,13 +160,10 @@ 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, @@ -178,12 +171,23 @@ func (s *SGXProofProducer) requestProof(opts *ProofRequestOptions) (*RaikoReques }, } + 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 }