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 (#697)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Apr 8, 2024
1 parent 7a68a25 commit 993d491
Show file tree
Hide file tree
Showing 30 changed files with 265 additions and 261 deletions.
2 changes: 1 addition & 1 deletion bindings/.githead
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b341a68d53b01087a6ce56a629b064d0b808b0bb
2c63cb0c796495948f1dd887662044397394d852
56 changes: 33 additions & 23 deletions bindings/encoding/input.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package encoding

import (
"bytes"
"encoding/binary"
"errors"
"fmt"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"

"github.com/taikoxyz/taiko-client/bindings"
)

// ABI arguments marshaling components.
var (
blockMetadataComponents = []abi.ArgumentMarshaling{
assignmentPayloadPrefix = "PROVER_ASSIGNMENT"
assignmentPayloadPrefixSize = len([]byte(assignmentPayloadPrefix))
paddedAssignmentPayloadPrefixBytes = common.LeftPadBytes([]byte(assignmentPayloadPrefix), assignmentPayloadPrefixSize)
blockMetadataComponents = []abi.ArgumentMarshaling{
{
Name: "l1Hash",
Type: "bytes32",
Expand Down Expand Up @@ -198,7 +204,6 @@ var (
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)
addressType, _ = abi.NewType("address", "", nil)
uint64Type, _ = abi.NewType("uint64", "", nil)
Expand All @@ -216,19 +221,14 @@ var (
},
},
)
proverAssignmentPayloadArgs = abi.Arguments{
{Name: "PROVER_ASSIGNMENT", Type: stringType},
{Name: "chainID", Type: uint64Type},
{Name: "taikoAddress", Type: addressType},
{Name: "assignmentHookAddress", Type: addressType},
{Name: "metaHash", Type: bytes32Type},
{Name: "parentMetaHash", Type: bytes32Type},
{Name: "blobHash", Type: bytes32Type},
{Name: "assignment.feeToken", Type: addressType},
{Name: "assignment.expiry", Type: uint64Type},
{Name: "assignment.maxBlockId", Type: uint64Type},
{Name: "assignment.maxProposedIn", Type: uint64Type},
{Name: "assignment.tierFees", Type: tierFeesType},
proverAssignmentHashPayloadArgs = abi.Arguments{
{Name: "_assignment.metaHash", Type: bytes32Type},
{Name: "_assignment.parentMetaHash", Type: bytes32Type},
{Name: "_assignment.feeToken", Type: addressType},
{Name: "_assignment.expiry", Type: uint64Type},
{Name: "_assignment.maxBlockId", Type: uint64Type},
{Name: "_assignment.maxProposedIn", Type: uint64Type},
{Name: "_assignment.tierFees", Type: tierFeesType},
}
blockMetadataComponentsType, _ = abi.NewType("tuple", "TaikoData.BlockMetadata", blockMetadataComponents)
transitionComponentsType, _ = abi.NewType("tuple", "TaikoData.Transition", transitionComponents)
Expand Down Expand Up @@ -341,21 +341,18 @@ func EncodeProverAssignmentPayload(
chainID uint64,
taikoAddress common.Address,
assignmentHookAddress common.Address,
txListHash common.Hash,
blockProposer common.Address,
assignedProver common.Address,
blobHash common.Hash,
feeToken common.Address,
expiry uint64,
maxBlockID uint64,
maxProposedIn uint64,
tierFees []TierFee,
) ([]byte, error) {
b, err := proverAssignmentPayloadArgs.Pack(
"PROVER_ASSIGNMENT",
chainID,
taikoAddress,
assignmentHookAddress,
hashBytesPayload, err := proverAssignmentHashPayloadArgs.Pack(
common.Hash{},
common.Hash{},
txListHash,
feeToken,
expiry,
maxBlockID,
Expand All @@ -365,7 +362,20 @@ func EncodeProverAssignmentPayload(
if err != nil {
return nil, fmt.Errorf("failed to abi.encode prover assignment hash payload, %w", err)
}
return b, nil

chainIDBytes := make([]byte, 8)
binary.BigEndian.PutUint64(chainIDBytes, chainID)

return bytes.Join([][]byte{
paddedAssignmentPayloadPrefixBytes[len(paddedAssignmentPayloadPrefixBytes)-assignmentPayloadPrefixSize:],
chainIDBytes,
taikoAddress.Bytes(),
blockProposer.Bytes(),
assignedProver.Bytes(),
blobHash.Bytes(),
crypto.Keccak256Hash(hashBytesPayload).Bytes(),
assignmentHookAddress.Bytes(),
}, nil), nil
}

// EncodeProveBlockInput performs the solidity `abi.encode` for the given TaikoL1.proveBlock input.
Expand Down
2 changes: 2 additions & 0 deletions bindings/encoding/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ func TestEncodeProverAssignmentPayload(t *testing.T) {
randomHash().Big().Uint64(),
common.BytesToAddress(randomBytes(20)),
common.BytesToAddress(randomBytes(20)),
common.BytesToAddress(randomBytes(20)),
common.BytesToAddress(randomBytes(20)),
common.BytesToHash(randomBytes(32)),
common.BytesToAddress(randomBytes(20)),
120,
Expand Down
2 changes: 1 addition & 1 deletion bindings/gen_address_manager.go

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

Loading

0 comments on commit 993d491

Please sign in to comment.