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
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Apr 29, 2024
1 parent a352b40 commit 9b12c2f
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 48 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
19 changes: 14 additions & 5 deletions cmd/flags/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package flags
import (
"time"

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

Expand Down Expand Up @@ -164,11 +165,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"},
EnvVars: []string{"GUARDIAN_PROVER_MINORITY"},
}
GuardianProverMajority = &cli.StringFlag{
Name: "guardianProverMajority",
Usage: "GuardianProverMajority contract `address`",
Category: proverCategory,
EnvVars: []string{"GUARDIAN_PROVER_MAJORITY"},
}
GuardianProofSubmissionDelay = &cli.DurationFlag{
Name: "guardian.submissionDelay",
Expand Down Expand Up @@ -224,7 +232,8 @@ var ProverFlags = MergeFlags(CommonFlags, []cli.Flag{
MinTaikoTokenBalance,
StartingBlockID,
Dummy,
GuardianProver,
GuardianProverMinority,
GuardianProverMajority,
GuardianProofSubmissionDelay,
GuardianProverHealthCheckServerEndpoint,
Graffiti,
Expand Down
2 changes: 1 addition & 1 deletion proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ 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.TierGuardianMajorityID:
// Guardian prover should not charge any fee.
p.tierFees = append(p.tierFees, encoding.TierFee{Tier: tier.ID, Fee: common.Big0})
default:
Expand Down
10 changes: 6 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 @@ -119,7 +120,7 @@ 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) {
if !c.IsSet(flags.GuardianProverMajority.Name) && !c.IsSet(flags.RaikoHostEndpoint.Name) {
return nil, errors.New("raiko host not provided")
}

Expand Down Expand Up @@ -180,7 +181,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
4 changes: 2 additions & 2 deletions prover/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ 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.AssignmentHookAddress.Name, os.Getenv("ASSIGNMENT_HOOK_ADDRESS"),
"--" + flags.Graffiti.Name, "",
"--" + flags.ProveUnassignedBlocks.Name,
Expand Down Expand Up @@ -117,7 +117,7 @@ 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.Graffiti.Name},
&cli.BoolFlag{Name: flags.ProveUnassignedBlocks.Name},
&cli.DurationFlag{Name: flags.RPCTimeout.Name},
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
2 changes: 1 addition & 1 deletion prover/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (p *Prover) initProofSubmitters(
L2Endpoint: p.cfg.RaikoL2Endpoint,
Dummy: p.cfg.Dummy,
}
case encoding.TierGuardianID:
case encoding.TierGuardianMajorityID:
producer = proofProducer.NewGuardianProofProducer(p.cfg.EnableLivenessBondProof)
default:
return fmt.Errorf("unsupported tier: %d", tier.ID)
Expand Down
2 changes: 1 addition & 1 deletion prover/proof_producer/guardian_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ func (g *GuardianProofProducer) RequestProof(

// Tier implements the ProofProducer interface.
func (g *GuardianProofProducer) Tier() uint16 {
return encoding.TierGuardianID
return encoding.TierGuardianMajorityID
}
4 changes: 2 additions & 2 deletions prover/proof_producer/guardian_producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestGuardianProducerRequestProof(t *testing.T) {

require.Equal(t, res.BlockID, blockID)
require.Equal(t, res.Header, header)
require.Equal(t, res.Tier, encoding.TierGuardianID)
require.Equal(t, res.Tier, encoding.TierGuardianMajorityID)
require.NotEmpty(t, res.Proof)
}

Expand Down Expand Up @@ -84,7 +84,7 @@ func TestGuardianProducerRequestProofReturnLivenessBond(t *testing.T) {

require.Equal(t, res.BlockID, blockID)
require.Equal(t, res.Header, header)
require.Equal(t, res.Tier, encoding.TierGuardianID)
require.Equal(t, res.Tier, encoding.TierGuardianMajorityID)
require.NotEmpty(t, res.Proof)
require.Equal(t, res.Proof, crypto.Keccak256([]byte("RETURN_LIVENESS_BOND")))
}
2 changes: 1 addition & 1 deletion prover/proof_submitter/proof_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (s *ProofSubmitter) SubmitProof(
Tier: proofWithHeader.Tier,
Data: proofWithHeader.Proof,
},
proofWithHeader.Tier == encoding.TierGuardianID,
proofWithHeader.Tier == encoding.TierGuardianMajorityID,
),
); err != nil {
if err.Error() == transaction.ErrUnretryableSubmission.Error() {
Expand Down
2 changes: 1 addition & 1 deletion prover/proof_submitter/proof_submitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (s *ProofSubmitterTestSuite) TestGuardianSubmitProofs() {
for _, e := range events {
s.Nil(s.submitter.RequestProof(context.Background(), e))
proofWithHeader := <-s.proofCh
proofWithHeader.Tier = encoding.TierGuardianID
proofWithHeader.Tier = encoding.TierGuardianMajorityID
s.Nil(s.submitter.SubmitProof(context.Background(), proofWithHeader))
}
}
Expand Down
8 changes: 4 additions & 4 deletions prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func InitFromConfig(ctx context.Context, p *Prover, cfg *Config) (err error) {
TaikoL1Address: cfg.TaikoL1Address,
TaikoL2Address: cfg.TaikoL2Address,
TaikoTokenAddress: cfg.TaikoTokenAddress,
GuardianProverAddress: cfg.GuardianProverAddress,
GuardianProverAddress: cfg.GuardianProverMajorityAddress,
Timeout: cfg.RPCTimeout,
}); err != nil {
return err
Expand Down Expand Up @@ -143,7 +143,7 @@ func InitFromConfig(ctx context.Context, p *Prover, cfg *Config) (err error) {
}
p.sharedState.SetTiers(tiers)

txBuilder := transaction.NewProveBlockTxBuilder(p.rpc, p.cfg.TaikoL1Address, p.cfg.GuardianProverAddress)
txBuilder := transaction.NewProveBlockTxBuilder(p.rpc, p.cfg.TaikoL1Address, p.cfg.GuardianProverMajorityAddress)

if p.txmgr, err = txmgr.NewSimpleTxManager(
"prover",
Expand Down Expand Up @@ -375,7 +375,7 @@ func (p *Prover) contestProofOp(req *proofProducer.ContestRequestBody) error {
// requestProofOp requests a new proof generation operation.
func (p *Prover) requestProofOp(e *bindings.TaikoL1ClientBlockProposed, minTier uint16) error {
if p.IsGuardianProver() {
minTier = encoding.TierGuardianID
minTier = encoding.TierGuardianMajorityID
}
if submitter := p.selectSubmitter(minTier); submitter != nil {
if err := submitter.RequestProof(p.ctx, e); err != nil {
Expand Down Expand Up @@ -453,7 +453,7 @@ func (p *Prover) getSubmitterByTier(tier uint16) proofSubmitter.Submitter {

// IsGuardianProver returns true if the current prover is a guardian prover.
func (p *Prover) IsGuardianProver() bool {
return p.cfg.GuardianProverAddress != common.Address{}
return p.cfg.GuardianProverMajorityAddress != common.Address{}
}

// ProverAddress returns the current prover account address.
Expand Down
22 changes: 11 additions & 11 deletions prover/prover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,14 @@ func (s *ProverTestSuite) TestContestWrongBlocks() {

s.Nil(s.p.transitionContestedHandler.Handle(context.Background(), contestedEvent))

s.p.cfg.GuardianProverAddress = common.HexToAddress(os.Getenv("GUARDIAN_PROVER_CONTRACT_ADDRESS"))
s.p.cfg.GuardianProverMajorityAddress = common.HexToAddress(os.Getenv("GUARDIAN_PROVER_CONTRACT_ADDRESS"))
s.True(s.p.IsGuardianProver())

txBuilder := transaction.NewProveBlockTxBuilder(s.p.rpc, s.p.cfg.TaikoL1Address, s.p.cfg.GuardianProverAddress)
txBuilder := transaction.NewProveBlockTxBuilder(s.p.rpc, s.p.cfg.TaikoL1Address, s.p.cfg.GuardianProverMajorityAddress)
s.p.proofSubmitters = nil
s.Nil(s.p.initProofSubmitters(s.p.txmgr, txBuilder))

s.p.rpc.GuardianProver, err = bindings.NewGuardianProver(s.p.cfg.GuardianProverAddress, s.p.rpc.L1)
s.p.rpc.GuardianProver, err = bindings.NewGuardianProver(s.p.cfg.GuardianProverMajorityAddress, s.p.rpc.L1)
s.Nil(err)

approvedSink := make(chan *bindings.GuardianProverGuardianApproval)
Expand All @@ -319,7 +319,7 @@ func (s *ProverTestSuite) TestContestWrongBlocks() {
}()
req = <-s.p.proofSubmissionCh
s.Nil(s.p.requestProofOp(req.Event, req.Tier))
s.Nil(s.p.selectSubmitter(encoding.TierGuardianID).SubmitProof(context.Background(), <-s.p.proofGenerationCh))
s.Nil(s.p.selectSubmitter(encoding.TierGuardianMajorityID).SubmitProof(context.Background(), <-s.p.proofGenerationCh))
approvedEvent := <-approvedSink

s.Equal(header.Number.Uint64(), approvedEvent.BlockId.Uint64())
Expand All @@ -340,7 +340,7 @@ func (s *ProverTestSuite) TestProveExpiredUnassignedBlock() {
}()

e.AssignedProver = common.BytesToAddress(testutils.RandomHash().Bytes())
s.p.cfg.GuardianProverAddress = common.Address{}
s.p.cfg.GuardianProverMajorityAddress = common.Address{}
s.Nil(s.p.assignmentExpiredHandler.Handle(context.Background(), e))
req := <-s.p.proofSubmissionCh
s.Nil(s.p.requestProofOp(req.Event, req.Tier))
Expand All @@ -353,21 +353,21 @@ func (s *ProverTestSuite) TestProveExpiredUnassignedBlock() {
}

func (s *ProverTestSuite) TestSelectSubmitter() {
submitter := s.p.selectSubmitter(encoding.TierGuardianID - 1)
submitter := s.p.selectSubmitter(encoding.TierGuardianMajorityID - 1)
s.NotNil(submitter)
s.Equal(encoding.TierGuardianID, submitter.Tier())
s.Equal(encoding.TierGuardianMajorityID, submitter.Tier())
}

func (s *ProverTestSuite) TestSelectSubmitterNotFound() {
submitter := s.p.selectSubmitter(encoding.TierGuardianID + 1)
submitter := s.p.selectSubmitter(encoding.TierGuardianMajorityID + 1)
s.Nil(submitter)
}

func (s *ProverTestSuite) TestGetSubmitterByTier() {
submitter := s.p.getSubmitterByTier(encoding.TierGuardianID)
submitter := s.p.getSubmitterByTier(encoding.TierGuardianMajorityID)
s.NotNil(submitter)
s.Equal(encoding.TierGuardianID, submitter.Tier())
s.Nil(s.p.getSubmitterByTier(encoding.TierGuardianID + 1))
s.Equal(encoding.TierGuardianMajorityID, submitter.Tier())
s.Nil(s.p.getSubmitterByTier(encoding.TierGuardianMajorityID + 1))
}

func (s *ProverTestSuite) TestProveOp() {
Expand Down
2 changes: 1 addition & 1 deletion prover/server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (s *ProverServer) CreateAssignment(c echo.Context) error {

// 4. Check if the proof fee meets prover's minimum requirement for each tier.
for _, tier := range req.TierFees {
if tier.Tier == encoding.TierGuardianID {
if tier.Tier == encoding.TierGuardianMajorityID {
continue
}

Expand Down

0 comments on commit 9b12c2f

Please sign in to comment.