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

Commit

Permalink
feat(all): offchain prover pool / alpha 5 tokenomics / bindings updat…
Browse files Browse the repository at this point in the history
…es (#368)

Co-authored-by: David <[email protected]>
  • Loading branch information
cyberhorsey and davidtaikocha authored Aug 25, 2023
1 parent 0feccbb commit 5fe3ffc
Show file tree
Hide file tree
Showing 41 changed files with 4,001 additions and 212 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
with:
repository: taikoxyz/taiko-mono
path: ${{ env.TAIKO_MONO_DIR }}
ref: prover_abstraction_and_protocol_simplification

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
Expand Down
2 changes: 1 addition & 1 deletion bindings/.githead
Original file line number Diff line number Diff line change
@@ -1 +1 @@
497fdee4a2450f009367d8768ff201ef697fbacc
bbaf0dadd79ab2f392c7fe39f4c0744b6ede530e
54 changes: 54 additions & 0 deletions bindings/encoding/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,36 @@ var (
Type: "bytes",
},
}
proverAssignmentComponents = []abi.ArgumentMarshaling{
{
Name: "prover",
Type: "address",
},
{
Name: "expiry",
Type: "uint64",
},
{
Name: "data",
Type: "bytes",
},
}
proposeBlockDataComponents = []abi.ArgumentMarshaling{
{
Name: "input",
Type: "tuple",
Components: blockMetadataInputComponents,
},
{
Name: "fee",
Type: "uint256",
},

{
Name: "expiry",
Type: "uint64",
},
}
)

var (
Expand All @@ -148,6 +178,12 @@ var (
// Evidence
EvidenceType, _ = abi.NewType("tuple", "TaikoData.BlockEvidence", evidenceComponents)
EvidenceArgs = abi.Arguments{{Name: "Evidence", Type: EvidenceType}}
// ProverAssignment
proverAssignmentType, _ = abi.NewType("tuple", "ProverAssignment", proverAssignmentComponents)
proverAssignmentArgs = abi.Arguments{{Name: "ProverAssignment", Type: proverAssignmentType}}
// ProposeBlockData
proposeBlockDataType, _ = abi.NewType("tuple", "ProposeBlockData", proposeBlockDataComponents)
proposeBlockDataArgs = abi.Arguments{{Name: "ProposeBlockData", Type: proposeBlockDataType}}
)

// Contract ABIs.
Expand Down Expand Up @@ -186,6 +222,24 @@ func EncodeBlockMetadata(meta *bindings.TaikoDataBlockMetadata) ([]byte, error)
return b, nil
}

// EncodeProverAssignment performs the solidity `abi.encode` for the given proverAssignment.
func EncodeProverAssignment(assignment *ProverAssignment) ([]byte, error) {
b, err := proverAssignmentArgs.Pack(assignment)
if err != nil {
return nil, fmt.Errorf("failed to abi.encode prover assignment, %w", err)
}
return b, nil
}

// EncodeProposeBlockData performs the solidity `abi.encode` for the given proposeBlockData.
func EncodeProposeBlockData(data *ProposeBlockData) ([]byte, error) {
b, err := proposeBlockDataArgs.Pack(data)
if err != nil {
return nil, fmt.Errorf("failed to abi.encode proposeBlock data, %w", err)
}
return b, nil
}

// EncodeEvidence performs the solidity `abi.encode` for the given evidence.
func EncodeEvidence(e *TaikoL1Evidence) ([]byte, error) {
b, err := EvidenceArgs.Pack(e)
Expand Down
13 changes: 13 additions & 0 deletions bindings/encoding/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ func TestEncodeProveBlockInput(t *testing.T) {
require.NotNil(t, encoded)
}

func TestEncodeProverAssignment(t *testing.T) {
encoded, err := EncodeProverAssignment(
&ProverAssignment{
Prover: common.BigToAddress(new(big.Int).SetUint64(rand.Uint64())),
Data: randomHash().Big().Bytes(),
Expiry: 1024,
},
)

require.Nil(t, err)
require.NotNil(t, encoded)
}

func TestEncodeProveBlockInvalidInput(t *testing.T) {
encoded, err := EncodeProveBlockInvalidInput(
&TaikoL1Evidence{
Expand Down
12 changes: 12 additions & 0 deletions bindings/encoding/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ type TaikoL1BlockMetadataInput struct {
CacheTxListInfo bool
}

type ProverAssignment struct {
Prover common.Address
Expiry uint64
Data []byte
}

type ProposeBlockData struct {
Input TaikoL1BlockMetadataInput `json:"input"`
Fee *big.Int `json:"fee"`
Expiry uint64 `json:"expiry"`
}

// FromGethHeader converts a GETH *types.Header to *BlockHeader.
func FromGethHeader(header *types.Header) *BlockHeader {
baseFeePerGas := header.BaseFee
Expand Down
86 changes: 41 additions & 45 deletions bindings/gen_taiko_l1.go

Large diffs are not rendered by default.

2,686 changes: 2,686 additions & 0 deletions bindings/gen_taiko_token.go

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions cmd/flags/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ var (
Required: true,
Category: proposerCategory,
}
ProverEndpoints = &cli.StringFlag{
Name: "proverEndpoints",
Usage: "Comma-delinated list of prover endpoints proposer should query when attemping to propose a block",
Category: proposerCategory,
}
BlockProposalFee = &cli.StringFlag{
Name: "blockProposalFee",
Usage: "Initial block proposal fee (in wei) paid on block proposing",
Category: proposerCategory,
}
TaikoTokenAddress = &cli.StringFlag{
Name: "taikoToken",
Usage: "TaikoToken contract address",
Required: true,
Category: proposerCategory,
}
)

// Optional flags used by proposer.
Expand Down Expand Up @@ -64,6 +80,12 @@ var (
Usage: "Gas tip cap (in wei) for a TaikoL1.proposeBlock transaction when doing the transaction replacement",
Category: proposerCategory,
}
BlockProposalFeeIncreasePercentage = &cli.Uint64Flag{
Name: "blockProposalFeeIncreasePercentage",
Usage: "Increase fee by what percentage when no prover wants to accept the block at initial fee",
Category: proposerCategory,
Value: 10,
}
)

// All proposer flags.
Expand All @@ -79,4 +101,8 @@ var ProposerFlags = MergeFlags(CommonFlags, []cli.Flag{
ProposeBlockTxGasLimit,
ProposeBlockTxReplacementMultiplier,
ProposeBlockTxGasTipCap,
ProverEndpoints,
BlockProposalFee,
BlockProposalFeeIncreasePercentage,
TaikoTokenAddress,
})
27 changes: 20 additions & 7 deletions cmd/flags/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ var (
Required: true,
Category: proverCategory,
}
MinProofFee = &cli.StringFlag{
Name: "prover.minProofFee",
Usage: "Minimum accepted fee for accepting proving a block",
Required: true,
Category: proverCategory,
}
)

// Optional flags used by prover.
Expand Down Expand Up @@ -81,12 +87,6 @@ var (
Category: proverCategory,
Value: "",
}
TaikoProverPoolL1Address = &cli.StringFlag{
Name: "taikoProverPoolL1",
Usage: "TaikoProverPoolL1 contract address",
Required: true,
Category: proverCategory,
}
CheckProofWindowExpiredInterval = &cli.Uint64Flag{
Name: "prover.checkProofWindowExpiredInterval",
Usage: "Interval in seconds to check for expired proof windows from other provers",
Expand All @@ -104,6 +104,17 @@ var (
Usage: "Gas limit will be used for TaikoL1.proveBlock transactions",
Category: proverCategory,
}
ProverHTTPServerPort = &cli.Uint64Flag{
Name: "prover.httpServerPort",
Usage: "Port to expose for http server",
Category: proverCategory,
Value: 9876,
}
ProverCapacity = &cli.Uint64Flag{
Name: "prover.capacity",
Usage: "Capacity of prover, required if oracleProver is false",
Category: proverCategory,
}
)

// All prover flags.
Expand All @@ -123,8 +134,10 @@ var ProverFlags = MergeFlags(CommonFlags, []cli.Flag{
OracleProofSubmissionDelay,
ProofSubmissionMaxRetry,
Graffiti,
TaikoProverPoolL1Address,
CheckProofWindowExpiredInterval,
ProveUnassignedBlocks,
ProveBlockTxGasLimit,
ProverHTTPServerPort,
ProverCapacity,
MinProofFee,
})
4 changes: 2 additions & 2 deletions cmd/utils/sub_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type SubcommandApplication interface {
InitFromCli(context.Context, *cli.Context) error
Name() string
Start() error
Close()
Close(context.Context)
}

func SubcommandAction(app SubcommandApplication) cli.ActionFunc {
Expand Down Expand Up @@ -44,7 +44,7 @@ func SubcommandAction(app SubcommandApplication) cli.ActionFunc {

defer func() {
ctxClose()
app.Close()
app.Close(ctx)
log.Info("Application stopped", "name", app.Name())
}()

Expand Down
9 changes: 7 additions & 2 deletions driver/chain_syncer/calldata/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ import (
txListValidator "github.com/taikoxyz/taiko-client/pkg/tx_list_validator"
)

var (
// Brecht recommends to hardcore 79, may be unrequired as proof system changes
defaultMaxTxPerBlock = uint64(79)
)

// Syncer responsible for letting the L2 execution engine catching up with protocol's latest
// pending block through deriving L1 calldata.
type Syncer struct {
Expand Down Expand Up @@ -65,8 +70,8 @@ func NewSyncer(
anchorConstructor: constructor,
txListValidator: txListValidator.NewTxListValidator(
uint64(configs.BlockMaxGasLimit),
configs.BlockMaxTransactions,
configs.BlockMaxTxListBytes,
defaultMaxTxPerBlock,
configs.BlockMaxTxListBytes.Uint64(),
rpc.L2ChainID,
),
}, nil
Expand Down
26 changes: 24 additions & 2 deletions driver/chain_syncer/calldata/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package calldata

import (
"context"
"fmt"
"math/big"
"math/rand"
"os"
Expand All @@ -16,18 +17,23 @@ import (
"github.com/taikoxyz/taiko-client/driver/chain_syncer/beaconsync"
"github.com/taikoxyz/taiko-client/driver/state"
"github.com/taikoxyz/taiko-client/proposer"
"github.com/taikoxyz/taiko-client/prover/http"
"github.com/taikoxyz/taiko-client/testutils"
)

type CalldataSyncerTestSuite struct {
testutils.ClientTestSuite
s *Syncer
p testutils.Proposer
s *Syncer
p testutils.Proposer
srv *http.Server
cancel context.CancelFunc
}

func (s *CalldataSyncerTestSuite) SetupTest() {
s.ClientTestSuite.SetupTest()

port := testutils.RandomPort()

state, err := state.New(context.Background(), s.RpcClient)
s.Nil(err)

Expand All @@ -50,16 +56,26 @@ func (s *CalldataSyncerTestSuite) SetupTest() {
L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"),
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")),
TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")),
L1ProposerPrivKey: l1ProposerPrivKey,
L2SuggestedFeeRecipient: common.HexToAddress(os.Getenv("L2_SUGGESTED_FEE_RECIPIENT")),
ProposeInterval: &proposeInterval,
MaxProposedTxListsPerEpoch: 1,
WaitReceiptTimeout: 10 * time.Second,
ProverEndpoints: []string{fmt.Sprintf("http://localhost:%v", port)},
BlockProposalFee: big.NewInt(1000),
})))

srv, cancel, err := testutils.HTTPServer(&s.ClientTestSuite, port)
s.Nil(err)

s.srv = srv
s.cancel = cancel

s.p = prop
}
func (s *CalldataSyncerTestSuite) TestNewSyncer() {
defer s.cancel()
ctx, cancel := context.WithCancel(context.Background())
cancel()
syncer, err := NewSyncer(
Expand All @@ -74,19 +90,22 @@ func (s *CalldataSyncerTestSuite) TestNewSyncer() {
}

func (s *CalldataSyncerTestSuite) TestProcessL1Blocks() {
defer s.cancel()
head, err := s.s.rpc.L1.HeaderByNumber(context.Background(), nil)
s.Nil(err)
s.Nil(s.s.ProcessL1Blocks(context.Background(), head))
}

func (s *CalldataSyncerTestSuite) TestProcessL1BlocksReorg() {
defer s.cancel()
head, err := s.s.rpc.L1.HeaderByNumber(context.Background(), nil)
testutils.ProposeAndInsertEmptyBlocks(&s.ClientTestSuite, s.p, s.s)
s.Nil(err)
s.Nil(s.s.ProcessL1Blocks(context.Background(), head))
}

func (s *CalldataSyncerTestSuite) TestOnBlockProposed() {
defer s.cancel()
s.Nil(s.s.onBlockProposed(
context.Background(),
&bindings.TaikoL1ClientBlockProposed{BlockId: common.Big0},
Expand All @@ -100,6 +119,7 @@ func (s *CalldataSyncerTestSuite) TestOnBlockProposed() {
}

func (s *CalldataSyncerTestSuite) TestInsertNewHead() {
defer s.cancel()
parent, err := s.s.rpc.L2.HeaderByNumber(context.Background(), nil)
s.Nil(err)
l1Head, err := s.s.rpc.L1.BlockByNumber(context.Background(), nil)
Expand Down Expand Up @@ -132,6 +152,7 @@ func (s *CalldataSyncerTestSuite) TestInsertNewHead() {
}

func (s *CalldataSyncerTestSuite) TestTreasuryIncomeAllAnchors() {
defer s.cancel()
treasury := common.HexToAddress(os.Getenv("TREASURY"))
s.NotZero(treasury.Big().Uint64())

Expand All @@ -154,6 +175,7 @@ func (s *CalldataSyncerTestSuite) TestTreasuryIncomeAllAnchors() {
}

func (s *CalldataSyncerTestSuite) TestTreasuryIncome() {
defer s.cancel()
treasury := common.HexToAddress(os.Getenv("TREASURY"))
s.NotZero(treasury.Big().Uint64())

Expand Down
2 changes: 1 addition & 1 deletion driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (d *Driver) Start() error {
}

// Close closes the driver instance.
func (d *Driver) Close() {
func (d *Driver) Close(ctx context.Context) {
d.state.Close()
d.wg.Wait()
}
Expand Down
Loading

0 comments on commit 5fe3ffc

Please sign in to comment.