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

feat(prover): add flag for guardian prover #530

Merged
merged 14 commits into from
Jan 29, 2024
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
19 changes: 17 additions & 2 deletions prover/proof_producer/guardian_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ 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 {
LivenessBond bool
RogerLamTd marked this conversation as resolved.
Show resolved Hide resolved
*DummyProofProducer
}

// 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 +34,18 @@ func (g *GuardianProofProducer) RequestProof(
"hash", header.Hash(),
)

if g.LivenessBond {
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
39 changes: 39 additions & 0 deletions 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 Down Expand Up @@ -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 = &GuardianProofProducer{LivenessBond: 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")))
}
5 changes: 4 additions & 1 deletion prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ 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.GuardianProofProducer{
LivenessBond: p.cfg.EnableLivenessBondProof,
DummyProofProducer: new(proofProducer.DummyProofProducer),
}
}

if submitter, err = proofSubmitter.New(
Expand Down
Loading