From 9fa5ab6174efce6ee747281a9a37c5afe2856640 Mon Sep 17 00:00:00 2001 From: Roger <50648015+RogerLamTd@users.noreply.github.com> Date: Mon, 29 Jan 2024 15:42:38 -0800 Subject: [PATCH] feat(prover): add `--prover.enableLivenessBondProof` flag for guardian prover (#530) Co-authored-by: David --- cmd/flags/prover.go | 7 ++++ prover/config.go | 2 + prover/proof_producer/guardian_producer.go | 31 +++++++++++++- .../proof_producer/guardian_producer_test.go | 41 ++++++++++++++++++- prover/prover.go | 2 +- 5 files changed, 79 insertions(+), 4 deletions(-) diff --git a/cmd/flags/prover.go b/cmd/flags/prover.go index 8e34fde8a..aadf1b43d 100644 --- a/cmd/flags/prover.go +++ b/cmd/flags/prover.go @@ -183,6 +183,13 @@ var ( Usage: "HTTP endpoint for main guardian prover health check server", Category: proverCategory, } + // Guardian prover specific flag + EnableLivenessBondProof = &cli.BoolFlag{ + Name: "prover.enableLivenessBondProof", + Usage: "Toggles whether the proof is a dummy proof or returns keccak256(RETURN_LIVENESS_BOND) as proof", + Value: false, + Category: proverCategory, + } ) // ProverFlags All prover flags. diff --git a/prover/config.go b/prover/config.go index 828ffaefa..f0917f6e6 100644 --- a/prover/config.go +++ b/prover/config.go @@ -37,6 +37,7 @@ type Config struct { BackOffRetryInterval time.Duration ProveUnassignedBlocks bool ContesterMode bool + EnableLivenessBondProof bool RPCTimeout time.Duration WaitReceiptTimeout time.Duration ProveBlockGasLimit *uint64 @@ -146,6 +147,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { BackOffRetryInterval: c.Duration(flags.BackOffRetryInterval.Name), ProveUnassignedBlocks: c.Bool(flags.ProveUnassignedBlocks.Name), ContesterMode: c.Bool(flags.ContesterMode.Name), + EnableLivenessBondProof: c.Bool(flags.EnableLivenessBondProof.Name), RPCTimeout: c.Duration(flags.RPCTimeout.Name), WaitReceiptTimeout: c.Duration(flags.WaitReceiptTimeout.Name), ProveBlockGasLimit: proveBlockTxGasLimit, diff --git a/prover/proof_producer/guardian_producer.go b/prover/proof_producer/guardian_producer.go index bd90cbd57..3beb87ec9 100644 --- a/prover/proof_producer/guardian_producer.go +++ b/prover/proof_producer/guardian_producer.go @@ -5,6 +5,7 @@ import ( "math/big" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/log" "github.com/taikoxyz/taiko-client/bindings" @@ -12,10 +13,24 @@ import ( ) // GuardianProofProducer always returns an optimistic (dummy) proof. -type GuardianProofProducer struct{ *DummyProofProducer } +type GuardianProofProducer struct { + returnLivenessBond bool + *DummyProofProducer +} + +func NewGuardianProofProducer(returnLivenessBond bool) *GuardianProofProducer { + gp := &GuardianProofProducer{ + returnLivenessBond: returnLivenessBond, + } + + if !returnLivenessBond { + gp.DummyProofProducer = new(DummyProofProducer) + } + + return gp +} // RequestProof implements the ProofProducer interface. -// TODO: support returning `keccak256("RETURN_LIVENESS_BOND")` as proof. func (g *GuardianProofProducer) RequestProof( ctx context.Context, opts *ProofRequestOptions, @@ -31,6 +46,18 @@ func (g *GuardianProofProducer) RequestProof( "hash", header.Hash(), ) + if g.returnLivenessBond { + return &ProofWithHeader{ + BlockID: blockID, + Meta: meta, + Header: header, + Proof: crypto.Keccak256([]byte("RETURN_LIVENESS_BOND")), + Degree: CircuitsIdx, + Opts: opts, + Tier: g.Tier(), + }, nil + } + return g.DummyProofProducer.RequestProof(ctx, opts, blockID, meta, header, g.Tier()) } diff --git a/prover/proof_producer/guardian_producer_test.go b/prover/proof_producer/guardian_producer_test.go index 0bcd24c13..a6e6b6d86 100644 --- a/prover/proof_producer/guardian_producer_test.go +++ b/prover/proof_producer/guardian_producer_test.go @@ -7,6 +7,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" "github.com/stretchr/testify/require" "github.com/taikoxyz/taiko-client/bindings" @@ -32,7 +33,7 @@ func TestGuardianProducerRequestProof(t *testing.T) { } var ( - producer = &GuardianProofProducer{} + producer = NewGuardianProofProducer(false) blockID = common.Big32 ) res, err := producer.RequestProof( @@ -49,3 +50,41 @@ func TestGuardianProducerRequestProof(t *testing.T) { require.Equal(t, res.Tier, encoding.TierGuardianID) require.NotEmpty(t, res.Proof) } + +func TestGuardianProducerRequestProofReturnLivenessBond(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(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.TierGuardianID) + require.NotEmpty(t, res.Proof) + require.Equal(t, res.Proof, crypto.Keccak256([]byte("RETURN_LIVENESS_BOND"))) +} diff --git a/prover/prover.go b/prover/prover.go index a9f1bb467..8f284d2af 100644 --- a/prover/prover.go +++ b/prover/prover.go @@ -218,7 +218,7 @@ func InitFromConfig(ctx context.Context, p *Prover, cfg *Config) (err error) { } producer = zkEvmRpcdProducer case encoding.TierGuardianID: - producer = &proofProducer.GuardianProofProducer{DummyProofProducer: new(proofProducer.DummyProofProducer)} + producer = proofProducer.NewGuardianProofProducer(p.cfg.EnableLivenessBondProof) } if submitter, err = proofSubmitter.New(