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

Commit

Permalink
feat(prover): guardian prover block signature && bindings updates for…
Browse files Browse the repository at this point in the history
… based contestable zkRollup (#450)

Co-authored-by: Roger <50648015+RogerLamTd@users.noreply.github.com>
  • Loading branch information
cyberhorsey and RogerLamTd authored Nov 25, 2023
1 parent 0ee8259 commit 904d3e7
Show file tree
Hide file tree
Showing 43 changed files with 2,546 additions and 519 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: bridgable_app
ref: update_relayer_eventindexer_post_hooks

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.dylib
bin
coverage.out
prover/dbPath

# Test binary, built with `go test -c`
*.test
Expand Down
2 changes: 1 addition & 1 deletion bindings/.githead
Original file line number Diff line number Diff line change
@@ -1 +1 @@
205eb2c49f2364ffe382408577040767a69c5a03
8a27392aead6350fd00d8add2ab0a459808e6160
5 changes: 5 additions & 0 deletions bindings/encoding/custom_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import (
func TryParsingCustomError(originalError error) error {
errData := getErrorData(originalError)

// if errData is unparsable and returns 0x, we should not match any errors.
if errData == "0x" {
return originalError
}

for _, l1CustomError := range TaikoL1ABI.Errors {
if strings.HasPrefix(l1CustomError.ID.Hex(), errData) {
return errors.New(l1CustomError.Name)
Expand Down
10 changes: 10 additions & 0 deletions bindings/encoding/custom_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ func (e *testJsonError) Error() string { return common.Bytes2Hex(randomBytes(10)

func (e *testJsonError) ErrorData() interface{} { return "0x8a1c400f" }

type emptyTestJsonError struct{}

func (e *emptyTestJsonError) Error() string { return "execution reverted" }

func (e *emptyTestJsonError) ErrorData() interface{} { return "0x" }

func TestTryParsingCustomError(t *testing.T) {
randomErr := common.Bytes2Hex(randomBytes(10))
require.Equal(t, randomErr, TryParsingCustomError(errors.New(randomErr)).Error())
Expand All @@ -29,4 +35,8 @@ func TestTryParsingCustomError(t *testing.T) {
err = TryParsingCustomError(&testJsonError{})

require.True(t, strings.HasPrefix(err.Error(), "L1_INVALID_BLOCK_ID"))

err = TryParsingCustomError(&emptyTestJsonError{})

require.Equal(t, err.Error(), "execution reverted")
}
74 changes: 62 additions & 12 deletions bindings/encoding/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ var (
Name: "blobUsed",
Type: "bool",
},
{
Name: "parentMetaHash",
Type: "bytes32",
},
}
transitionComponents = []abi.ArgumentMarshaling{
{
Expand Down Expand Up @@ -100,9 +104,8 @@ var (
}
blockParamsComponents = []abi.ArgumentMarshaling{
{
Name: "assignment",
Type: "tuple",
Components: proverAssignmentComponents,
Name: "assignedProver",
Type: "address",
},
{
Name: "extraData",
Expand All @@ -124,15 +127,45 @@ var (
Name: "cacheBlobForReuse",
Type: "bool",
},
{
Name: "parentMetaHash",
Type: "bytes32",
},
{
Name: "hookCalls",
Type: "tuple[]",
Components: []abi.ArgumentMarshaling{
{
Name: "hook",
Type: "address",
},
{
Name: "data",
Type: "bytes",
},
},
},
}
proverAssignmentComponents = []abi.ArgumentMarshaling{
{
Name: "prover",
Name: "feeToken",
Type: "address",
},
{
Name: "feeToken",
Type: "address",
Name: "expiry",
Type: "uint64",
},
{
Name: "maxBlockId",
Type: "uint64",
},
{
Name: "maxProposedIn",
Type: "uint64",
},
{
Name: "metaHash",
Type: "bytes32",
},
{
Name: "tierFees",
Expand All @@ -149,22 +182,27 @@ var (
},
},
{
Name: "expiry",
Type: "uint64",
Name: "signature",
Type: "bytes",
},
}
assignmentHookInputComponents = []abi.ArgumentMarshaling{
{
Name: "maxBlockId",
Type: "uint64",
Name: "assignment",
Type: "tuple",
Components: proverAssignmentComponents,
},
{
Name: "signature",
Type: "bytes",
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 @@ -193,6 +231,7 @@ var (
{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)
Expand Down Expand Up @@ -232,13 +271,23 @@ 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,
txListHash common.Hash,
feeToken common.Address,
expiry uint64,
maxBlockID uint64,
maxProposedIn uint64,
tierFees []TierFee,
) ([]byte, error) {
b, err := proverAssignmentPayloadArgs.Pack(
Expand All @@ -248,6 +297,7 @@ func EncodeProverAssignmentPayload(
feeToken,
expiry,
maxBlockID,
maxProposedIn,
tierFees,
)
if err != nil {
Expand Down
20 changes: 20 additions & 0 deletions bindings/encoding/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package encoding

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

Expand All @@ -22,13 +23,32 @@ func TestEncodeProverAssignmentPayload(t *testing.T) {
common.BytesToAddress(randomBytes(20)),
120,
1024,
0,
[]TierFee{{Tier: 0, Fee: common.Big1}},
)

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

func TestEncodeAssignmentHookInput(t *testing.T) {
encoded, err := EncodeAssignmentHookInput(&AssignmentHookInput{
Assignment: &ProverAssignment{
FeeToken: common.Address{},
Expiry: 1,
MaxBlockId: 1,
MaxProposedIn: 1,
MetaHash: [32]byte{0xff},
TierFees: []TierFee{{Tier: 0, Fee: common.Big1}},
Signature: []byte{0xff},
},
Tip: big.NewInt(1),
})

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

func TestUnpackTxListBytes(t *testing.T) {
_, err := UnpackTxListBytes(randomBytes(1024))
require.NotNil(t, err)
Expand Down
29 changes: 22 additions & 7 deletions bindings/encoding/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +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 @@ -56,12 +64,19 @@ 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
Signature []byte
FeeToken common.Address
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.
Expand Down
Loading

0 comments on commit 904d3e7

Please sign in to comment.