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

Commit

Permalink
add hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey committed Nov 21, 2023
1 parent b08ccda commit 61c4fcf
Show file tree
Hide file tree
Showing 30 changed files with 1,644 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
with:
repository: taikoxyz/taiko-mono
path: ${{ env.TAIKO_MONO_DIR }}
ref: based_contestable_zkrollup
ref: update_relayer_eventindexer_post_hooks

- 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 @@
d61af90b54fba27ee5db074ad0c34c82c6642022
8a27392aead6350fd00d8add2ab0a459808e6160
67 changes: 49 additions & 18 deletions bindings/encoding/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@ var (
}
blockParamsComponents = []abi.ArgumentMarshaling{
{
Name: "assignment",
Type: "tuple",
Components: proverAssignmentComponents,
Name: "assignedProver",
Type: "address",
},
{
Name: "extraData",
Expand All @@ -132,30 +131,26 @@ var (
Name: "parentMetaHash",
Type: "bytes32",
},
}
proverAssignmentComponents = []abi.ArgumentMarshaling{
{
Name: "prover",
Type: "address",
},
{
Name: "feeToken",
Type: "address",
},
{
Name: "tierFees",
Name: "hookCalls",
Type: "tuple[]",
Components: []abi.ArgumentMarshaling{
{
Name: "tier",
Type: "uint16",
Name: "hook",
Type: "address",
},
{
Name: "fee",
Type: "uint128",
Name: "data",
Type: "bytes",
},
},
},
}
proverAssignmentComponents = []abi.ArgumentMarshaling{
{
Name: "feeToken",
Type: "address",
},
{
Name: "expiry",
Type: "uint64",
Expand All @@ -172,15 +167,42 @@ var (
Name: "metaHash",
Type: "bytes32",
},
{
Name: "tierFees",
Type: "tuple[]",
Components: []abi.ArgumentMarshaling{
{
Name: "tier",
Type: "uint16",
},
{
Name: "fee",
Type: "uint128",
},
},
},
{
Name: "signature",
Type: "bytes",
},
}
assignmentHookInputComponents = []abi.ArgumentMarshaling{
{
Name: "assignment",
Type: "tuple",
Components: proverAssignmentComponents,
},
{
Name: "tip",
Type: "uint256",
},
}
)

var (
// BlockParams
assignmentHookInputType, _ = abi.NewType("tuple", "AssignmentHook.Input", assignmentHookInputComponents)
assignmentHookInputArgs = abi.Arguments{{Name: "AssignmentHook.Input", Type: assignmentHookInputType}}
blockParamsComponentsType, _ = abi.NewType("tuple", "TaikoData.BlockParams", blockParamsComponents)
blockParamsComponentsArgs = abi.Arguments{{Name: "TaikoData.BlockParams", Type: blockParamsComponentsType}}
// ProverAssignmentPayload
Expand Down Expand Up @@ -249,6 +271,15 @@ func EncodeBlockParams(params *BlockParams) ([]byte, error) {
return b, nil
}

// EncodeAssignmentHookInput performs the solidity `abi.encode` for the given input
func EncodeAssignmentHookInput(input *AssignmentHookInput) ([]byte, error) {
b, err := assignmentHookInputArgs.Pack(input)
if err != nil {
return nil, fmt.Errorf("failed to abi.encode assignment hook input params, %w", err)
}
return b, nil
}

// EncodeProverAssignmentPayload performs the solidity `abi.encode` for the given proverAssignment payload.
func EncodeProverAssignmentPayload(
taikoAddress common.Address,
Expand Down
18 changes: 15 additions & 3 deletions bindings/encoding/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,22 @@ type BlockHeader struct {
BaseFeePerGas *big.Int
}

// HookCall should be same with TaikoData.HookCall
type HookCall struct {
Hook common.Address
Data []byte
}

// BlockParams should be same with TaikoData.BlockParams.
type BlockParams struct {
Assignment *ProverAssignment
AssignedProver common.Address
ExtraData [32]byte
BlobHash [32]byte
TxListByteOffset *big.Int
TxListByteSize *big.Int
CacheBlobForReuse bool
ParentMetaHash [32]byte
HookCalls []HookCall
}

// TierFee should be same with TaikoData.TierFee.
Expand All @@ -57,16 +64,21 @@ type TierFee struct {

// ProverAssignment should be same with TaikoData.ProverAssignment.
type ProverAssignment struct {
Prover common.Address
FeeToken common.Address
TierFees []TierFee
Expiry uint64
MaxBlockId uint64
MaxProposedIn uint64
MetaHash [32]byte
TierFees []TierFee
Signature []byte
}

// AssignmentHookInput should be same as AssignmentHook.Input
type AssignmentHookInput struct {
Assignment *ProverAssignment
Tip *big.Int
}

// FromGethHeader converts a GETH *types.Header to *BlockHeader.
func FromGethHeader(header *types.Header) *BlockHeader {
baseFeePerGas := header.BaseFee
Expand Down
1,448 changes: 1,448 additions & 0 deletions bindings/gen_assignment_hook.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions bindings/gen_taiko_l1.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions cmd/flags/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ var (
Required: true,
Category: proposerCategory,
}
ProposerAssignmentHookAddress = &cli.StringFlag{
Name: "assignmentHookAddress",
Usage: "Address of the AssignmentHook contract",
Required: true,
Category: proposerCategory,
}
)

// Optional flags used by proposer.
Expand Down Expand Up @@ -139,4 +145,5 @@ var ProposerFlags = MergeFlags(CommonFlags, []cli.Flag{
TierFeePriceBump,
MaxTierFeePriceBumps,
ProposeBlockIncludeParentMetaHash,
ProposerAssignmentHookAddress,
})
7 changes: 7 additions & 0 deletions cmd/flags/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ var (
Required: true,
Category: proverCategory,
}
ProverAssignmentHookAddress = &cli.StringFlag{
Name: "assignmentHookAddress",
Usage: "Address of the AssignmentHook contract",
Required: true,
Category: proverCategory,
}
)

// Optional flags used by prover.
Expand Down Expand Up @@ -210,4 +216,5 @@ var ProverFlags = MergeFlags(CommonFlags, []cli.Flag{
MaxAcceptableBlockSlippage,
DatabasePath,
DatabaseCacheSize,
ProverAssignmentHookAddress,
})
1 change: 1 addition & 0 deletions driver/chain_syncer/calldata/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (s *CalldataSyncerTestSuite) SetupTest() {
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")),
TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")),
AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
L1ProposerPrivKey: l1ProposerPrivKey,
ProposeInterval: &proposeInterval,
MaxProposedTxListsPerEpoch: 1,
Expand Down
1 change: 1 addition & 0 deletions driver/chain_syncer/chain_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (s *ChainSyncerTestSuite) SetupTest() {
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")),
TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")),
AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
L1ProposerPrivKey: l1ProposerPrivKey,
ProposeInterval: &proposeInterval,
MaxProposedTxListsPerEpoch: 1,
Expand Down
1 change: 1 addition & 0 deletions driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (s *DriverTestSuite) SetupTest() {
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")),
TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")),
AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
L1ProposerPrivKey: l1ProposerPrivKey,
ProposeInterval: &proposeInterval,
MaxProposedTxListsPerEpoch: 1,
Expand Down
3 changes: 3 additions & 0 deletions integration_test/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ L1_SIGNAL_SERVICE_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.signal_service
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_prover' | sed 's/\"//g')
ASSIGNMENT_HOOK_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.assignment_hook' | sed 's/\"//g')

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

Expand All @@ -39,6 +40,7 @@ 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"
echo "ASSIGNMENT_HOOK_CONTRACT_ADDRESS: $ASSIGNMENT_HOOK_CONTRACT_ADDRESS"

if [ "$RUN_TESTS" == "true" ]; then
L1_NODE_HTTP_ENDPOINT=http://localhost:18545 \
Expand All @@ -49,6 +51,7 @@ if [ "$RUN_TESTS" == "true" ]; then
TAIKO_L1_ADDRESS=$TAIKO_L1_CONTRACT_ADDRESS \
TAIKO_L2_ADDRESS=0x1670010000000000000000000000000000010001 \
TAIKO_TOKEN_ADDRESS=$TAIKO_TOKEN_CONTRACT_ADDRESS \
ASSIGNMENT_HOOK_ADDRESS=$ASSIGNMENT_HOOK_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 \
Expand Down
62 changes: 30 additions & 32 deletions pkg/rpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,54 +40,52 @@ func GetProtocolStateVariables(
return &stateVars, nil
}

// CheckProverBalance checks if the prover has the necessary balance either in TaikoL1 token balances
// or, if not, then check allowance, as contract will attempt to burn directly after
// if it doesnt have the available token balance in-contract.
// CheckProverBalance checks if the prover has the necessary allowance and
// balance for a prover to pay the liveness bond.
func CheckProverBalance(
ctx context.Context,
rpc *Client,
prover common.Address,
taikoL1Address common.Address,
address common.Address,
bond *big.Int,
) (bool, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, defaultTimeout)
defer cancel()

depositedBalance, err := rpc.TaikoL1.GetTaikoTokenBalance(&bind.CallOpts{Context: ctxWithTimeout}, prover)
// Check allowance on taiko token contract
allowance, err := rpc.TaikoToken.Allowance(&bind.CallOpts{Context: ctxWithTimeout}, prover, address)
if err != nil {
return false, err
}

log.Info("Prover's deposited taikoTokenBalance", "balance", depositedBalance.String(), "address", prover.Hex())

if bond.Cmp(depositedBalance) > 0 {
// Check allowance on taiko token contract
allowance, err := rpc.TaikoToken.Allowance(&bind.CallOpts{Context: ctxWithTimeout}, prover, taikoL1Address)
if err != nil {
return false, err
}
log.Info("Prover allowance for TaikoL1 contract",
"allowance", allowance.String(),
"address", prover.Hex(),
"bond", bond.String(),
)

log.Info("Prover allowance for TaikoL1 contract", "allowance", allowance.String(), "address", prover.Hex())
// Check prover's taiko token balance
balance, err := rpc.TaikoToken.BalanceOf(&bind.CallOpts{Context: ctxWithTimeout}, prover)
if err != nil {
return false, err
}

// Check prover's taiko token balance
balance, err := rpc.TaikoToken.BalanceOf(&bind.CallOpts{Context: ctxWithTimeout}, prover)
if err != nil {
return false, err
}
log.Info(
"Prover's wallet taiko token balance",
"balance", balance.String(),
"address", prover.Hex(),
"bond", bond.String(),
)

log.Info("Prover's wallet taiko token balance", "balance", balance.String(), "address", prover.Hex())

if bond.Cmp(allowance) > 0 || bond.Cmp(balance) > 0 {
log.Info(
"Assigned prover does not have required on-chain token balance or allowance",
"providedProver", prover.Hex(),
"depositedBalance", depositedBalance.String(),
"taikoTokenBalance", balance,
"allowance", allowance.String(),
"bond", bond,
)
return false, nil
}
if bond.Cmp(allowance) > 0 || bond.Cmp(balance) > 0 {
log.Info(
"Assigned prover does not have required on-chain token balance or allowance",
"providedProver", prover.Hex(),
"taikoTokenBalance", balance,
"allowance", allowance.String(),
"bond", bond,
)
return false, nil
}

return true, nil
Expand Down
2 changes: 2 additions & 0 deletions proposer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Config struct {
TaikoL1Address common.Address
TaikoL2Address common.Address
TaikoTokenAddress common.Address
AssignmentHookAddress common.Address
L1ProposerPrivKey *ecdsa.PrivateKey
ExtraData string
ProposeInterval *time.Duration
Expand Down Expand Up @@ -118,6 +119,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
TaikoL1Address: common.HexToAddress(c.String(flags.TaikoL1Address.Name)),
TaikoL2Address: common.HexToAddress(c.String(flags.TaikoL2Address.Name)),
TaikoTokenAddress: common.HexToAddress(c.String(flags.TaikoTokenAddress.Name)),
AssignmentHookAddress: common.HexToAddress(c.String(flags.ProposerAssignmentHookAddress.Name)),
L1ProposerPrivKey: l1ProposerPrivKey,
ExtraData: c.String(flags.ExtraData.Name),
ProposeInterval: proposingInterval,
Expand Down
1 change: 1 addition & 0 deletions proposer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func (s *ProposerTestSuite) SetupApp() *cli.App {
&cli.Uint64Flag{Name: flags.TierFeePriceBump.Name},
&cli.Uint64Flag{Name: flags.MaxTierFeePriceBumps.Name},
&cli.BoolFlag{Name: flags.ProposeBlockIncludeParentMetaHash.Name},
&cli.StringFlag{Name: flags.ProposerAssignmentHookAddress.Name},
}
app.Action = func(ctx *cli.Context) error {
_, err := NewConfigFromCliContext(ctx)
Expand Down
Loading

0 comments on commit 61c4fcf

Please sign in to comment.