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

Commit

Permalink
fix following comments
Browse files Browse the repository at this point in the history
  • Loading branch information
YoGhurt111 committed May 7, 2024
1 parent b774099 commit 24fa834
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 180 deletions.
16 changes: 8 additions & 8 deletions pkg/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -113,21 +113,21 @@ 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 {
return nil, err
}
}
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
}
}
Expand All @@ -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 {
Expand Down
5 changes: 0 additions & 5 deletions prover/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions prover/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down
65 changes: 8 additions & 57 deletions prover/proof_producer/guardian_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand All @@ -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
}

Expand All @@ -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
}
79 changes: 77 additions & 2 deletions prover/proof_producer/guardian_producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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")))
}
91 changes: 0 additions & 91 deletions prover/proof_producer/minority_guardian_producer_test.go

This file was deleted.

Loading

0 comments on commit 24fa834

Please sign in to comment.