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

Commit

Permalink
feat(prover): add --prover.enableLivenessBondProof flag for guardia…
Browse files Browse the repository at this point in the history
…n prover (#530)

Co-authored-by: David <[email protected]>
  • Loading branch information
RogerLamTd and davidtaikocha committed Jan 29, 2024
1 parent 7a0bd8a commit 9fa5ab6
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 4 deletions.
7 changes: 7 additions & 0 deletions cmd/flags/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions prover/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Config struct {
BackOffRetryInterval time.Duration
ProveUnassignedBlocks bool
ContesterMode bool
EnableLivenessBondProof bool
RPCTimeout time.Duration
WaitReceiptTimeout time.Duration
ProveBlockGasLimit *uint64
Expand Down Expand Up @@ -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,
Expand Down
31 changes: 29 additions & 2 deletions prover/proof_producer/guardian_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,32 @@ 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"
"github.com/taikoxyz/taiko-client/bindings/encoding"
)

// 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,
Expand All @@ -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())
}

Expand Down
41 changes: 40 additions & 1 deletion prover/proof_producer/guardian_producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -32,7 +33,7 @@ func TestGuardianProducerRequestProof(t *testing.T) {
}

var (
producer = &GuardianProofProducer{}
producer = NewGuardianProofProducer(false)
blockID = common.Big32
)
res, err := producer.RequestProof(
Expand All @@ -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")))
}
2 changes: 1 addition & 1 deletion prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 9fa5ab6

Please sign in to comment.