Skip to content
This repository was archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
Simplify ZKP message
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaubennassar committed Sep 21, 2023
1 parent 4db4fa3 commit 331db00
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
14 changes: 7 additions & 7 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"strings"
"time"

"github.com/0xPolygon/silencer/tx"
"github.com/0xPolygonHermez/zkevm-node/encoding"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonzkevm"
ethmanTypes "github.com/0xPolygonHermez/zkevm-node/etherman/types"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/state"
"github.com/0xPolygonHermez/zkevm-node/test/operations"
Expand Down Expand Up @@ -48,18 +48,18 @@ func (e *Etherman) GetSequencerAddr(l1Contract common.Address) (common.Address,
return contract.TrustedSequencer(&bind.CallOpts{Pending: false})
}

func (e *Etherman) BuildTrustedVerifyBatchesTxData(l1Contract common.Address, lastVerifiedBatch, newVerifiedBatch uint64, inputs *ethmanTypes.FinalProofInputs) (data []byte, err error) {
func (e *Etherman) BuildTrustedVerifyBatchesTxData(l1Contract common.Address, lastVerifiedBatch, newVerifiedBatch uint64, proof tx.Proof) (data []byte, err error) {
opts, contract, err := e.contractCaller(l1Contract)
if err != nil {
return nil, err
}
var newLocalExitRoot [32]byte
copy(newLocalExitRoot[:], inputs.NewLocalExitRoot)
copy(newLocalExitRoot[:], proof.NewLocalExitRoot.Hash().Bytes())
var newStateRoot [32]byte
copy(newStateRoot[:], inputs.NewStateRoot)
proof, err := ConvertProof(inputs.FinalProof.Proof)
copy(newStateRoot[:], proof.NewStateRoot.Hash().Bytes())
finalProof, err := ConvertProof(proof.Proof.Hex())
if err != nil {
log.Errorf("error converting proof. Error: %v, Proof: %s", err, inputs.FinalProof.Proof)
log.Errorf("error converting proof. Error: %v, Proof: %s", err, proof.Proof)
return nil, err
}

Expand All @@ -71,7 +71,7 @@ func (e *Etherman) BuildTrustedVerifyBatchesTxData(l1Contract common.Address, la
newVerifiedBatch,
newLocalExitRoot,
newStateRoot,
proof,
finalProof,
)
if err != nil {
if parsedErr, ok := tryParseError(err); ok {
Expand Down
4 changes: 2 additions & 2 deletions rpc/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"math/big"

ethmanTypes "github.com/0xPolygonHermez/zkevm-node/etherman/types"
"github.com/0xPolygon/silencer/tx"
"github.com/0xPolygonHermez/zkevm-node/ethtxmanager"
"github.com/0xPolygonHermez/zkevm-node/jsonrpc/types"
"github.com/ethereum/go-ethereum"
Expand All @@ -18,7 +18,7 @@ type DBInterface interface {

type EthermanInterface interface {
GetSequencerAddr(l1Contract common.Address) (common.Address, error)
BuildTrustedVerifyBatchesTxData(l1Contract common.Address, lastVerifiedBatch, newVerifiedBatch uint64, inputs *ethmanTypes.FinalProofInputs) (data []byte, err error)
BuildTrustedVerifyBatchesTxData(l1Contract common.Address, lastVerifiedBatch, newVerifiedBatch uint64, proof tx.Proof) (data []byte, err error)
CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
}

Expand Down
8 changes: 4 additions & 4 deletions rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (i *InteropEndpoints) SendTx(signedTx tx.SignedTx) (interface{}, types.Erro
signedTx.Tx.L1Contract,
uint64(signedTx.Tx.LastVerifiedBatch),
uint64(signedTx.Tx.NewVerifiedBatch),
&signedTx.Tx.ZKP,
signedTx.Tx.ZKP,
)
if err != nil {
return "0x0", types.NewRPCError(types.DefaultErrorCode, fmt.Sprintf("failed to build verify ZKP tx: %s", err))
Expand Down Expand Up @@ -98,12 +98,12 @@ func (i *InteropEndpoints) SendTx(signedTx tx.SignedTx) (interface{}, types.Erro
if err != nil {
return "0x0", types.NewRPCError(types.DefaultErrorCode, fmt.Sprintf("failed to get batch from our node, error: %s", err))
}
if batch.StateRoot != signedTx.Tx.NewStateRoot.Hash() || batch.LocalExitRoot != signedTx.Tx.NewLocalExitRoot.Hash() {
if batch.StateRoot != signedTx.Tx.ZKP.NewStateRoot.Hash() || batch.LocalExitRoot != signedTx.Tx.ZKP.NewLocalExitRoot.Hash() {
return "0x0", types.NewRPCError(types.DefaultErrorCode, fmt.Sprintf(
"Missmatch detected, expected local exit root: %s actual: %s. expected state root: %s actual: %s",
signedTx.Tx.NewLocalExitRoot.Hash().Hex(),
signedTx.Tx.ZKP.NewLocalExitRoot.Hash().Hex(),
batch.LocalExitRoot.Hex(),
signedTx.Tx.NewStateRoot.Hash().Hex(),
signedTx.Tx.ZKP.NewStateRoot.Hash().Hex(),
batch.StateRoot.Hex(),
))
}
Expand Down
17 changes: 10 additions & 7 deletions tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tx
import (
"crypto/ecdsa"

ethmanTypes "github.com/0xPolygonHermez/zkevm-node/etherman/types"
"github.com/0xPolygonHermez/zkevm-node/jsonrpc/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
Expand All @@ -16,25 +15,29 @@ import (
// Validium L1Concensus = "validium"
// )

type Proof struct {
NewStateRoot types.ArgHash
NewLocalExitRoot types.ArgHash
Proof types.ArgBytes
}

type Tx struct {
L1Contract common.Address
// L1Concensus L1Con census
// Batches []types.Batch
LastVerifiedBatch types.ArgUint64
NewVerifiedBatch types.ArgUint64
ZKP ethmanTypes.FinalProofInputs
NewStateRoot types.ArgHash
NewLocalExitRoot types.ArgHash
ZKP Proof
}

// Hash returns a hash that uniquely identifies the tx
func (t *Tx) Hash() common.Hash {
return common.BytesToHash(crypto.Keccak256(
[]byte(t.LastVerifiedBatch.Hex()),
[]byte(t.NewVerifiedBatch.Hex()),
[]byte(t.ZKP.FinalProof.Proof),
t.NewStateRoot[:],
t.NewLocalExitRoot[:],
t.ZKP.NewStateRoot[:],
t.ZKP.NewLocalExitRoot[:],
[]byte(t.ZKP.Proof.Hex()),
))
}

Expand Down

0 comments on commit 331db00

Please sign in to comment.