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

Commit

Permalink
feat(prover): introduce TierGuardianMinority (#777)
Browse files Browse the repository at this point in the history
Co-authored-by: gavin <gavin@taiko.xyz>
Co-authored-by: maskpp <maskpp266@gmail.com>
  • Loading branch information
3 people authored May 7, 2024
1 parent 0c52dc5 commit 4ab635c
Show file tree
Hide file tree
Showing 23 changed files with 269 additions and 113 deletions.
14 changes: 8 additions & 6 deletions bindings/encoding/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ import (

// Tier IDs defined in protocol.
var (
TierOptimisticID uint16 = 100
TierSgxID uint16 = 200
TierSgxAndZkVMID uint16 = 300
TierGuardianID uint16 = 1000
ProtocolTiers = []uint16{
TierOptimisticID uint16 = 100
TierSgxID uint16 = 200
TierSgxAndZkVMID uint16 = 300
TierGuardianMinorityID uint16 = 900
TierGuardianMajorityID uint16 = 1000
ProtocolTiers = []uint16{
TierOptimisticID,
TierSgxID,
TierSgxAndZkVMID,
TierGuardianID,
TierGuardianMinorityID,
TierGuardianMajorityID,
}
GoldenTouchPrivKey = "92954368afd3caa1f3ce3ead0069c1af414054aefe1ef9aeacc1bf426222ce38"
)
Expand Down
20 changes: 15 additions & 5 deletions cmd/flags/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"time"

"github.com/urfave/cli/v2"

"github.com/taikoxyz/taiko-client/pkg/rpc"
)

// Required flags used by prover.
Expand Down Expand Up @@ -165,11 +167,18 @@ var (
EnvVars: []string{"PROVER_GUARDIAN_PROVER_HEALTH_CHECK_SERVER_ENDPOINT"},
}
// Guardian prover specific flag
GuardianProver = &cli.StringFlag{
Name: "guardianProver",
Usage: "GuardianProver contract `address`",
GuardianProverMinority = &cli.StringFlag{
Name: "guardianProverMinority",
Usage: "GuardianProverMinority contract `address`",
Value: rpc.ZeroAddress.Hex(),
Category: proverCategory,
EnvVars: []string{"GUARDIAN_PROVER_MINORITY"},
}
GuardianProverMajority = &cli.StringFlag{
Name: "guardianProverMajority",
Usage: "GuardianProverMajority contract `address`",
Category: proverCategory,
EnvVars: []string{"GUARDIAN_PROVER"},
EnvVars: []string{"GUARDIAN_PROVER_MAJORITY"},
}
GuardianProofSubmissionDelay = &cli.DurationFlag{
Name: "guardian.submissionDelay",
Expand Down Expand Up @@ -225,7 +234,8 @@ var ProverFlags = MergeFlags(CommonFlags, []cli.Flag{
MinTaikoTokenBalance,
StartingBlockID,
Dummy,
GuardianProver,
GuardianProverMinority,
GuardianProverMajority,
GuardianProofSubmissionDelay,
GuardianProverHealthCheckServerEndpoint,
Graffiti,
Expand Down
1 change: 1 addition & 0 deletions integration_test/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ check_env "ASSIGNMENT_HOOK_ADDRESS"
check_env "TIMELOCK_CONTROLLER"
check_env "ROLLUP_ADDRESS_MANAGER_CONTRACT_ADDRESS"
check_env "GUARDIAN_PROVER_CONTRACT_ADDRESS"
check_env "GUARDIAN_PROVER_MINORITY_ADDRESS"
check_env "L1_CONTRACT_OWNER_PRIVATE_KEY"
check_env "L1_SECURITY_COUNCIL_PRIVATE_KEY"
check_env "L1_PROPOSER_PRIVATE_KEY"
Expand Down
2 changes: 2 additions & 0 deletions integration_test/test_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export ASSIGNMENT_HOOK_ADDRESS=$(echo "$DEPLOYMENT_JSON" | jq '.assignment_hook'
export TIMELOCK_CONTROLLER=$(echo "$DEPLOYMENT_JSON" | jq '.timelock_controller' | sed 's/\"//g')
export ROLLUP_ADDRESS_MANAGER_CONTRACT_ADDRESS=$(echo "$DEPLOYMENT_JSON" | jq '.rollup_address_manager' | sed 's/\"//g')
export GUARDIAN_PROVER_CONTRACT_ADDRESS=$(echo "$DEPLOYMENT_JSON" | jq '.guardian_prover' | sed 's/\"//g')
export GUARDIAN_PROVER_MINORITY_ADDRESS=$(echo "$DEPLOYMENT_JSON" | jq '.guardian_prover_minority' | sed 's/\"//g')
export L1_CONTRACT_OWNER_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
export L1_SECURITY_COUNCIL_PRIVATE_KEY=0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97
export L1_PROPOSER_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
Expand All @@ -40,6 +41,7 @@ ASSIGNMENT_HOOK_ADDRESS=$ASSIGNMENT_HOOK_ADDRESS
TIMELOCK_CONTROLLER=$TIMELOCK_CONTROLLER
ROLLUP_ADDRESS_MANAGER_CONTRACT_ADDRESS=$ROLLUP_ADDRESS_MANAGER_CONTRACT_ADDRESS
GUARDIAN_PROVER_CONTRACT_ADDRESS=$GUARDIAN_PROVER_CONTRACT_ADDRESS
GUARDIAN_PROVER_MINORITY_ADDRESS=$GUARDIAN_PROVER_MINORITY_ADDRESS
L1_CONTRACT_OWNER_PRIVATE_KEY=$L1_CONTRACT_OWNER_PRIVATE_KEY
L1_SECURITY_COUNCIL_PRIVATE_KEY=$L1_SECURITY_COUNCIL_PRIVATE_KEY
L1_PROPOSER_PRIVATE_KEY=$L1_PROPOSER_PRIVATE_KEY
Expand Down
17 changes: 9 additions & 8 deletions internal/testutils/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ func (s *ClientTestSuite) SetupTest() {
s.NotEmpty(jwtSecret)

rpcCli, err := rpc.NewClient(context.Background(), &rpc.ClientConfig{
L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"),
L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"),
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")),
TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")),
GuardianProverAddress: common.HexToAddress(os.Getenv("GUARDIAN_PROVER_CONTRACT_ADDRESS")),
L2EngineEndpoint: os.Getenv("L2_EXECUTION_ENGINE_AUTH_ENDPOINT"),
JwtSecret: string(jwtSecret),
L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"),
L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"),
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")),
TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")),
GuardianProverMajorityAddress: common.HexToAddress(os.Getenv("GUARDIAN_PROVER_CONTRACT_ADDRESS")),
GuardianProverMinorityAddress: common.HexToAddress(os.Getenv("GUARDIAN_PROVER_MINORITY_ADDRESS")),
L2EngineEndpoint: os.Getenv("L2_EXECUTION_ENGINE_AUTH_ENDPOINT"),
JwtSecret: string(jwtSecret),
})
s.Nil(err)
s.RPCClient = rpcCli
Expand Down
65 changes: 37 additions & 28 deletions pkg/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,29 @@ type Client struct {
// Beacon clients
L1Beacon *BeaconClient
// Protocol contracts clients
TaikoL1 *bindings.TaikoL1Client
TaikoL2 *bindings.TaikoL2Client
TaikoToken *bindings.TaikoToken
GuardianProver *bindings.GuardianProver
TaikoL1 *bindings.TaikoL1Client
TaikoL2 *bindings.TaikoL2Client
TaikoToken *bindings.TaikoToken
GuardianProverMajority *bindings.GuardianProver
GuardianProverMinority *bindings.GuardianProver
}

// ClientConfig contains all configs which will be used to initializing an
// RPC client. If not providing L2EngineEndpoint or JwtSecret, then the L2Engine client
// won't be initialized.
type ClientConfig struct {
L1Endpoint string
L2Endpoint string
L1BeaconEndpoint string
L2CheckPoint string
TaikoL1Address common.Address
TaikoL2Address common.Address
TaikoTokenAddress common.Address
GuardianProverAddress common.Address
L2EngineEndpoint string
JwtSecret string
Timeout time.Duration
L1Endpoint string
L2Endpoint string
L1BeaconEndpoint string
L2CheckPoint string
TaikoL1Address common.Address
TaikoL2Address common.Address
TaikoTokenAddress common.Address
GuardianProverMinorityAddress common.Address
GuardianProverMajorityAddress common.Address
L2EngineEndpoint string
JwtSecret string
Timeout time.Duration
}

// NewClient initializes all RPC clients used by Taiko client software.
Expand Down Expand Up @@ -110,16 +112,22 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) {
}

var (
taikoToken *bindings.TaikoToken
guardianProver *bindings.GuardianProver
taikoToken *bindings.TaikoToken
guardianProverMajority *bindings.GuardianProver
guardianProverMinority *bindings.GuardianProver
)
if cfg.TaikoTokenAddress.Hex() != ZeroAddress.Hex() {
if taikoToken, err = bindings.NewTaikoToken(cfg.TaikoTokenAddress, l1Client); err != nil {
return nil, err
}
}
if cfg.GuardianProverAddress.Hex() != ZeroAddress.Hex() {
if guardianProver, err = bindings.NewGuardianProver(cfg.GuardianProverAddress, l1Client); err != nil {
if cfg.GuardianProverMinorityAddress.Hex() != ZeroAddress.Hex() {
if guardianProverMinority, err = bindings.NewGuardianProver(cfg.GuardianProverMinorityAddress, l1Client); err != nil {
return nil, err
}
}
if cfg.GuardianProverMajorityAddress.Hex() != ZeroAddress.Hex() {
if guardianProverMajority, err = bindings.NewGuardianProver(cfg.GuardianProverMajorityAddress, l1Client); err != nil {
return nil, err
}
}
Expand All @@ -135,15 +143,16 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) {
}

client := &Client{
L1: l1Client,
L1Beacon: l1BeaconClient,
L2: l2Client,
L2CheckPoint: l2CheckPoint,
L2Engine: l2AuthClient,
TaikoL1: taikoL1,
TaikoL2: taikoL2,
TaikoToken: taikoToken,
GuardianProver: guardianProver,
L1: l1Client,
L1Beacon: l1BeaconClient,
L2: l2Client,
L2CheckPoint: l2CheckPoint,
L2Engine: l2AuthClient,
TaikoL1: taikoL1,
TaikoL2: taikoL2,
TaikoToken: taikoToken,
GuardianProverMajority: guardianProverMajority,
GuardianProverMinority: guardianProverMinority,
}

if err := client.ensureGenesisMatched(ctxWithTimeout); err != nil {
Expand Down
4 changes: 3 additions & 1 deletion proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,9 @@ func (p *Proposer) initTierFees() error {
p.tierFees = append(p.tierFees, encoding.TierFee{Tier: tier.ID, Fee: p.OptimisticTierFee})
case encoding.TierSgxID:
p.tierFees = append(p.tierFees, encoding.TierFee{Tier: tier.ID, Fee: p.SgxTierFee})
case encoding.TierGuardianID:
case encoding.TierGuardianMinorityID:
p.tierFees = append(p.tierFees, encoding.TierFee{Tier: tier.ID, Fee: common.Big0})
case encoding.TierGuardianMajorityID:
// Guardian prover should not charge any fee.
p.tierFees = append(p.tierFees, encoding.TierFee{Tier: tier.ID, Fee: common.Big0})
default:
Expand Down
9 changes: 5 additions & 4 deletions prover/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ type Config struct {
L1ProverPrivKey *ecdsa.PrivateKey
StartingBlockID *big.Int
Dummy bool
GuardianProverAddress common.Address
GuardianProverMinorityAddress common.Address
GuardianProverMajorityAddress common.Address
GuardianProofSubmissionDelay time.Duration
Graffiti string
BackOffMaxRetries uint64
Expand Down Expand Up @@ -101,7 +102,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
}

// If we are running a guardian prover, we need to prove unassigned blocks and run in contester mode by default.
if c.IsSet(flags.GuardianProver.Name) {
if c.IsSet(flags.GuardianProverMajority.Name) {
if err := c.Set(flags.ProveUnassignedBlocks.Name, "true"); err != nil {
return nil, err
}
Expand All @@ -117,7 +118,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)
Expand Down Expand Up @@ -175,7 +175,8 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
RaikoL2Endpoint: raikoL2Endpoint,
StartingBlockID: startingBlockID,
Dummy: c.Bool(flags.Dummy.Name),
GuardianProverAddress: common.HexToAddress(c.String(flags.GuardianProver.Name)),
GuardianProverMinorityAddress: common.HexToAddress(c.String(flags.GuardianProverMinority.Name)),
GuardianProverMajorityAddress: common.HexToAddress(c.String(flags.GuardianProverMajority.Name)),
GuardianProofSubmissionDelay: c.Duration(flags.GuardianProofSubmissionDelay.Name),
GuardianProverHealthCheckServerEndpoint: guardianProverHealthCheckServerEndpoint,
Graffiti: c.String(flags.Graffiti.Name),
Expand Down
8 changes: 6 additions & 2 deletions prover/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,16 @@ func (s *ProverTestSuite) TestNewConfigFromCliContextGuardianProver() {
"--" + flags.MinOptimisticTierFee.Name, fmt.Sprint(minTierFee),
"--" + flags.MinSgxTierFee.Name, fmt.Sprint(minTierFee),
"--" + flags.ProverCapacity.Name, "8",
"--" + flags.GuardianProver.Name, os.Getenv("GUARDIAN_PROVER_CONTRACT_ADDRESS"),
"--" + flags.GuardianProverMajority.Name, os.Getenv("GUARDIAN_PROVER_CONTRACT_ADDRESS"),
"--" + flags.GuardianProverMinority.Name, os.Getenv("GUARDIAN_PROVER_MINORITY_ADDRESS"),
"--" + flags.AssignmentHookAddress.Name, os.Getenv("ASSIGNMENT_HOOK_ADDRESS"),
"--" + flags.Graffiti.Name, "",
"--" + flags.ProveUnassignedBlocks.Name,
"--" + flags.MaxProposedIn.Name, "100",
"--" + flags.Allowance.Name, fmt.Sprint(allowance),
"--" + flags.L1NodeVersion.Name, l1NodeVersion,
"--" + flags.L2NodeVersion.Name, l2NodeVersion,
"--" + flags.RaikoHostEndpoint.Name, "https://dummy.raiko.xyz",
}))
}

Expand All @@ -117,7 +119,8 @@ func (s *ProverTestSuite) SetupApp() *cli.App {
&cli.StringFlag{Name: flags.L1ProverPrivKey.Name},
&cli.Uint64Flag{Name: flags.StartingBlockID.Name},
&cli.BoolFlag{Name: flags.Dummy.Name},
&cli.StringFlag{Name: flags.GuardianProver.Name},
&cli.StringFlag{Name: flags.GuardianProverMajority.Name},
&cli.StringFlag{Name: flags.GuardianProverMinority.Name},
&cli.StringFlag{Name: flags.Graffiti.Name},
&cli.BoolFlag{Name: flags.ProveUnassignedBlocks.Name},
&cli.DurationFlag{Name: flags.RPCTimeout.Name},
Expand All @@ -130,6 +133,7 @@ func (s *ProverTestSuite) SetupApp() *cli.App {
&cli.StringFlag{Name: flags.ContesterMode.Name},
&cli.StringFlag{Name: flags.L1NodeVersion.Name},
&cli.StringFlag{Name: flags.L2NodeVersion.Name},
&cli.StringFlag{Name: flags.RaikoHostEndpoint.Name},
}
app.Flags = append(app.Flags, flags.TxmgrFlags...)
app.Action = func(ctx *cli.Context) error {
Expand Down
14 changes: 7 additions & 7 deletions prover/event_handler/block_proposed.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ type BlockProposedEventHandler struct {
backOffMaxRetrys uint64
contesterMode bool
proveUnassignedBlocks bool
tierToOverride uint16
submissionDelay time.Duration
// Guardian prover related.
isGuardian bool
submissionDelay time.Duration
}

// NewBlockProposedEventHandlerOps is the options for creating a new BlockProposedEventHandler.
Expand Down Expand Up @@ -79,7 +80,7 @@ func NewBlockProposedEventHandler(opts *NewBlockProposedEventHandlerOps) *BlockP
opts.BackOffMaxRetrys,
opts.ContesterMode,
opts.ProveUnassignedBlocks,
0,
false,
opts.SubmissionDelay,
}
}
Expand Down Expand Up @@ -347,8 +348,8 @@ func (h *BlockProposedEventHandler) checkExpirationAndSubmitProof(
return err
}

if h.tierToOverride != 0 {
tier = h.tierToOverride
if h.isGuardian {
tier = encoding.TierGuardianMinorityID
}

log.Info(
Expand Down Expand Up @@ -388,8 +389,7 @@ func NewBlockProposedEventGuardianHandler(
opts *NewBlockProposedGuardianEventHandlerOps,
) *BlockProposedGuaridanEventHandler {
blockProposedEventHandler := NewBlockProposedEventHandler(opts.NewBlockProposedEventHandlerOps)
// For guardian provers, we only send top tier proofs.
blockProposedEventHandler.tierToOverride = encoding.TierGuardianID
blockProposedEventHandler.isGuardian = true

return &BlockProposedGuaridanEventHandler{
BlockProposedEventHandler: blockProposedEventHandler,
Expand Down
2 changes: 1 addition & 1 deletion prover/event_handler/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type ProverEventHandlerTestSuite struct {
func (s *ProverEventHandlerTestSuite) TestGetProvingWindowNotFound() {
_, err := getProvingWindow(&bindings.TaikoL1ClientBlockProposed{
Meta: bindings.TaikoDataBlockMetadata{
MinTier: encoding.TierGuardianID + 1,
MinTier: encoding.TierGuardianMajorityID + 1,
},
}, []*rpc.TierProviderTierWithID{})
s.ErrorIs(err, errTierNotFound)
Expand Down
13 changes: 11 additions & 2 deletions prover/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,24 @@ func (p *Prover) initProofSubmitters(
ProofType: proofProducer.ProofTypeSgx,
Dummy: p.cfg.Dummy,
}
case encoding.TierGuardianID:
case encoding.TierGuardianMinorityID:
producer = proofProducer.NewGuardianProofProducer(&proofProducer.SGXProofProducer{
RaikoHostEndpoint: p.cfg.RaikoHostEndpoint,
L1Endpoint: p.cfg.RaikoL1Endpoint,
L1BeaconEndpoint: p.cfg.RaikoL1BeaconEndpoint,
L2Endpoint: p.cfg.RaikoL2Endpoint,
ProofType: proofProducer.ProofTypeCPU,
Dummy: p.cfg.Dummy,
}, p.cfg.EnableLivenessBondProof)
}, encoding.TierGuardianMinorityID, p.cfg.EnableLivenessBondProof)
case encoding.TierGuardianMajorityID:
producer = proofProducer.NewGuardianProofProducer(&proofProducer.SGXProofProducer{
RaikoHostEndpoint: p.cfg.RaikoHostEndpoint,
L1Endpoint: p.cfg.RaikoL1Endpoint,
L1BeaconEndpoint: p.cfg.RaikoL1BeaconEndpoint,
L2Endpoint: p.cfg.RaikoL2Endpoint,
ProofType: proofProducer.ProofTypeCPU,
Dummy: p.cfg.Dummy,
}, encoding.TierGuardianMajorityID, p.cfg.EnableLivenessBondProof)
default:
return fmt.Errorf("unsupported tier: %d", tier.ID)
}
Expand Down
Loading

0 comments on commit 4ab635c

Please sign in to comment.