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

Commit

Permalink
feat(prover): implement staking based tokenomics in client (#292)
Browse files Browse the repository at this point in the history
Co-authored-by: David <[email protected]>
  • Loading branch information
cyberhorsey and davidtaikocha authored Jul 3, 2023
1 parent 59469fa commit 7324547
Show file tree
Hide file tree
Showing 31 changed files with 2,524 additions and 672 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: alpha-4

- 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 @@
9d7bc39c282c6ceb0e62146aa6271d5ceaee7633
8e398f40bd8693af5966c3ac7bf21cb3516d4b2d
3 changes: 1 addition & 2 deletions bindings/encoding/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import (
)

var (
OracleProverAddress = common.HexToAddress("0x0000000000000000000000000000000000000000")
SystemProverAddress = common.HexToAddress("0x0000000000000000000000000000000000000001")
OracleProverAddress = common.HexToAddress("0x0000000000000000000000000000000000000001")
)

type BlockHeader struct {
Expand Down
440 changes: 195 additions & 245 deletions bindings/gen_taiko_l1.go

Large diffs are not rendered by default.

1,982 changes: 1,982 additions & 0 deletions bindings/gen_taiko_prover_pool_l1.go

Large diffs are not rendered by default.

31 changes: 13 additions & 18 deletions cmd/flags/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,28 @@ var (
Usage: "Set whether prover should use oracle prover or not",
Category: proverCategory,
}
SystemProver = &cli.BoolFlag{
Name: "systemProver",
Usage: "Set whether prover should use system prover or not",
Category: proverCategory,
}
OracleProverPrivateKey = &cli.StringFlag{
Name: "oracleProverPrivateKey",
Usage: "Private key of oracle prover",
Category: proverCategory,
}
SystemProverPrivateKey = &cli.StringFlag{
Name: "systemProverPrivateKey",
Usage: "Private key of system prover",
Category: proverCategory,
}
Graffiti = &cli.StringFlag{
Name: "graffiti",
Usage: "When string is passed, adds additional graffiti info to proof evidence",
Category: proverCategory,
Value: "",
}
ExpectedReward = &cli.Uint64Flag{
Name: "expectedReward",
Usage: "The expected prover reward for each block",
Category: proverCategory,
Value: 100_000_000,
TaikoProverPoolL1Address = &cli.StringFlag{
Name: "taikoProverPoolL1",
Usage: "TaikoProverPoolL1 contract address",
Required: true,
Category: commonCategory,
}
CheckProofWindowExpiredInterval = &cli.Uint64Flag{
Name: "prover.checkProofWindowExpiredInterval",
Usage: "Interval in seconds to check for expired proof windows from other provers",
Category: commonCategory,
Value: 15,
}
)

Expand All @@ -100,9 +96,8 @@ var ProverFlags = MergeFlags(CommonFlags, []cli.Flag{
Dummy,
RandomDummyProofDelay,
OracleProver,
SystemProver,
OracleProverPrivateKey,
SystemProverPrivateKey,
Graffiti,
ExpectedReward,
TaikoProverPoolL1Address,
CheckProofWindowExpiredInterval,
})
7 changes: 3 additions & 4 deletions driver/chain_syncer/calldata/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func NewSyncer(
progressTracker: progressTracker,
anchorConstructor: constructor,
txListValidator: txListValidator.NewTxListValidator(
configs.BlockMaxGasLimit,
configs.MaxTransactionsPerBlock,
configs.MaxBytesPerTxList,
uint64(configs.BlockMaxGasLimit),
configs.BlockMaxTransactions,
configs.BlockMaxTxListBytes,
rpc.L2ChainID,
),
}, nil
Expand Down Expand Up @@ -176,7 +176,6 @@ func (s *Syncer) onBlockProposed(
"L1Height", event.Raw.BlockNumber,
"L1Hash", event.Raw.BlockHash,
"BlockID", event.Id,
"BlockFee", event.BlockFee,
"Removed", event.Raw.Removed,
)

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

maxNumBlocks = configs.MaxNumProposedBlocks.Uint64()
maxNumBlocks = configs.BlockMaxProposals.Uint64()
return nil
},
backoff.NewConstantBackOff(d.backOffRetryInterval),
Expand Down
2 changes: 1 addition & 1 deletion driver/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (s *State) startSubscriptions(ctx context.Context) {
case e := <-s.blockProposedCh:
s.setHeadBlockID(e.Id)
case e := <-s.blockProvenCh:
if e.Prover != encoding.SystemProverAddress && e.Prover != encoding.OracleProverAddress {
if e.Prover != encoding.OracleProverAddress {
log.Info("✅ Block proven", "blockID", e.Id, "hash", common.Hash(e.BlockHash), "prover", e.Prover)
}
case e := <-s.blockVerifiedCh:
Expand Down
4 changes: 4 additions & 0 deletions integration_test/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ $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')
TAIKO_PROVER_POOL_L1_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.prover_pool' | sed 's/\"//g')
TAIKO_TOKEN_L1_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.taiko_token' | sed 's/\"//g')
L1_SIGNAL_SERVICE_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.signal_service' | sed 's/\"//g')

trap "docker compose -f $TESTNET_CONFIG down -v" EXIT INT KILL ERR
Expand All @@ -44,6 +46,8 @@ if [ "$RUN_TESTS" == "true" ]; then
L2_EXECUTION_ENGINE_WS_ENDPOINT=ws://localhost:28546 \
L2_EXECUTION_ENGINE_AUTH_ENDPOINT=http://localhost:28551 \
TAIKO_L1_ADDRESS=$TAIKO_L1_CONTRACT_ADDRESS \
TAIKO_PROVER_POOL_L1_ADDRESS=$TAIKO_PROVER_POOL_L1_CONTRACT_ADDRESS \
TAIKO_TOKEN_L1_ADDRESS=$TAIKO_TOKEN_L1_CONTRACT_ADDRESS \
TAIKO_L2_ADDRESS=0x1000777700000000000000000000000000000001 \
L1_SIGNAL_SERVICE_CONTRACT_ADDRESS=$L1_SIGNAL_SERVICE_CONTRACT_ADDRESS \
L1_CONTRACT_OWNER_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
Expand Down
7 changes: 2 additions & 5 deletions integration_test/nodes/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,17 @@ L2_GENESIS_HASH=$(
# Deploy Taiko protocol.
cd $TAIKO_MONO_DIR/packages/protocol &&
PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
SYSTEM_PROVER=0x70997970C51812dc3A010C7d01b50e0d17dc79C8 \
ORACLE_PROVER=0x70997970C51812dc3A010C7d01b50e0d17dc79C8 \
SOLO_PROPOSER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
OWNER=0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC \
TREASURY=0xdf09A0afD09a63fb04ab3573922437e1e637dE8b \
INITIAL_PROOF_TIME_TARGET=101 \
TAIKO_L2_ADDRESS=0x1000777700000000000000000000000000000001 \
L2_SIGNAL_SERVICE=0x1000777700000000000000000000000000000007 \
SHARED_SIGNAL_SERVICE=0x0000000000000000000000000000000000000000 \
TAIKO_TOKEN_PREMINT_RECIPIENT=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
TAIKO_TOKEN_PREMINT_AMOUNT=18446744073709551614 \
TAIKO_TOKEN_PREMINT_RECIPIENTS=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266,0x70997970C51812dc3A010C7d01b50e0d17dc79C8 \
TAIKO_TOKEN_PREMINT_AMOUNTS=9223372036854775807,9223372036854775807 \
L2_GENESIS_HASH=$L2_GENESIS_HASH \
L2_CHAIN_ID=167001 \
ADJUSTMENT_QUOTIENT=32000 \
forge script script/DeployOnL1.s.sol:DeployOnL1 \
--fork-url http://localhost:18545 \
--broadcast \
Expand Down
55 changes: 33 additions & 22 deletions pkg/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ type Client struct {
// Geth Engine API clients
L2Engine *EngineClient
// Protocol contracts clients
TaikoL1 *bindings.TaikoL1Client
TaikoL2 *bindings.TaikoL2Client
TaikoL1 *bindings.TaikoL1Client
TaikoL2 *bindings.TaikoL2Client
TaikoProverPoolL1 *bindings.TaikoL1ProverPool
// Chain IDs
L1ChainID *big.Int
L2ChainID *big.Int
Expand All @@ -38,14 +39,15 @@ 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
L2EngineEndpoint string
JwtSecret string
RetryInterval time.Duration
L1Endpoint string
L2Endpoint string
L2CheckPoint string
TaikoL1Address common.Address
TaikoProverPoolL1Address common.Address
TaikoL2Address common.Address
L2EngineEndpoint string
JwtSecret string
RetryInterval time.Duration
}

// NewClient initializes all RPC clients used by Taiko client softwares.
Expand All @@ -60,6 +62,14 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) {
return nil, err
}

var taikoProverPoolL1 *bindings.TaikoL1ProverPool
if cfg.TaikoProverPoolL1Address.Hex() != "" {
taikoProverPoolL1, err = bindings.NewTaikoL1ProverPool(cfg.TaikoProverPoolL1Address, l1RPC)
if err != nil {
return nil, err
}
}

l2RPC, err := DialClientWithBackoff(ctx, cfg.L2Endpoint, cfg.RetryInterval)
if err != nil {
return nil, err
Expand Down Expand Up @@ -112,18 +122,19 @@ 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,
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,
TaikoProverPoolL1: taikoProverPoolL1,
L1ChainID: l1ChainID,
L2ChainID: l2ChainID,
}

if err := client.ensureGenesisMatched(ctx); err != nil {
Expand Down
15 changes: 8 additions & 7 deletions pkg/rpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import (

func newTestClient(t *testing.T) *Client {
client, err := NewClient(context.Background(), &ClientConfig{
L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"),
L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"),
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")),
L2EngineEndpoint: os.Getenv("L2_EXECUTION_ENGINE_AUTH_ENDPOINT"),
JwtSecret: os.Getenv("JWT_SECRET"),
RetryInterval: backoff.DefaultMaxInterval,
L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"),
L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"),
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")),
TaikoProverPoolL1Address: common.HexToAddress(os.Getenv("TAIKO_PROVER_POOL_L1_ADDRESS")),
L2EngineEndpoint: os.Getenv("L2_EXECUTION_ENGINE_AUTH_ENDPOINT"),
JwtSecret: os.Getenv("JWT_SECRET"),
RetryInterval: backoff.DefaultMaxInterval,
})

require.Nil(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/rpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (c *Client) WaitL1Origin(ctx context.Context, blockID *big.Int) (*rawdb.L1O
func (c *Client) GetPoolContent(
ctx context.Context,
maxTransactionsPerBlock uint64,
blockMaxGasLimit uint64,
blockMaxGasLimit uint32,
maxBytesPerTxList uint64,
locals []common.Address,
) ([]types.Transactions, error) {
Expand Down
18 changes: 18 additions & 0 deletions pkg/rpc/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ func SubscribeBlockProven(
})
}

// SubscribeSlashed subscribes the prover pool's Slashed events.
func SubscribeSlashed(
taikoProverPool *bindings.TaikoL1ProverPool,
ch chan *bindings.TaikoL1ProverPoolSlashed,
) event.Subscription {
return SubscribeEvent("Slashed", func(ctx context.Context) (event.Subscription, error) {
sub, err := taikoProverPool.WatchSlashed(nil, ch, nil)
if err != nil {
log.Error("Create taikoProverPool.WatchSlashed subscription error", "error", err)
return nil, err
}

defer sub.Unsubscribe()

return waitSubErr(ctx, sub)
})
}

// SubscribeChainHead subscribes the new chain heads.
func SubscribeChainHead(
client *ethclient.Client,
Expand Down
7 changes: 7 additions & 0 deletions pkg/rpc/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ func TestSubscribeBlockProven(t *testing.T) {
)
}

func TestSubscribeSlashed(t *testing.T) {
require.NotNil(t, SubscribeSlashed(
newTestClient(t).TaikoProverPoolL1,
make(chan *bindings.TaikoL1ProverPoolSlashed, 1024)),
)
}

func TestSubscribeChainHead(t *testing.T) {
require.NotNil(t, SubscribeChainHead(
newTestClient(t).L1,
Expand Down
Loading

0 comments on commit 7324547

Please sign in to comment.