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

Commit

Permalink
feat(bindings): update Go contract bindings for the latest protocol (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Nov 1, 2023
1 parent 9e9c7f3 commit 02c981d
Show file tree
Hide file tree
Showing 29 changed files with 1,783 additions and 942 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: contestable-zkrollup
ref: bridgable_app

- 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 @@
cb43010d59dd532e495167cc51046c2f1073d1c3
0f41cb6d94caf3c0e04f4b63e1cea83024c20869
118 changes: 93 additions & 25 deletions bindings/encoding/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,57 @@ import (

// ABI arguments marshaling components.
var (
evidenceComponents = []abi.ArgumentMarshaling{
blockMetadataComponents = []abi.ArgumentMarshaling{
{
Name: "metaHash",
Name: "l1Hash",
Type: "bytes32",
},
{
Name: "difficulty",
Type: "bytes32",
},
{
Name: "blobHash",
Type: "bytes32",
},
{
Name: "extraData",
Type: "bytes32",
},
{
Name: "depositsHash",
Type: "bytes32",
},
{
Name: "coinbase",
Type: "address",
},
{
Name: "id",
Type: "uint64",
},
{
Name: "gasLimit",
Type: "uint32",
},
{
Name: "timestamp",
Type: "uint64",
},
{
Name: "l1Height",
Type: "uint64",
},
{
Name: "minTier",
Type: "uint16",
},
{
Name: "blobUsed",
Type: "bool",
},
}
transitionComponents = []abi.ArgumentMarshaling{
{
Name: "parentHash",
Type: "bytes32",
Expand All @@ -33,15 +79,28 @@ var (
Name: "graffiti",
Type: "bytes32",
},
}
tierProofComponents = []abi.ArgumentMarshaling{
{
Name: "tier",
Type: "uint16",
},
{
Name: "proof",
Name: "data",
Type: "bytes",
},
}
blockParamsComponents = []abi.ArgumentMarshaling{
{
Name: "assignment",
Type: "tuple",
Components: proverAssignmentComponents,
},
{
Name: "extraData",
Type: "bytes32",
},
}
proverAssignmentComponents = []abi.ArgumentMarshaling{
{
Name: "prover",
Expand All @@ -61,7 +120,7 @@ var (
},
{
Name: "fee",
Type: "uint256",
Type: "uint128",
},
},
},
Expand All @@ -77,12 +136,9 @@ var (
)

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}}
// BlockParams
blockParamsComponentsType, _ = abi.NewType("tuple", "TaikoData.BlockParams", blockParamsComponents)
blockParamsComponentsArgs = abi.Arguments{{Name: "TaikoData.BlockParams", Type: blockParamsComponentsType}}
// ProverAssignmentPayload
stringType, _ = abi.NewType("string", "", nil)
bytes32Type, _ = abi.NewType("bytes32", "", nil)
Expand All @@ -98,17 +154,25 @@ var (
},
{
Name: "fee",
Type: "uint256",
Type: "uint128",
},
},
)
proverAssignmentPayloadArgs = abi.Arguments{
{Name: "PROVER_ASSIGNMENT", Type: stringType},
{Name: "txListHash", Type: bytes32Type},
{Name: "blobHash", Type: bytes32Type},
{Name: "assignment.feeToken", Type: addressType},
{Name: "assignment.expiry", Type: uint64Type},
{Name: "assignment.tierFees", Type: tierFeesType},
}
blockMetadataComponentsType, _ = abi.NewType("tuple", "TaikoData.BlockMetadata", blockMetadataComponents)
transitionComponentsType, _ = abi.NewType("tuple", "TaikoData.Transition", transitionComponents)
tierProofComponentsType, _ = abi.NewType("tuple", "TaikoData.TierProof", tierProofComponents)
proveBlockInputArgs = abi.Arguments{
{Name: "TaikoData.BlockMetadata", Type: blockMetadataComponentsType},
{Name: "TaikoData.Transition", Type: transitionComponentsType},
{Name: "TaikoData.TierProof", Type: tierProofComponentsType},
}
)

// Contract ABIs.
Expand All @@ -129,20 +193,11 @@ func init() {
}
}

// 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
}

// EncodeEvidence performs the solidity `abi.encode` for the given evidence.
func EncodeEvidence(e *BlockEvidence) ([]byte, error) {
b, err := evidenceArgs.Pack(e)
// EncodeBlockParams performs the solidity `abi.encode` for the given blockParams.
func EncodeBlockParams(params *BlockParams) ([]byte, error) {
b, err := blockParamsComponentsArgs.Pack(params)
if err != nil {
return nil, fmt.Errorf("failed to abi.encode evidence, %w", err)
return nil, fmt.Errorf("failed to abi.encode block params, %w", err)
}
return b, nil
}
Expand All @@ -161,6 +216,19 @@ func EncodeProverAssignmentPayload(
return b, nil
}

// EncodeProveBlockInput performs the solidity `abi.encode` for the given TaikoL1.proveBlock input.
func EncodeProveBlockInput(
meta *bindings.TaikoDataBlockMetadata,
transition *bindings.TaikoDataTransition,
tierProof *bindings.TaikoDataTierProof,
) ([]byte, error) {
b, err := proveBlockInputArgs.Pack(meta, transition, tierProof)
if err != nil {
return nil, fmt.Errorf("failed to abi.encode TakoL1.proveBlock input, %w", err)
}
return b, nil
}

// UnpackTxListBytes unpacks the input data of a TaikoL1.proposeBlock transaction, and returns the txList bytes.
func UnpackTxListBytes(txData []byte) ([]byte, error) {
method, err := TaikoL1ABI.MethodById(txData)
Expand Down
39 changes: 2 additions & 37 deletions bindings/encoding/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,19 @@ package encoding

import (
"context"
"math/big"
"math/rand"
"os"
"testing"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/stretchr/testify/require"
"github.com/taikoxyz/taiko-client/bindings"
)

func TestEncodeEvidence(t *testing.T) {
evidence := &BlockEvidence{
MetaHash: randomHash(),
BlockHash: randomHash(),
ParentHash: randomHash(),
SignalRoot: randomHash(),
Graffiti: randomHash(),
Tier: uint16(rand.Uint64()),
Proof: randomHash().Big().Bytes(),
}

b, err := EncodeEvidence(evidence)

require.Nil(t, err)
require.NotEmpty(t, b)
}

func TestEncodeProverAssignment(t *testing.T) {
encoded, err := EncodeProverAssignment(
&ProverAssignment{
Prover: common.BigToAddress(new(big.Int).SetUint64(rand.Uint64())),
FeeToken: common.Address{},
TierFees: []TierFee{{Tier: 0, Fee: common.Big1}},
Signature: randomHash().Big().Bytes(),
Expiry: 1024,
},
)

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

func TestEncodeProverAssignmentPayload(t *testing.T) {
encoded, err := EncodeProverAssignmentPayload(
common.BytesToHash(randomBytes(32)),
Expand Down Expand Up @@ -97,9 +64,7 @@ func TestUnpackTxListBytes(t *testing.T) {

tx, err := taikoL1.ProposeBlock(
opts,
randomHash(),
[32]byte(randomHash().Bytes()),
randomBytes(32),
randomBytes(1024),
txListBytes,
)
require.Nil(t, err)
Expand Down
13 changes: 4 additions & 9 deletions bindings/encoding/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,10 @@ type BlockHeader struct {
BaseFeePerGas *big.Int
}

// BlockEvidence should be same with TaikoData.BlockEvidence.
type BlockEvidence struct {
MetaHash [32]byte
ParentHash [32]byte
BlockHash [32]byte
SignalRoot [32]byte
Graffiti [32]byte
Tier uint16
Proof []byte
// BlockParams should be same with TaikoData.BlockParams.
type BlockParams struct {
Assignment *ProverAssignment
ExtraData [32]byte
}

// TierFee should be same with TaikoData.TierFee.
Expand Down
Loading

0 comments on commit 02c981d

Please sign in to comment.