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

Commit

Permalink
feat(bindings): updates related to TaikoToken && guardian prover chan…
Browse files Browse the repository at this point in the history
…ges (#436)
  • Loading branch information
davidtaikocha authored Oct 24, 2023
1 parent 57410f6 commit 9066722
Show file tree
Hide file tree
Showing 17 changed files with 1,684 additions and 93 deletions.
2 changes: 1 addition & 1 deletion bindings/.githead
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2cc9863870b35939117135e6100e7f3b241d3310
8ba512b54c2102b93907d12cc108c4c3b02602f0
1,475 changes: 1,475 additions & 0 deletions bindings/gen_guardian_prover.go

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions bindings/gen_taiko_token.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions cmd/flags/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ var (
Category: proverCategory,
}
// Guardian prover related.
GuardianProver = &cli.BoolFlag{
Name: "guardian",
Usage: "Set whether prover should use guardian prover or not",
GuardianProver = &cli.StringFlag{
Name: "guardianProver",
Usage: "GuardianProver contract `address`",
Category: proverCategory,
}
GuardianProverPrivateKey = &cli.StringFlag{
Expand Down
6 changes: 3 additions & 3 deletions integration_test/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ if ! docker info >/dev/null 2>&1; then
fi

TESTNET_CONFIG=$DIR/nodes/docker-compose.yml
PREMINT_TOKEN_AMOUNT=92233720368547758070000000000000

TESTNET_CONFIG=$TESTNET_CONFIG \
TAIKO_MONO_DIR=$TAIKO_MONO_DIR \
PREMINT_TOKEN_AMOUNT=$PREMINT_TOKEN_AMOUNT \
$DIR/nodes/init.sh

DEPLOYMENT_JSON=$(cat $TAIKO_MONO_DIR/packages/protocol/deployments/deploy_l1.json)
TAIKO_L1_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.taiko' | sed 's/\"//g')
L1_SIGNAL_SERVICE_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.signal_service' | sed 's/\"//g')
TAIKO_TOKEN_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.taiko_token' | sed 's/\"//g')
ADDRESS_MANAGER_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.address_manager' | sed 's/\"//g')
GUARDIAN_PROVER_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.guardian' | sed 's/\"//g')

trap "docker compose -f $TESTNET_CONFIG down -v" EXIT INT KILL ERR

Expand All @@ -39,6 +38,7 @@ PACKAGE=${PACKAGE:-...}
echo "TAIKO_L1_CONTRACT_ADDRESS: $TAIKO_L1_CONTRACT_ADDRESS"
echo "TAIKO_TOKEN_CONTRACT_ADDRESS: $TAIKO_TOKEN_CONTRACT_ADDRESS"
echo "L1_SIGNAL_SERVICE_CONTRACT_ADDRESS: $L1_SIGNAL_SERVICE_CONTRACT_ADDRESS"
echo "GUARDIAN_PROVER_CONTRACT_ADDRESS: $GUARDIAN_PROVER_CONTRACT_ADDRESS"

if [ "$RUN_TESTS" == "true" ]; then
L1_NODE_HTTP_ENDPOINT=http://localhost:18545 \
Expand All @@ -50,13 +50,13 @@ if [ "$RUN_TESTS" == "true" ]; then
TAIKO_L2_ADDRESS=0x1000777700000000000000000000000000000001 \
TAIKO_TOKEN_ADDRESS=$TAIKO_TOKEN_CONTRACT_ADDRESS \
ADDRESS_MANAGER_CONTRACT_ADDRESS=$ADDRESS_MANAGER_CONTRACT_ADDRESS \
GUARDIAN_PROVER_CONTRACT_ADDRESS=$GUARDIAN_PROVER_CONTRACT_ADDRESS \
L1_SIGNAL_SERVICE_CONTRACT_ADDRESS=$L1_SIGNAL_SERVICE_CONTRACT_ADDRESS \
L1_CONTRACT_OWNER_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
L1_PROPOSER_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
L2_SUGGESTED_FEE_RECIPIENT=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
L1_PROVER_PRIVATE_KEY=59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d \
TREASURY=0xdf09A0afD09a63fb04ab3573922437e1e637dE8b \
PREMINT_TOKEN_AMOUNT=$PREMINT_TOKEN_AMOUNT \
JWT_SECRET=$DIR/nodes/jwt.hex \
go test -v -p=1 ./$PACKAGE -coverprofile=coverage.out -covermode=atomic -timeout=300s
else
Expand Down
3 changes: 1 addition & 2 deletions integration_test/nodes/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ cd $TAIKO_MONO_DIR/packages/protocol &&
L2_SIGNAL_SERVICE=0x1000777700000000000000000000000000000007 \
SHARED_SIGNAL_SERVICE=0x0000000000000000000000000000000000000000 \
PROPOSER=0x0000000000000000000000000000000000000000 \
TAIKO_TOKEN_PREMINT_RECIPIENTS="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266,0x70997970C51812dc3A010C7d01b50e0d17dc79C8" \
TAIKO_TOKEN_PREMINT_AMOUNTS=$PREMINT_TOKEN_AMOUNT,$PREMINT_TOKEN_AMOUNT \
TAIKO_TOKEN_PREMINT_RECIPIENT=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
TIER_PROVIDER=0x0 \
L2_GENESIS_HASH=$L2_GENESIS_HASH \
forge script script/DeployOnL1.s.sol:DeployOnL1 \
Expand Down
70 changes: 40 additions & 30 deletions pkg/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ type Client struct {
// Geth Engine API clients
L2Engine *EngineClient
// Protocol contracts clients
TaikoL1 *bindings.TaikoL1Client
TaikoL2 *bindings.TaikoL2Client
TaikoToken *bindings.TaikoToken
TaikoL1 *bindings.TaikoL1Client
TaikoL2 *bindings.TaikoL2Client
TaikoToken *bindings.TaikoToken
GuardianProver *bindings.GuardianProver
// Chain IDs
L1ChainID *big.Int
L2ChainID *big.Int
Expand All @@ -44,17 +45,18 @@ type Client struct {
// RPC client. If not providing L2EngineEndpoint or JwtSecret, then the L2Engine client
// won't be initialized.
type ClientConfig struct {
L1Endpoint string
L2Endpoint string
L2CheckPoint string
TaikoL1Address common.Address
TaikoL2Address common.Address
TaikoTokenAddress common.Address
L2EngineEndpoint string
JwtSecret string
RetryInterval time.Duration
Timeout *time.Duration
BackOffMaxRetrys *big.Int
L1Endpoint string
L2Endpoint string
L2CheckPoint string
TaikoL1Address common.Address
TaikoL2Address common.Address
TaikoTokenAddress common.Address
GuardianProverAddress common.Address
L2EngineEndpoint string
JwtSecret string
RetryInterval time.Duration
Timeout *time.Duration
BackOffMaxRetrys *big.Int
}

// NewClient initializes all RPC clients used by Taiko client software.
Expand Down Expand Up @@ -99,10 +101,17 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) {
return nil, err
}

var taikoToken *bindings.TaikoToken
var (
taikoToken *bindings.TaikoToken
guardianProver *bindings.GuardianProver
)
if cfg.TaikoTokenAddress.Hex() != ZeroAddress.Hex() {
taikoToken, err = bindings.NewTaikoToken(cfg.TaikoTokenAddress, l1RPC)
if err != nil {
if taikoToken, err = bindings.NewTaikoToken(cfg.TaikoTokenAddress, l1RPC); err != nil {
return nil, err
}
}
if cfg.GuardianProverAddress.Hex() != ZeroAddress.Hex() {
if guardianProver, err = bindings.NewGuardianProver(cfg.GuardianProverAddress, l1RPC); err != nil {
return nil, err
}
}
Expand Down Expand Up @@ -175,19 +184,20 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) {
}

client := &Client{
L1: l1RPC,
L2: l2RPC,
L2CheckPoint: l2CheckPoint,
L1RawRPC: l1RawRPC,
L2RawRPC: l2RawRPC,
L1GethClient: gethclient.New(l1RawRPC),
L2GethClient: gethclient.New(l2RawRPC),
L2Engine: l2AuthRPC,
TaikoL1: taikoL1,
TaikoL2: taikoL2,
TaikoToken: taikoToken,
L1ChainID: l1ChainID,
L2ChainID: l2ChainID,
L1: l1RPC,
L2: l2RPC,
L2CheckPoint: l2CheckPoint,
L1RawRPC: l1RawRPC,
L2RawRPC: l2RawRPC,
L1GethClient: gethclient.New(l1RawRPC),
L2GethClient: gethclient.New(l2RawRPC),
L2Engine: l2AuthRPC,
TaikoL1: taikoL1,
TaikoL2: taikoL2,
TaikoToken: taikoToken,
GuardianProver: guardianProver,
L1ChainID: l1ChainID,
L2ChainID: l2ChainID,
}

if err := client.ensureGenesisMatched(ctxWithTimeout); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions prover/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Config struct {
StartingBlockID *big.Int
MaxConcurrentProvingJobs uint
Dummy bool
GuardianProver bool
GuardianProverAddress common.Address
GuardianProverPrivateKey *ecdsa.PrivateKey
GuardianProofSubmissionDelay time.Duration
ProofSubmissionMaxRetry uint64
Expand Down Expand Up @@ -115,7 +115,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
StartingBlockID: startingBlockID,
MaxConcurrentProvingJobs: c.Uint(flags.MaxConcurrentProvingJobs.Name),
Dummy: c.Bool(flags.Dummy.Name),
GuardianProver: c.Bool(flags.GuardianProver.Name),
GuardianProverAddress: common.HexToAddress(c.String(flags.GuardianProver.Name)),
GuardianProverPrivateKey: guardianProverPrivKey,
GuardianProofSubmissionDelay: c.Duration(flags.GuardianProofSubmissionDelay.Name),
ProofSubmissionMaxRetry: c.Uint64(flags.ProofSubmissionMaxRetry.Name),
Expand Down
9 changes: 4 additions & 5 deletions prover/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func (s *ProverTestSuite) TestNewConfigFromCliContextGuardianProver() {
crypto.PubkeyToAddress(c.L1ProverPrivKey.PublicKey),
)
s.True(c.Dummy)
s.True(c.GuardianProver)
s.Equal(
crypto.PubkeyToAddress(s.p.cfg.GuardianProverPrivateKey.PublicKey),
crypto.PubkeyToAddress(c.GuardianProverPrivateKey.PublicKey),
Expand Down Expand Up @@ -75,7 +74,7 @@ func (s *ProverTestSuite) TestNewConfigFromCliContextGuardianProver() {
"--" + flags.MinSgxTierFee.Name, fmt.Sprint(minTierFee),
"--" + flags.MinPseZkevmTierFee.Name, fmt.Sprint(minTierFee),
"--" + flags.ProverCapacity.Name, "8",
"--" + flags.GuardianProver.Name,
"--" + flags.GuardianProver.Name, os.Getenv("GUARDIAN_PROVER_CONTRACT_ADDRESS"),
"--" + flags.ProveBlockTxReplacementMultiplier.Name, "3",
"--" + flags.ProveBlockMaxTxGasTipCap.Name, "256",
"--" + flags.GuardianProverPrivateKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
Expand All @@ -97,7 +96,7 @@ func (s *ProverTestSuite) TestNewConfigFromCliContextGuardianProverError() {
"--" + flags.TaikoL2Address.Name, taikoL2,
"--" + flags.L1ProverPrivKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"--" + flags.Dummy.Name,
"--" + flags.GuardianProver.Name,
"--" + flags.GuardianProver.Name, os.Getenv("GUARDIAN_PROVER_CONTRACT_ADDRESS"),
"--" + flags.Graffiti.Name, "",
"--" + flags.RPCTimeout.Name, "5s",
"--" + flags.MinOptimisticTierFee.Name, fmt.Sprint(minTierFee),
Expand All @@ -121,7 +120,7 @@ func (s *ProverTestSuite) TestNewConfigFromCliContextGuardianProverKeyError() {
s.ErrorContains(app.Run([]string{
"TestNewConfigFromCliContext",
"--" + flags.L1ProverPrivKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"--" + flags.GuardianProver.Name,
"--" + flags.GuardianProver.Name, os.Getenv("GUARDIAN_PROVER_CONTRACT_ADDRESS"),
"--" + flags.GuardianProverPrivateKey.Name, "",
}), "invalid guardian private key")
}
Expand All @@ -138,7 +137,7 @@ func (s *ProverTestSuite) SetupApp() *cli.App {
&cli.StringFlag{Name: flags.L1ProverPrivKey.Name},
&cli.Uint64Flag{Name: flags.StartingBlockID.Name},
&cli.BoolFlag{Name: flags.Dummy.Name},
&cli.BoolFlag{Name: flags.GuardianProver.Name},
&cli.StringFlag{Name: flags.GuardianProver.Name},
&cli.StringFlag{Name: flags.GuardianProverPrivateKey.Name},
&cli.StringFlag{Name: flags.Graffiti.Name},
&cli.BoolFlag{Name: flags.ProveUnassignedBlocks.Name},
Expand Down
2 changes: 1 addition & 1 deletion prover/proof_submitter/proof_contester.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (c *ProofContester) SubmitContest(
},
Tier: transitionProvedEvent.Tier,
},
c.txBuilder.Build(ctx, transitionProvedEvent.BlockId, input),
c.txBuilder.BuildForNormalProofSubmission(ctx, transitionProvedEvent.BlockId, input),
); err != nil {
if errors.Is(err, transaction.ErrUnretryable) {
return nil
Expand Down
13 changes: 12 additions & 1 deletion prover/proof_submitter/proof_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,18 @@ func (s *ProofSubmitter) SubmitProof(
return fmt.Errorf("failed to encode TaikoL1.proveBlock inputs: %w", err)
}

if err := s.txSender.Send(ctx, proofWithHeader, s.txBuilder.Build(ctx, proofWithHeader.BlockID, input)); err != nil {
var txBuilder transaction.TxBuilder
if proofWithHeader.Tier == encoding.TierGuardianID {
txBuilder = s.txBuilder.BuildForGuardianProofSubmission(
ctx,
proofWithHeader.BlockID,
(*bindings.TaikoDataBlockEvidence)(evidence),
)
} else {
txBuilder = s.txBuilder.BuildForNormalProofSubmission(ctx, proofWithHeader.BlockID, input)
}

if err := s.txSender.Send(ctx, proofWithHeader, txBuilder); err != nil {
if errors.Is(err, transaction.ErrUnretryable) {
return nil
}
Expand Down
12 changes: 12 additions & 0 deletions prover/proof_submitter/proof_submitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/suite"
"github.com/taikoxyz/taiko-client/bindings"
"github.com/taikoxyz/taiko-client/bindings/encoding"
"github.com/taikoxyz/taiko-client/driver/chain_syncer/beaconsync"
"github.com/taikoxyz/taiko-client/driver/chain_syncer/calldata"
"github.com/taikoxyz/taiko-client/driver/state"
Expand Down Expand Up @@ -130,6 +131,17 @@ func (s *ProofSubmitterTestSuite) TestSubmitProofs() {
}
}

func (s *ProofSubmitterTestSuite) TestGuardianSubmitProofs() {
events := testutils.ProposeAndInsertEmptyBlocks(&s.ClientTestSuite, s.proposer, s.calldataSyncer)

for _, e := range events {
s.Nil(s.proofSubmitter.RequestProof(context.Background(), e))
proofWithHeader := <-s.proofCh
proofWithHeader.Tier = encoding.TierGuardianID
s.Nil(s.proofSubmitter.SubmitProof(context.Background(), proofWithHeader))
}
}

func (s *ProofSubmitterTestSuite) TestProofSubmitterRequestProofCancelled() {
ctx, cancel := context.WithCancel(context.Background())
go func() { time.AfterFunc(2*time.Second, func() { cancel() }) }()
Expand Down
66 changes: 64 additions & 2 deletions prover/proof_submitter/transaction/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/ethereum/go-ethereum/common"
"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/pkg/rpc"
)

Expand Down Expand Up @@ -46,8 +48,12 @@ func NewProveBlockTxBuilder(
}
}

// Build creates a new ProveBlock transaction with the given nonce.
func (a *ProveBlockTxBuilder) Build(ctx context.Context, blockID *big.Int, input []byte) TxBuilder {
// BuildForNormalProofSubmission creates a new TaikoL1.ProveBlock transaction with the given nonce.
func (a *ProveBlockTxBuilder) BuildForNormalProofSubmission(
ctx context.Context,
blockID *big.Int,
input []byte,
) TxBuilder {
return func(nonce *big.Int) (*types.Transaction, error) {
a.mutex.Lock()
defer a.mutex.Unlock()
Expand Down Expand Up @@ -76,10 +82,66 @@ func (a *ProveBlockTxBuilder) Build(ctx context.Context, blockID *big.Int, input
}
}

log.Info(
"Build proof submission transaction",
"blockID", blockID,
"gasLimit", txOpts.GasLimit,
"nonce", txOpts.Nonce,
"gasTipCap", txOpts.GasTipCap,
"gasFeeCap", txOpts.GasFeeCap,
)

return a.rpc.TaikoL1.ProveBlock(txOpts, blockID.Uint64(), input)
}
}

// BuildForGuardianProofSubmission creates a new GuardianProver.approveEvidence transaction with the given nonce.
func (a *ProveBlockTxBuilder) BuildForGuardianProofSubmission(
ctx context.Context,
blockID *big.Int,
evidence *bindings.TaikoDataBlockEvidence,
) TxBuilder {
return func(nonce *big.Int) (*types.Transaction, error) {
a.mutex.Lock()
defer a.mutex.Unlock()

txOpts, err := getProveBlocksTxOpts(ctx, a.rpc.L1, a.rpc.L1ChainID, a.proverPrivateKey)
if err != nil {
return nil, err
}

if a.gasLimit != nil {
txOpts.GasLimit = a.gasLimit.Uint64()
}

if nonce != nil {
txOpts.Nonce = nonce

if txOpts, err = rpc.IncreaseGasTipCap(
ctx,
a.rpc,
txOpts,
a.proverAddress,
a.gasTipMultiplier,
a.gasTipCap,
); err != nil {
return nil, err
}
}

log.Info(
"Build guardian proof submission transaction",
"blockID", blockID,
"gasLimit", txOpts.GasLimit,
"nonce", txOpts.Nonce,
"gasTipCap", txOpts.GasTipCap,
"gasFeeCap", txOpts.GasFeeCap,
)

return a.rpc.GuardianProver.ApproveEvidence(txOpts, blockID.Uint64(), *evidence)
}
}

// getProveBlocksTxOpts creates a bind.TransactOpts instance using the given private key.
// Used for creating TaikoL1.proveBlock and TaikoL1.proveBlockInvalid transactions.
func getProveBlocksTxOpts(
Expand Down
Loading

0 comments on commit 9066722

Please sign in to comment.