diff --git a/pkg/rpc/client.go b/pkg/rpc/client.go index af51baa16..d91d26f29 100644 --- a/pkg/rpc/client.go +++ b/pkg/rpc/client.go @@ -30,8 +30,8 @@ type Client struct { TaikoL1 *bindings.TaikoL1Client TaikoL2 *bindings.TaikoL2Client TaikoToken *bindings.TaikoToken - MajorityGuardianProver *bindings.GuardianProver - MinorityGuardianProver *bindings.GuardianProver + GuardianProverMajority *bindings.GuardianProver + GuardianProverMinority *bindings.GuardianProver } // ClientConfig contains all configs which will be used to initializing an @@ -113,8 +113,8 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) { var ( taikoToken *bindings.TaikoToken - majorityGuardianProver *bindings.GuardianProver - minorityGuardianProver *bindings.GuardianProver + guardianProverMajority *bindings.GuardianProver + guardianProverMinority *bindings.GuardianProver ) if cfg.TaikoTokenAddress.Hex() != ZeroAddress.Hex() { if taikoToken, err = bindings.NewTaikoToken(cfg.TaikoTokenAddress, l1Client); err != nil { @@ -122,12 +122,12 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) { } } if cfg.GuardianProverMinorityAddress.Hex() != ZeroAddress.Hex() { - if minorityGuardianProver, err = bindings.NewGuardianProver(cfg.GuardianProverMinorityAddress, l1Client); err != nil { + if guardianProverMinority, err = bindings.NewGuardianProver(cfg.GuardianProverMinorityAddress, l1Client); err != nil { return nil, err } } if cfg.GuardianProverMajorityAddress.Hex() != ZeroAddress.Hex() { - if majorityGuardianProver, err = bindings.NewGuardianProver(cfg.GuardianProverMajorityAddress, l1Client); err != nil { + if guardianProverMajority, err = bindings.NewGuardianProver(cfg.GuardianProverMajorityAddress, l1Client); err != nil { return nil, err } } @@ -151,8 +151,8 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) { TaikoL1: taikoL1, TaikoL2: taikoL2, TaikoToken: taikoToken, - MajorityGuardianProver: majorityGuardianProver, - MinorityGuardianProver: minorityGuardianProver, + GuardianProverMajority: guardianProverMajority, + GuardianProverMinority: guardianProverMinority, } if err := client.ensureGenesisMatched(ctxWithTimeout); err != nil { diff --git a/prover/config.go b/prover/config.go index 6f30d6e68..992779383 100644 --- a/prover/config.go +++ b/prover/config.go @@ -117,11 +117,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { if !c.IsSet(flags.L2NodeVersion.Name) { return nil, errors.New("--prover.l2NodeVersion flag is required if guardian prover is set") } - - // If we are running a guardian prover, a raiko host endpoint is required. - if !c.IsSet(flags.RaikoHostEndpoint.Name) { - return nil, errors.New("raiko host not provided") - } } var ( raikoL1Endpoint = c.String(flags.RaikoL1Endpoint.Name) diff --git a/prover/init.go b/prover/init.go index 354ddfaa9..02b724ca4 100644 --- a/prover/init.go +++ b/prover/init.go @@ -114,14 +114,14 @@ func (p *Prover) initProofSubmitters( Dummy: p.cfg.Dummy, } case encoding.TierGuardianMinorityID: - producer = proofProducer.NewMinorityGuardianProofProducer(&proofProducer.SGXProofProducer{ + 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, @@ -130,7 +130,7 @@ func (p *Prover) initProofSubmitters( L2Endpoint: p.cfg.RaikoL2Endpoint, ProofType: proofProducer.ProofTypeCPU, Dummy: p.cfg.Dummy, - }, p.cfg.EnableLivenessBondProof) + }, encoding.TierGuardianMajorityID, p.cfg.EnableLivenessBondProof) default: return fmt.Errorf("unsupported tier: %d", tier.ID) } diff --git a/prover/proof_producer/guardian_producer.go b/prover/proof_producer/guardian_producer.go index 5ac243681..a6b196713 100644 --- a/prover/proof_producer/guardian_producer.go +++ b/prover/proof_producer/guardian_producer.go @@ -9,35 +9,24 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/taikoxyz/taiko-client/bindings" - "github.com/taikoxyz/taiko-client/bindings/encoding" ) // GuardianProofProducer always returns an optimistic (dummy) proof. type GuardianProofProducer struct { returnLivenessBond bool + tier uint16 *SGXProofProducer } -// MinorityGuardianProofProducer always returns an optimistic (dummy) proof. -type MinorityGuardianProofProducer struct { - returnLivenessBond bool - *SGXProofProducer -} - -func NewGuardianProofProducer(sgxProofProducer *SGXProofProducer, returnLivenessBond bool) *GuardianProofProducer { - return &GuardianProofProducer{ - SGXProofProducer: sgxProofProducer, - returnLivenessBond: returnLivenessBond, - } -} - -func NewMinorityGuardianProofProducer( +func NewGuardianProofProducer( sgxProofProducer *SGXProofProducer, + tier uint16, returnLivenessBond bool, -) *MinorityGuardianProofProducer { - return &MinorityGuardianProofProducer{ +) *GuardianProofProducer { + return &GuardianProofProducer{ SGXProofProducer: sgxProofProducer, returnLivenessBond: returnLivenessBond, + tier: tier, } } @@ -64,7 +53,7 @@ func (g *GuardianProofProducer) RequestProof( Header: header, Proof: crypto.Keccak256([]byte("RETURN_LIVENESS_BOND")), Opts: opts, - Tier: g.Tier(), + Tier: g.tier, }, nil } @@ -78,45 +67,7 @@ func (g *GuardianProofProducer) RequestProof( return g.DummyProofProducer.RequestProof(opts, blockID, meta, header, g.Tier()) } -func (m *MinorityGuardianProofProducer) RequestProof( - ctx context.Context, - opts *ProofRequestOptions, - blockID *big.Int, - meta *bindings.TaikoDataBlockMetadata, - header *types.Header, -) (*ProofWithHeader, error) { - log.Info( - "Request guardian proof", - "blockID", blockID, - "coinbase", meta.Coinbase, - "height", header.Number, - "hash", header.Hash(), - ) - - if m.returnLivenessBond { - return &ProofWithHeader{ - BlockID: blockID, - Meta: meta, - Header: header, - Proof: crypto.Keccak256([]byte("RETURN_LIVENESS_BOND")), - Opts: opts, - Tier: m.Tier(), - }, nil - } - - if _, err := m.SGXProofProducer.RequestProof(ctx, opts, blockID, meta, header); err != nil { - return nil, err - } - - return m.DummyProofProducer.RequestProof(opts, blockID, meta, header, m.Tier()) -} - // Tier implements the ProofProducer interface. func (g *GuardianProofProducer) Tier() uint16 { - return encoding.TierGuardianMajorityID -} - -// Tier returns TierGuardianMinorityID -func (m *MinorityGuardianProofProducer) Tier() uint16 { - return encoding.TierGuardianMinorityID + return g.tier } diff --git a/prover/proof_producer/guardian_producer_test.go b/prover/proof_producer/guardian_producer_test.go index d012d0565..7f295b8dc 100644 --- a/prover/proof_producer/guardian_producer_test.go +++ b/prover/proof_producer/guardian_producer_test.go @@ -33,7 +33,7 @@ func TestGuardianProducerRequestProof(t *testing.T) { } var ( - producer = NewGuardianProofProducer(&SGXProofProducer{Dummy: true}, false) + producer = NewGuardianProofProducer(&SGXProofProducer{Dummy: true}, encoding.TierGuardianMajorityID, false) blockID = common.Big32 ) res, err := producer.RequestProof( @@ -70,7 +70,7 @@ func TestGuardianProducerRequestProofReturnLivenessBond(t *testing.T) { } var ( - producer = NewGuardianProofProducer(&SGXProofProducer{Dummy: true}, true) + producer = NewGuardianProofProducer(&SGXProofProducer{Dummy: true}, encoding.TierGuardianMajorityID, true) blockID = common.Big32 ) res, err := producer.RequestProof( @@ -88,3 +88,78 @@ func TestGuardianProducerRequestProofReturnLivenessBond(t *testing.T) { require.NotEmpty(t, res.Proof) require.Equal(t, res.Proof, crypto.Keccak256([]byte("RETURN_LIVENESS_BOND"))) } + +func TestMinorityRequestProof(t *testing.T) { + header := &types.Header{ + ParentHash: randHash(), + UncleHash: randHash(), + Coinbase: common.BytesToAddress(randHash().Bytes()), + Root: randHash(), + TxHash: randHash(), + ReceiptHash: randHash(), + Difficulty: common.Big0, + Number: common.Big256, + GasLimit: 1024, + GasUsed: 1024, + Time: uint64(time.Now().Unix()), + Extra: randHash().Bytes(), + MixDigest: randHash(), + Nonce: types.BlockNonce{}, + } + + var ( + producer = NewGuardianProofProducer(&SGXProofProducer{Dummy: true}, encoding.TierGuardianMinorityID, false) + blockID = common.Big32 + ) + res, err := producer.RequestProof( + context.Background(), + &ProofRequestOptions{}, + blockID, + &bindings.TaikoDataBlockMetadata{}, + header, + ) + require.Nil(t, err) + + require.Equal(t, res.BlockID, blockID) + require.Equal(t, res.Header, header) + require.Equal(t, res.Tier, encoding.TierGuardianMinorityID) + require.NotEmpty(t, res.Proof) +} + +func TestRequestMinorityProofReturnLivenessBond(t *testing.T) { + header := &types.Header{ + ParentHash: randHash(), + UncleHash: randHash(), + Coinbase: common.BytesToAddress(randHash().Bytes()), + Root: randHash(), + TxHash: randHash(), + ReceiptHash: randHash(), + Difficulty: common.Big0, + Number: common.Big256, + GasLimit: 1024, + GasUsed: 1024, + Time: uint64(time.Now().Unix()), + Extra: randHash().Bytes(), + MixDigest: randHash(), + Nonce: types.BlockNonce{}, + } + + var ( + producer = NewGuardianProofProducer(&SGXProofProducer{Dummy: true}, encoding.TierGuardianMinorityID, true) + blockID = common.Big32 + ) + res, err := producer.RequestProof( + context.Background(), + &ProofRequestOptions{}, + blockID, + &bindings.TaikoDataBlockMetadata{}, + header, + ) + require.Nil(t, err) + + require.Equal(t, res.BlockID, blockID) + require.Equal(t, res.Header, header) + require.Equal(t, res.Tier, encoding.TierGuardianMinorityID) + require.NotEmpty(t, res.Proof) + require.Equal(t, res.Proof, crypto.Keccak256([]byte("RETURN_LIVENESS_BOND"))) +} diff --git a/prover/proof_producer/minority_guardian_producer_test.go b/prover/proof_producer/minority_guardian_producer_test.go deleted file mode 100644 index 9d506b708..000000000 --- a/prover/proof_producer/minority_guardian_producer_test.go +++ /dev/null @@ -1,91 +0,0 @@ -package producer - -import ( - "context" - "testing" - "time" - - "github.com/ethereum/go-ethereum/crypto" - - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" - "github.com/stretchr/testify/require" - - "github.com/taikoxyz/taiko-client/bindings" - "github.com/taikoxyz/taiko-client/bindings/encoding" -) - -func TestRequestProof(t *testing.T) { - header := &types.Header{ - ParentHash: randHash(), - UncleHash: randHash(), - Coinbase: common.BytesToAddress(randHash().Bytes()), - Root: randHash(), - TxHash: randHash(), - ReceiptHash: randHash(), - Difficulty: common.Big0, - Number: common.Big256, - GasLimit: 1024, - GasUsed: 1024, - Time: uint64(time.Now().Unix()), - Extra: randHash().Bytes(), - MixDigest: randHash(), - Nonce: types.BlockNonce{}, - } - - var ( - producer = NewMinorityGuardianProofProducer(&SGXProofProducer{Dummy: true}, false) - blockID = common.Big32 - ) - res, err := producer.RequestProof( - context.Background(), - &ProofRequestOptions{}, - blockID, - &bindings.TaikoDataBlockMetadata{}, - header, - ) - require.Nil(t, err) - - require.Equal(t, res.BlockID, blockID) - require.Equal(t, res.Header, header) - require.Equal(t, res.Tier, encoding.TierGuardianMinorityID) - require.NotEmpty(t, res.Proof) -} - -func TestRequestProofReturnLivenessBond(t *testing.T) { - header := &types.Header{ - ParentHash: randHash(), - UncleHash: randHash(), - Coinbase: common.BytesToAddress(randHash().Bytes()), - Root: randHash(), - TxHash: randHash(), - ReceiptHash: randHash(), - Difficulty: common.Big0, - Number: common.Big256, - GasLimit: 1024, - GasUsed: 1024, - Time: uint64(time.Now().Unix()), - Extra: randHash().Bytes(), - MixDigest: randHash(), - Nonce: types.BlockNonce{}, - } - - var ( - producer = NewMinorityGuardianProofProducer(&SGXProofProducer{Dummy: true}, true) - blockID = common.Big32 - ) - res, err := producer.RequestProof( - context.Background(), - &ProofRequestOptions{}, - blockID, - &bindings.TaikoDataBlockMetadata{}, - header, - ) - require.Nil(t, err) - - require.Equal(t, res.BlockID, blockID) - require.Equal(t, res.Header, header) - require.Equal(t, res.Tier, encoding.TierGuardianMinorityID) - require.NotEmpty(t, res.Proof) - require.Equal(t, res.Proof, crypto.Keccak256([]byte("RETURN_LIVENESS_BOND"))) -} diff --git a/prover/proof_submitter/transaction/builder.go b/prover/proof_submitter/transaction/builder.go index 0a069f97c..7614055aa 100644 --- a/prover/proof_submitter/transaction/builder.go +++ b/prover/proof_submitter/transaction/builder.go @@ -27,18 +27,18 @@ type TxBuilder func(txOpts *bind.TransactOpts) (*txmgr.TxCandidate, error) type ProveBlockTxBuilder struct { rpc *rpc.Client taikoL1Address common.Address - majorityGuardianProverAddress common.Address - minorityGuardianProverAddress common.Address + guardianProverMajorityAddress common.Address + guardianProverMinorityAddress common.Address } // NewProveBlockTxBuilder creates a new ProveBlockTxBuilder instance. func NewProveBlockTxBuilder( rpc *rpc.Client, taikoL1Address common.Address, - majorityGuardianProverAddress common.Address, - minorityGuardianProverAddress common.Address, + guardianProverMajorityAddress common.Address, + guardianProverMinorityAddress common.Address, ) *ProveBlockTxBuilder { - return &ProveBlockTxBuilder{rpc, taikoL1Address, majorityGuardianProverAddress, minorityGuardianProverAddress} + return &ProveBlockTxBuilder{rpc, taikoL1Address, guardianProverMajorityAddress, guardianProverMinorityAddress} } // Build creates a new TaikoL1.ProveBlock transaction with the given nonce. @@ -79,11 +79,11 @@ func (a *ProveBlockTxBuilder) Build( } } else { if tier > encoding.TierGuardianMinorityID { - to = a.majorityGuardianProverAddress - } else if tier == encoding.TierGuardianMinorityID && a.minorityGuardianProverAddress != ZeroAddress { - to = a.minorityGuardianProverAddress + to = a.guardianProverMajorityAddress + } else if tier == encoding.TierGuardianMinorityID && a.guardianProverMinorityAddress != ZeroAddress { + to = a.guardianProverMinorityAddress } else { - return nil, fmt.Errorf("tier %d need set minorityGuardianProverAddress", tier) + return nil, fmt.Errorf("tier %d need set guardianProverMinorityAddress", tier) } if data, err = encoding.GuardianProverABI.Pack("approve", *meta, *transition, *tierProof); err != nil { if isSubmitProofTxErrorRetryable(err, blockID) { diff --git a/prover/prover.go b/prover/prover.go index e9797713c..6647e4676 100644 --- a/prover/prover.go +++ b/prover/prover.go @@ -195,12 +195,12 @@ func InitFromConfig(ctx context.Context, p *Prover, cfg *Config) (err error) { // Guardian prover heartbeat sender if p.IsGuardianProver() && p.cfg.GuardianProverHealthCheckServerEndpoint != nil { // Check guardian prover contract address is correct. - if _, err := p.rpc.MajorityGuardianProver.MinGuardians(&bind.CallOpts{Context: ctx}); err != nil { + if _, err := p.rpc.GuardianProverMajority.MinGuardians(&bind.CallOpts{Context: ctx}); err != nil { return fmt.Errorf("failed to get MinGuardians from majority guardian prover contract: %w", err) } - if p.rpc.MinorityGuardianProver != nil { - if _, err := p.rpc.MinorityGuardianProver.MinGuardians(&bind.CallOpts{Context: ctx}); err != nil { + if p.rpc.GuardianProverMinority != nil { + if _, err := p.rpc.GuardianProverMinority.MinGuardians(&bind.CallOpts{Context: ctx}); err != nil { return fmt.Errorf("failed to get MinGuardians from minority guardian prover contract: %w", err) } } diff --git a/prover/prover_test.go b/prover/prover_test.go index 3d7e15e1c..3127c3af1 100644 --- a/prover/prover_test.go +++ b/prover/prover_test.go @@ -310,11 +310,11 @@ func (s *ProverTestSuite) TestContestWrongBlocks() { s.p.proofSubmitters = nil s.Nil(s.p.initProofSubmitters(s.p.txmgr, txBuilder)) - s.p.rpc.MajorityGuardianProver, err = bindings.NewGuardianProver(s.p.cfg.GuardianProverMajorityAddress, s.p.rpc.L1) + s.p.rpc.GuardianProverMajority, err = bindings.NewGuardianProver(s.p.cfg.GuardianProverMajorityAddress, s.p.rpc.L1) s.Nil(err) approvedSink := make(chan *bindings.GuardianProverGuardianApproval) - approvedSub, err := s.p.rpc.MajorityGuardianProver.WatchGuardianApproval( + approvedSub, err := s.p.rpc.GuardianProverMajority.WatchGuardianApproval( nil, approvedSink, []common.Address{}, [](*big.Int){}, []([32]byte){}, ) s.Nil(err)