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

Commit

Permalink
feat(all): changes based on contestable zkRollup protocol design (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Oct 16, 2023
1 parent 4a1012a commit 25a0c3b
Show file tree
Hide file tree
Showing 80 changed files with 5,697 additions and 3,932 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
with:
repository: taikoxyz/taiko-mono
path: ${{ env.TAIKO_MONO_DIR }}
ref: contestable-zkrollup

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ Then, run the integration tests:
2. Perform a `pnpm install` in `taiko-mono/packages/protocol`
3. Replace `<PATH_TO_TAIKO_MONO_REPO>` and execute:

```bash
TAIKO_MONO_DIR=<PATH_TO_TAIKO_MONO_REPO> \
COMPILE_PROTOCOL=true \
make test
```
```sh
TAIKO_MONO_DIR=<PATH_TO_TAIKO_MONO_REPO> make test
```
2 changes: 1 addition & 1 deletion bindings/.githead
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ee2688156733d49cbf43c5178211db95a7079b26
7d947b2850ed84ef9fd12cb9856e71e38157c1b8
254 changes: 60 additions & 194 deletions bindings/encoding/input.go
Original file line number Diff line number Diff line change
@@ -1,103 +1,17 @@
package encoding

import (
"bytes"
"errors"
"fmt"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
"github.com/taikoxyz/taiko-client/bindings"
)

// ABI arguments marshaling components.
var (
blockMetadataInputComponents = []abi.ArgumentMarshaling{
{
Name: "txListHash",
Type: "bytes32",
},
{
Name: "proposer",
Type: "address",
},
{
Name: "txListByteStart",
Type: "uint24",
},
{
Name: "txListByteEnd",
Type: "uint24",
},
{
Name: "cacheTxListInfo",
Type: "bool",
},
}
blockMetadataComponents = []abi.ArgumentMarshaling{
{
Name: "id",
Type: "uint64",
},
{
Name: "timestamp",
Type: "uint64",
},
{
Name: "l1Height",
Type: "uint64",
},
{
Name: "l1Hash",
Type: "bytes32",
},
{
Name: "mixHash",
Type: "bytes32",
},
{
Name: "txListHash",
Type: "bytes32",
},
{
Name: "txListByteStart",
Type: "uint24",
},
{
Name: "txListByteEnd",
Type: "uint24",
},
{
Name: "gasLimit",
Type: "uint32",
},
{
Name: "proposer",
Type: "address",
},
{
Name: "depositsProcessed",
Type: "tuple[]",
Components: []abi.ArgumentMarshaling{
{
Name: "recipient",
Type: "address",
},
{
Name: "amount",
Type: "uint96",
},
{
Name: "id",
Type: "uint64",
},
},
},
}
evidenceComponents = []abi.ArgumentMarshaling{
{
Name: "metaHash",
Expand All @@ -120,11 +34,11 @@ var (
Type: "bytes32",
},
{
Name: "prover",
Type: "address",
Name: "tier",
Type: "uint16",
},
{
Name: "proofs",
Name: "proof",
Type: "bytes",
},
}
Expand All @@ -134,48 +48,67 @@ var (
Type: "address",
},
{
Name: "expiry",
Type: "uint64",
},
{
Name: "data",
Type: "bytes",
},
}
proposeBlockDataComponents = []abi.ArgumentMarshaling{
{
Name: "input",
Type: "tuple",
Components: blockMetadataInputComponents,
Name: "feeToken",
Type: "address",
},
{
Name: "fee",
Type: "uint256",
Name: "tierFees",
Type: "tuple[]",
Components: []abi.ArgumentMarshaling{
{
Name: "tier",
Type: "uint16",
},
{
Name: "fee",
Type: "uint256",
},
},
},

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

var (
// BlockMetadataInput
blockMetadataInputType, _ = abi.NewType("tuple", "TaikoData.BlockMetadataInput", blockMetadataInputComponents)
blockMetadataInputArgs = abi.Arguments{{Name: "BlockMetadataInput", Type: blockMetadataInputType}}
// BlockMetadata
blockMetadataType, _ = abi.NewType("tuple", "TaikoData.BlockMetadata", blockMetadataComponents)
blockMetadataArgs = abi.Arguments{{Name: "BlockMetadata", Type: blockMetadataType}}
// Evidence
EvidenceType, _ = abi.NewType("tuple", "TaikoData.BlockEvidence", evidenceComponents)
EvidenceArgs = abi.Arguments{{Name: "Evidence", Type: EvidenceType}}
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}}
// ProverAssignmentPayload
stringType, _ = abi.NewType("string", "", nil)
bytes32Type, _ = abi.NewType("bytes32", "", nil)
addressType, _ = abi.NewType("address", "", nil)
uint64Type, _ = abi.NewType("uint64", "", nil)
tierFeesType, _ = abi.NewType(
"tuple[]",
"",
[]abi.ArgumentMarshaling{
{
Name: "tier",
Type: "uint16",
},
{
Name: "fee",
Type: "uint256",
},
},
)
proverAssignmentPayloadArgs = abi.Arguments{
{Name: "PROVER_ASSIGNMENT", Type: stringType},
{Name: "txListHash", Type: bytes32Type},
{Name: "assignment.feeToken", Type: addressType},
{Name: "assignment.expiry", Type: uint64Type},
{Name: "assignment.tierFees", Type: tierFeesType},
}
)

// Contract ABIs.
Expand All @@ -196,24 +129,6 @@ func init() {
}
}

// EncodeBlockMetadataInput performs the solidity `abi.encode` for the given blockMetadataInput.
func EncodeBlockMetadataInput(meta *TaikoL1BlockMetadataInput) ([]byte, error) {
b, err := blockMetadataInputArgs.Pack(meta)
if err != nil {
return nil, fmt.Errorf("failed to abi.encode block metadata input, %w", err)
}
return b, nil
}

// EncodeBlockMetadata performs the solidity `abi.encode` for the given blockMetadata.
func EncodeBlockMetadata(meta *bindings.TaikoDataBlockMetadata) ([]byte, error) {
b, err := blockMetadataArgs.Pack(meta)
if err != nil {
return nil, fmt.Errorf("failed to abi.encode block metadata, %w", err)
}
return b, nil
}

// EncodeProverAssignment performs the solidity `abi.encode` for the given proverAssignment.
func EncodeProverAssignment(assignment *ProverAssignment) ([]byte, error) {
b, err := proverAssignmentArgs.Pack(assignment)
Expand All @@ -223,76 +138,27 @@ func EncodeProverAssignment(assignment *ProverAssignment) ([]byte, error) {
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)
func EncodeEvidence(e *BlockEvidence) ([]byte, error) {
b, err := evidenceArgs.Pack(e)
if err != nil {
return nil, fmt.Errorf("failed to abi.encode evidence, %w", err)
}
return b, nil
}

// EncodeCommitHash performs the solidity `abi.encodePacked` for the given
// commitHash components.
func EncodeCommitHash(beneficiary common.Address, txListHash [32]byte) []byte {
// keccak256(abi.encodePacked(beneficiary, txListHash));
return crypto.Keccak256(
bytes.Join([][]byte{beneficiary.Bytes(), txListHash[:]}, nil),
)
}

// EncodeProposeBlockInput encodes the input params for TaikoL1.proposeBlock.
func EncodeProposeBlockInput(metadataInput *TaikoL1BlockMetadataInput) ([]byte, error) {
metaBytes, err := EncodeBlockMetadataInput(metadataInput)
if err != nil {
return nil, err
}
return metaBytes, nil
}

// EncodeProveBlockInput encodes the input params for TaikoL1.proveBlock.
func EncodeProveBlockInput(
evidence *TaikoL1Evidence,
// EncodeProverAssignmentPayload performs the solidity `abi.encode` for the given proverAssignment payload.
func EncodeProverAssignmentPayload(
txListHash common.Hash,
feeToken common.Address,
expiry uint64,
tierFees []TierFee,
) ([]byte, error) {
evidenceBytes, err := EncodeEvidence(evidence)
b, err := proverAssignmentPayloadArgs.Pack("PROVER_ASSIGNMENT", txListHash, feeToken, expiry, tierFees)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to abi.encode prover assignment hash payload, %w", err)
}

return evidenceBytes, nil
}

// EncodeProveBlockInvalidInput encodes the input params for TaikoL1.proveBlockInvalid.
func EncodeProveBlockInvalidInput(
evidence *TaikoL1Evidence,
target *bindings.TaikoDataBlockMetadata,
receipt *types.Receipt,
) ([][]byte, error) {
evidenceBytes, err := EncodeEvidence(evidence)
if err != nil {
return nil, err
}

metaBytes, err := EncodeBlockMetadata(target)
if err != nil {
return nil, err
}

receiptBytes, err := rlp.EncodeToBytes(receipt)
if err != nil {
return nil, err
}

return [][]byte{evidenceBytes, metaBytes, receiptBytes}, nil
return b, nil
}

// UnpackTxListBytes unpacks the input data of a TaikoL1.proposeBlock transaction, and returns the txList bytes.
Expand Down
Loading

0 comments on commit 25a0c3b

Please sign in to comment.