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

Commit

Permalink
feat(all): update bindings based on latest tokenomics changes (#367)
Browse files Browse the repository at this point in the history
Co-authored-by: jeff <[email protected]>
Co-authored-by: Jeffery Walsh <[email protected]>
  • Loading branch information
3 people authored Aug 29, 2023
1 parent dca8fee commit 28ea4db
Show file tree
Hide file tree
Showing 51 changed files with 4,511 additions and 2,979 deletions.
2 changes: 1 addition & 1 deletion bindings/.githead
Original file line number Diff line number Diff line change
@@ -1 +1 @@
55be84a00af93ff248059a86546f215a8702e95b
437763a729bbf02cbf588559a20cc354f19b1677
60 changes: 51 additions & 9 deletions bindings/encoding/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ var (
Name: "beneficiary",
Type: "address",
},
{
Name: "treasury",
Type: "address",
},
{
Name: "depositsProcessed",
Type: "tuple[]",
Expand Down Expand Up @@ -128,18 +124,40 @@ var (
Type: "address",
},
{
Name: "parentGasUsed",
Type: "uint32",
Name: "proofs",
Type: "bytes",
},
}
proverAssignmentComponents = []abi.ArgumentMarshaling{
{
Name: "gasUsed",
Type: "uint32",
Name: "prover",
Type: "address",
},
{
Name: "expiry",
Type: "uint64",
},
{
Name: "proof",
Name: "data",
Type: "bytes",
},
}
proposeBlockDataComponents = []abi.ArgumentMarshaling{
{
Name: "input",
Type: "tuple",
Components: blockMetadataInputComponents,
},
{
Name: "fee",
Type: "uint256",
},

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

var (
Expand All @@ -152,6 +170,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 @@ -190,6 +214,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
214 changes: 109 additions & 105 deletions bindings/encoding/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
"github.com/taikoxyz/taiko-client/bindings"
)

func TestEncodeEvidence(t *testing.T) {
evidence := &TaikoL1Evidence{
MetaHash: randomHash(),
BlockHash: randomHash(),
ParentHash: randomHash(),
SignalRoot: randomHash(),
Graffiti: randomHash(),
Prover: common.BigToAddress(new(big.Int).SetUint64(rand.Uint64())),
ParentGasUsed: 1024,
GasUsed: 1024,
Proof: randomHash().Big().Bytes(),
MetaHash: randomHash(),
BlockHash: randomHash(),
ParentHash: randomHash(),
SignalRoot: randomHash(),
Graffiti: randomHash(),
Prover: common.BigToAddress(new(big.Int).SetUint64(rand.Uint64())),
Proofs: randomHash().Big().Bytes(),
}

b, err := EncodeEvidence(evidence)
Expand All @@ -44,15 +43,26 @@ func TestEncodeProposeBlockInput(t *testing.T) {
func TestEncodeProveBlockInput(t *testing.T) {
encoded, err := EncodeProveBlockInput(
&TaikoL1Evidence{
MetaHash: randomHash(),
BlockHash: randomHash(),
ParentHash: randomHash(),
SignalRoot: randomHash(),
Graffiti: randomHash(),
Prover: common.BigToAddress(new(big.Int).SetUint64(rand.Uint64())),
ParentGasUsed: 1024,
GasUsed: 1024,
Proof: randomHash().Big().Bytes(),
MetaHash: randomHash(),
BlockHash: randomHash(),
ParentHash: randomHash(),
SignalRoot: randomHash(),
Graffiti: randomHash(),
Prover: common.BigToAddress(new(big.Int).SetUint64(rand.Uint64())),
Proofs: randomHash().Big().Bytes(),
},
)

require.Nil(t, err)
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,
},
)

Expand All @@ -63,15 +73,13 @@ func TestEncodeProveBlockInput(t *testing.T) {
func TestEncodeProveBlockInvalidInput(t *testing.T) {
encoded, err := EncodeProveBlockInvalidInput(
&TaikoL1Evidence{
MetaHash: randomHash(),
BlockHash: randomHash(),
ParentHash: randomHash(),
SignalRoot: randomHash(),
Graffiti: randomHash(),
Prover: common.BigToAddress(new(big.Int).SetUint64(rand.Uint64())),
ParentGasUsed: 1024,
GasUsed: 1024,
Proof: randomHash().Big().Bytes(),
MetaHash: randomHash(),
BlockHash: randomHash(),
ParentHash: randomHash(),
SignalRoot: randomHash(),
Graffiti: randomHash(),
Prover: common.BigToAddress(new(big.Int).SetUint64(rand.Uint64())),
Proofs: randomHash().Big().Bytes(),
},
&testMeta,
types.NewReceipt(randomHash().Bytes(), false, 1024),
Expand All @@ -81,84 +89,80 @@ func TestEncodeProveBlockInvalidInput(t *testing.T) {
require.NotNil(t, encoded)
}

// TODO(Roger): fix this test
// func TestEncodeBlockMetadata(t *testing.T) {
// // since strings are right padded in solidity https://github.com/ethereum/solidity/issues/1340
// var abcdBytes [32]byte
// copy(abcdBytes[:], common.RightPadBytes([]byte("abcd"), 32))

// // Encode block metadata using EncodeBlockMetadata function
// encoded, err := EncodeBlockMetadata(&bindings.TaikoDataBlockMetadata{
// Id: uint64(1),
// L1Height: uint64(1),
// L1Hash: abcdBytes,
// Beneficiary: common.HexToAddress("0x10020FCb72e27650651B05eD2CEcA493bC807Ba4"),
// Treasury: common.HexToAddress("0x50081b12838240B1bA02b3177153Bca678a86078"),
// TxListHash: abcdBytes,
// TxListByteStart: big.NewInt(0),
// TxListByteEnd: big.NewInt(1000),
// GasLimit: 1,
// MixHash: abcdBytes,
// Timestamp: uint64(1),
// DepositsProcessed: []bindings.TaikoDataEthDeposit{},
// })

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

// kgv, err := hexutil.Decode("0x0000000000000000000000000000000000000000000000000" +
// "000000000000020000000000000000000000000000000000000000000000000000000000000000" +
// "100000000000000000000000000000000000000000000000000000000000000010000000000000" +
// "000000000000000000000000000000000000000000000000001616263640000000000000000000" +
// "000000000000000000000000000000000000061626364000000000000000000000000000000000" +
// "000000000000000000000006162636400000000000000000000000000000000000000000000000" +
// "000000000000000000000000000000000000000000000000000000000000000000000000000000" +
// "000000000000000000000000000000000000000000000000000000003e80000000000000000000" +
// "00000000000000000000000000000000000000000000100000000000000000000000010020fcb7" +
// "2e27650651b05ed2ceca493bc807ba400000000000000000000000050081b12838240b1ba02b31" +
// "77153bca678a860780000000000000000000000000000000000000000000000000000000000000" +
// "1800000000000000000000000000000000000000000000000000000000000000000")

// require.Nil(t, err)
// require.Equal(t, kgv, encoded)

// encoded2, err := EncodeBlockMetadata(&bindings.TaikoDataBlockMetadata{
// Id: uint64(1),
// L1Height: uint64(1),
// L1Hash: abcdBytes,
// Beneficiary: common.HexToAddress("0x10020FCb72e27650651B05eD2CEcA493bC807Ba4"),
// Treasury: common.HexToAddress("0x50081b12838240B1bA02b3177153Bca678a86078"),
// TxListHash: abcdBytes,
// TxListByteStart: big.NewInt(0),
// TxListByteEnd: big.NewInt(1000),
// GasLimit: 1,
// MixHash: abcdBytes,
// Timestamp: uint64(1),
// DepositsProcessed: []bindings.TaikoDataEthDeposit{
// {Recipient: common.HexToAddress("0x10020FCb72e27650651B05eD2CEcA493bC807Ba4"), Amount: big.NewInt(2)},
// },
// })

// require.Nil(t, err)
// require.NotNil(t, encoded2)

// kgv2, err := hexutil.Decode("0x0000000000000000000000000000000000000000000000000" +
// "0000000000000200000000000000000000000000000000000000000000000000000000000000001000" +
// "0000000000000000000000000000000000000000000000000000000000001000000000000000000000" +
// "0000000000000000000000000000000000000000001616263640000000000000000000000000000000" +
// "0000000000000000000000000616263640000000000000000000000000000000000000000000000000" +
// "0000000616263640000000000000000000000000000000000000000000000000000000000000000000" +
// "0000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
// "000000000000000000000000000000003e800000000000000000000000000000000000000000000000" +
// "0000000000000000100000000000000000000000010020fcb72e27650651b05ed2ceca493bc807ba40" +
// "0000000000000000000000050081b12838240b1ba02b3177153bca678a860780000000000000000000" +
// "0000000000000000000000000000000000000000001800000000000000000000000000000000000000" +
// "00000000000000000000000000100000000000000000000000010020fcb72e27650651b05ed2ceca49" +
// "3bc807ba40000000000000000000000000000000000000000000000000000000000000002")

// require.Nil(t, err)
// require.Equal(t, kgv2, encoded2)
// }
func TestEncodeBlockMetadata(t *testing.T) {
// since strings are right padded in solidity https://github.com/ethereum/solidity/issues/1340
var abcdBytes [32]byte
copy(abcdBytes[:], common.RightPadBytes([]byte("abcd"), 32))

// Encode block metadata using EncodeBlockMetadata function
encoded, err := EncodeBlockMetadata(&bindings.TaikoDataBlockMetadata{
Id: uint64(1),
L1Height: uint64(1),
L1Hash: abcdBytes,
Beneficiary: common.HexToAddress("0x10020FCb72e27650651B05eD2CEcA493bC807Ba4"),
TxListHash: abcdBytes,
TxListByteStart: big.NewInt(0),
TxListByteEnd: big.NewInt(1000),
GasLimit: 1,
MixHash: abcdBytes,
Timestamp: uint64(1),
DepositsProcessed: []bindings.TaikoDataEthDeposit{},
})

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

kgv, err := hexutil.Decode("0x00000000000000000000000000000000000000000000000000000000" +
"0000002000000000000000000000000000000000000000000000000000000000000000010000000000000" +
"0000000000000000000000000000000000000000000000000010000000000000000000000000000000000" +
"0000000000000000000000000000016162636400000000000000000000000000000000000000000000000" +
"0000000006162636400000000000000000000000000000000000000000000000000000000616263640000" +
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
"00000003e8000000000000000000000000000000000000000000000000000000000000000100000000000" +
"000000000000010020fcb72e27650651b05ed2ceca493bc807ba400000000000000000000000000000000" +
"0000000000000000000000000000016000000000000000000000000000000000000000000000000000000" +
"00000000000")

require.Nil(t, err)
require.Equal(t, kgv, encoded)

encoded2, err := EncodeBlockMetadata(&bindings.TaikoDataBlockMetadata{
Id: uint64(1),
L1Height: uint64(1),
L1Hash: abcdBytes,
Beneficiary: common.HexToAddress("0x10020FCb72e27650651B05eD2CEcA493bC807Ba4"),
TxListHash: abcdBytes,
TxListByteStart: big.NewInt(0),
TxListByteEnd: big.NewInt(1000),
GasLimit: 1,
MixHash: abcdBytes,
Timestamp: uint64(1),
DepositsProcessed: []bindings.TaikoDataEthDeposit{
{Recipient: common.HexToAddress("0x10020FCb72e27650651B05eD2CEcA493bC807Ba4"), Amount: big.NewInt(2), Id: uint64(1)},
},
})

require.Nil(t, err)
require.NotNil(t, encoded2)

kgv2, err := hexutil.Decode("0x0000000000000000000000000000000000000000000000000000000" +
"0000000200000000000000000000000000000000000000000000000000000000000000001000000000000" +
"0000000000000000000000000000000000000000000000000001000000000000000000000000000000000" +
"0000000000000000000000000000001616263640000000000000000000000000000000000000000000000" +
"0000000000616263640000000000000000000000000000000000000000000000000000000061626364000" +
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
"000000003e800000000000000000000000000000000000000000000000000000000000000010000000000" +
"0000000000000010020fcb72e27650651b05ed2ceca493bc807ba40000000000000000000000000000000" +
"0000000000000000000000000000001600000000000000000000000000000000000000000000000000000" +
"00000000000100000000000000000000000010020fcb72e27650651b05ed2ceca493bc807ba4000000000" +
"0000000000000000000000000000000000000000000000000000002000000000000000000000000000000" +
"0000000000000000000000000000000001")

require.Nil(t, err)
require.Equal(t, kgv2, encoded2)
}

func TestUnpackTxListBytes(t *testing.T) {
_, err := UnpackTxListBytes(randomBytes(1024))
Expand Down
28 changes: 19 additions & 9 deletions bindings/encoding/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ type BlockHeader struct {
}

type TaikoL1Evidence struct {
MetaHash [32]byte
BlockHash [32]byte
ParentHash [32]byte
SignalRoot [32]byte
Graffiti [32]byte
Prover common.Address
ParentGasUsed uint32
GasUsed uint32
Proof []byte
MetaHash [32]byte
BlockHash [32]byte
ParentHash [32]byte
SignalRoot [32]byte
Graffiti [32]byte
Prover common.Address
Proofs []byte
}

type TaikoL1BlockMetadataInput struct {
Expand All @@ -51,6 +49,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
1 change: 0 additions & 1 deletion bindings/encoding/struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ var (
TxListByteEnd: common.Big256,
GasLimit: rand.Uint32(),
Beneficiary: common.BytesToAddress(randomHash().Bytes()),
Treasury: common.BytesToAddress(randomHash().Bytes()),
DepositsProcessed: []bindings.TaikoDataEthDeposit{},
}
)
Expand Down
Loading

0 comments on commit 28ea4db

Please sign in to comment.