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

feat(prover): integrate new anchor transaction circuits #308

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions bindings/encoding/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ var (
},
},
}
depositsProcessedComponents = []abi.ArgumentMarshaling{
{
Name: "recipient",
Type: "address",
},
{
Name: "amount",
Type: "uint96",
},
{
Name: "id",
Type: "uint64",
},
}
evidenceComponents = []abi.ArgumentMarshaling{
{
Name: "metaHash",
Expand Down Expand Up @@ -160,6 +174,9 @@ var (
// Evidence
EvidenceType, _ = abi.NewType("tuple", "TaikoData.BlockEvidence", evidenceComponents)
EvidenceArgs = abi.Arguments{{Name: "Evidence", Type: EvidenceType}}
// DepositsProcessed
DepositsProcessedType, _ = abi.NewType("tuple[]", "TaikoData.EthDeposit[]", depositsProcessedComponents)
DepositsProcessedArgs = abi.Arguments{{Name: "DepositsProcessed", Type: DepositsProcessedType}}
)

// Contract ABIs.
Expand Down Expand Up @@ -237,6 +254,15 @@ func EncodeProveBlockInput(
return evidenceBytes, nil
}

// EncodeDepositsProcessed performs the solidity `abi.encode` for the given deposits.
func EncodeDepositsProcessed(deposits []bindings.TaikoDataEthDeposit) ([]byte, error) {
b, err := DepositsProcessedArgs.Pack(deposits)
if err != nil {
return nil, fmt.Errorf("failed to abi.encode deposits, %w", err)
}
return b, nil
}

// EncodeProveBlockInvalidInput encodes the input params for TaikoL1.proveBlockInvalid.
func EncodeProveBlockInvalidInput(
evidence *TaikoL1Evidence,
Expand Down
8 changes: 8 additions & 0 deletions bindings/encoding/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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) {
Expand Down Expand Up @@ -42,6 +43,13 @@ func TestEncodeProposeBlockInput(t *testing.T) {
require.NotNil(t, encoded)
}

func TestEncodeDepositsProcessed(t *testing.T) {
encoded, err := EncodeDepositsProcessed([]bindings.TaikoDataEthDeposit{})

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

func TestEncodeProveBlockInput(t *testing.T) {
encoded, err := EncodeProveBlockInput(
&TaikoL1Evidence{
Expand Down
3 changes: 2 additions & 1 deletion prover/proof_producer/proof_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ type ProofRequestOptions struct {
L1SignalService common.Address
L2SignalService common.Address
TaikoL2 common.Address
MetaHash common.Hash
MetaData *bindings.TaikoDataBlockMetadata
BlockHash common.Hash
ParentHash common.Hash
SignalRoot common.Hash
Graffiti string
GasUsed uint64
ParentGasUsed uint64
AnchorGasLimit uint64
}

type ProofWithHeader struct {
Expand Down
75 changes: 56 additions & 19 deletions prover/proof_producer/zkevm_rpcd_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
"github.com/cenkalti/backoff/v4"
"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/taikoxyz/taiko-client/bindings"
"github.com/taikoxyz/taiko-client/bindings/encoding"
)

var (
Expand Down Expand Up @@ -59,20 +61,36 @@ type RequestProofBodyParam struct {

// RequestProofBody represents the JSON body of RequestProofBody.Param's `protocol_instance` field.
type ProtocolInstance struct {
L1SignalService string `json:"l1_signal_service"`
L2SignalService string `json:"l2_signal_service"`
TaikoL2 string `json:"l2_contract"`
MetaHash string `json:"meta_hash"`
BlockHash string `json:"block_hash"`
ParentHash string `json:"parent_hash"`
SignalRoot string `json:"signal_root"`
Graffiti string `json:"graffiti"`
Prover string `json:"prover"`
GasUsed uint64 `json:"gas_used"`
ParentGasUsed uint64 `json:"parent_gas_used"`
BlockMaxGasLimit uint64 `json:"block_max_gas_limit"`
MaxTransactionsPerBlock uint64 `json:"max_transactions_per_block"`
MaxBytesPerTxList uint64 `json:"max_bytes_per_tx_list"`
L1SignalService string `json:"l1_signal_service"`
L2SignalService string `json:"l2_signal_service"`
TaikoL2 string `json:"l2_contract"`
MetaData *RequestProofMetaData `json:"meta_data"`
BlockHash string `json:"block_hash"`
ParentHash string `json:"parent_hash"`
SignalRoot string `json:"signal_root"`
Graffiti string `json:"graffiti"`
Prover string `json:"prover"`
GasUsed uint64 `json:"gas_used"`
ParentGasUsed uint64 `json:"parent_gas_used"`
BlockMaxGasLimit uint64 `json:"block_max_gas_limit"`
MaxTransactionsPerBlock uint64 `json:"max_transactions_per_block"`
MaxBytesPerTxList uint64 `json:"max_bytes_per_tx_list"`
AnchorGasLimit uint64 `json:"anchor_gas_limit"`
}

type RequestProofMetaData struct {
ID uint64 `json:"id"`
Timestamp uint64 `json:"timestamp"`
L1Height uint64 `json:"l1_height"`
L1Hash string `json:"l1_hash"`
L1MixHash string `json:"l1_mix_hash"`
DepositsProcessed string `json:"deposits_processed"`
TxListHash string `json:"tx_list_hash"`
TxListByteStart uint32 `json:"tx_list_byte_start"`
TxListByteEnd uint32 `json:"tx_list_byte_end"`
GasLimit uint32 `json:"gas_limit"`
Beneficiary string `json:"beneficiary"`
Treasury string `json:"treasury"`
}

// RequestProofBodyResponse represents the JSON body of the response of the proof requests.
Expand Down Expand Up @@ -204,6 +222,11 @@ func (p *ZkevmRpcdProducer) callProverDaemon(ctx context.Context, opts *ProofReq

// requestProof sends a RPC request to proverd to try to get the requested proof.
func (p *ZkevmRpcdProducer) requestProof(opts *ProofRequestOptions) (*RpcdOutput, error) {
abiEncodedDeposits, err := encoding.EncodeDepositsProcessed(opts.MetaData.DepositsProcessed)
if err != nil {
return nil, err
}

reqBody := RequestProofBody{
JsonRPC: "2.0",
ID: common.Big1,
Expand All @@ -219,11 +242,24 @@ func (p *ZkevmRpcdProducer) requestProof(opts *ProofRequestOptions) (*RpcdOutput
MockFeedback: false,
Aggregate: true,
ProtocolInstance: &ProtocolInstance{
Prover: opts.ProverAddress.Hex()[2:],
L1SignalService: opts.L1SignalService.Hex()[2:],
L2SignalService: opts.L2SignalService.Hex()[2:],
TaikoL2: opts.TaikoL2.Hex()[2:],
MetaHash: opts.MetaHash.Hex()[2:],
Prover: opts.ProverAddress.Hex()[2:],
L1SignalService: opts.L1SignalService.Hex()[2:],
L2SignalService: opts.L2SignalService.Hex()[2:],
TaikoL2: opts.TaikoL2.Hex()[2:],
MetaData: &RequestProofMetaData{
ID: opts.MetaData.Id,
Timestamp: opts.MetaData.Timestamp,
L1Height: opts.MetaData.L1Height,
L1Hash: common.Bytes2Hex(opts.MetaData.L1Hash[:]),
L1MixHash: common.Bytes2Hex(opts.MetaData.MixHash[:]),
DepositsProcessed: crypto.Keccak256Hash(abiEncodedDeposits).Hex()[2:],
TxListHash: common.Bytes2Hex(opts.MetaData.TxListHash[:]),
TxListByteStart: uint32(opts.MetaData.TxListByteStart.Uint64()),
TxListByteEnd: uint32(opts.MetaData.TxListByteEnd.Uint64()),
GasLimit: opts.MetaData.GasLimit,
Beneficiary: opts.MetaData.Beneficiary.Hex()[2:],
Treasury: opts.MetaData.Treasury.Hex()[2:],
},
BlockHash: opts.BlockHash.Hex()[2:],
ParentHash: opts.ParentHash.Hex()[2:],
SignalRoot: opts.SignalRoot.Hex()[2:],
Expand All @@ -233,6 +269,7 @@ func (p *ZkevmRpcdProducer) requestProof(opts *ProofRequestOptions) (*RpcdOutput
BlockMaxGasLimit: uint64(p.ProtocolConfig.BlockMaxGasLimit),
MaxTransactionsPerBlock: p.ProtocolConfig.BlockMaxTransactions,
MaxBytesPerTxList: p.ProtocolConfig.BlockMaxTxListBytes,
AnchorGasLimit: opts.AnchorGasLimit,
},
}},
}
Expand Down
22 changes: 12 additions & 10 deletions prover/proof_submitter/valid_proof_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ func (s *ValidProofSubmitter) RequestProof(ctx context.Context, event *bindings.
return fmt.Errorf("failed to get the L2 parent block by hash (%s): %w", block.ParentHash(), err)
}

blockInfo, err := s.rpc.TaikoL1.GetBlock(nil, event.BlockId)
if err != nil {
return err
}

if block.Transactions().Len() == 0 {
return errors.New("no transaction in block")
}
Expand All @@ -125,13 +120,14 @@ func (s *ValidProofSubmitter) RequestProof(ctx context.Context, event *bindings.
L1SignalService: s.l1SignalService,
L2SignalService: s.l2SignalService,
TaikoL2: s.taikoL2Address,
MetaHash: blockInfo.MetaHash,
MetaData: &event.Meta,
BlockHash: block.Hash(),
ParentHash: block.ParentHash(),
SignalRoot: signalRoot,
Graffiti: common.Bytes2Hex(s.graffiti[:]),
GasUsed: block.GasUsed(),
ParentGasUsed: parent.GasUsed(),
AnchorGasLimit: block.Transactions()[0].Gas(),
}

if err := s.proofProducer.RequestProof(
Expand Down Expand Up @@ -203,8 +199,13 @@ func (s *ValidProofSubmitter) SubmitProof(
return fmt.Errorf("failed to fetch anchor transaction receipt: %w", err)
}

blockInfo, err := s.rpc.TaikoL1.GetBlock(nil, blockID)
if err != nil {
return err
}

evidence := &encoding.TaikoL1Evidence{
MetaHash: proofWithHeader.Opts.MetaHash,
MetaHash: blockInfo.MetaHash,
ParentHash: proofWithHeader.Opts.ParentHash,
BlockHash: proofWithHeader.Opts.BlockHash,
SignalRoot: proofWithHeader.Opts.SignalRoot,
Expand All @@ -214,9 +215,10 @@ func (s *ValidProofSubmitter) SubmitProof(
Proof: zkProof,
}

var circuitsIdx uint16
var prover common.Address

var (
circuitsIdx uint16
prover common.Address
)
if s.isOracleProver {
prover = encoding.OracleProverAddress

Expand Down