Skip to content

Commit

Permalink
Prover: fix the txnrlp duplicated txnrlp bug
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreBelling committed Sep 23, 2024
1 parent 6eb6bd8 commit bc631a1
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 35 deletions.
19 changes: 12 additions & 7 deletions prover/backend/execution/craft.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ func inspectStateManagerTraces(
resp.ParentStateRootHash = firstParent.Hex()
}

func (req *Request) collectSignatures() map[[32]byte]ethereum.Signature {
func (req *Request) collectSignatures() ([]ethereum.Signature, [][32]byte) {

var (
res = map[[32]byte]ethereum.Signature{}
blocks = req.Blocks()
currTx = 0
signatures = []ethereum.Signature{}
txHashes = [][32]byte{}
blocks = req.Blocks()
currTx = 0
)

for i := range blocks {
Expand All @@ -159,12 +160,14 @@ func (req *Request) collectSignatures() map[[32]byte]ethereum.Signature {
txSignature = ethereum.GetJsonSignature(tx)
)

res[txHash] = txSignature
signatures = append(signatures, txSignature)
txHashes = append(txHashes, txHash)

currTx++
}
}

return res
return signatures, txHashes
}

// FuncInput are all the relevant fields parsed by the prover that
Expand Down Expand Up @@ -207,11 +210,13 @@ func (rsp *Response) FuncInput() *execution.FunctionalPublicInput {
}

func NewWitness(cfg *config.Config, req *Request, rsp *Response) *Witness {
txSignatures, txHashes := req.collectSignatures()
return &Witness{
ZkEVM: &zkevm.Witness{
ExecTracesFPath: path.Join(cfg.Execution.ConflatedTracesDir, req.ConflatedExecutionTracesFile),
SMTraces: req.StateManagerTraces(),
TxSignatures: req.collectSignatures(),
TxSignatures: txSignatures,
TxHashes: txHashes,
L2BridgeAddress: cfg.Layer2.MsgSvcContract,
ChainID: cfg.Layer2.ChainID,
},
Expand Down
2 changes: 2 additions & 0 deletions prover/backend/execution/prove.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ func mustProveAndPass(
fullZkEvm := zkevm.FullZkEVMCheckOnly(traces)
// this will panic to alert errors, so there is no need to handle or
// sanity-check anything.
logrus.Infof("Prover starting the prover")
_ = fullZkEvm.ProveInner(w.ZkEVM)
logrus.Infof("Prover checks passed")
return "", ""

default:
Expand Down
26 changes: 10 additions & 16 deletions prover/zkevm/prover/ecdsa/adress.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,16 @@ func newAddress(comp *wizard.CompiledIOP, size int, ecRec *EcRecover, ac *antich
column.Shift(addr.isAddressHiEcRec, -1), addr.isAddressFromEcRec,
)

td.csTxnData(comp)

// Waiting for the resolution of:
//
// https://github.com/Consensys/zkevm-monorepo/issues/3801
//
// // projection from txn-data to address columns
// projection.InsertProjection(comp, ifaces.QueryIDf("Project_AddressHi_TxnData"),
// []ifaces.Column{td.fromHi}, []ifaces.Column{addr.addressHi},
// td.isFrom, addr.isAddressFromTxnData,
// )
//
// projection.InsertProjection(comp, ifaces.QueryIDf("Project_AddressLO_TxnData"),
// []ifaces.Column{td.fromLo}, []ifaces.Column{addr.addressLo},
// td.isFrom, addr.isAddressFromTxnData,
// )
// projection from txn-data to address columns
projection.InsertProjection(comp, ifaces.QueryIDf("Project_AddressHi_TxnData"),
[]ifaces.Column{td.fromHi}, []ifaces.Column{addr.addressHi},
td.isFrom, addr.isAddressFromTxnData,
)

projection.InsertProjection(comp, ifaces.QueryIDf("Project_AddressLO_TxnData"),
[]ifaces.Column{td.fromLo}, []ifaces.Column{addr.addressLo},
td.isFrom, addr.isAddressFromTxnData,
)

// impose that hashNum = ac.ID + 1
comp.InsertGlobal(0, ifaces.QueryIDf("Hash_NUM_IS_ID"),
Expand Down
2 changes: 1 addition & 1 deletion prover/zkevm/prover/ecdsa/antichamber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestAntichamber(t *testing.T) {
}
}

func dummyTxSignatureGetter(txHash []byte) (r, s, v *big.Int, err error) {
func dummyTxSignatureGetter(i int, txHash []byte) (r, s, v *big.Int, err error) {
// some dummy values from the traces
m := map[[32]byte]struct{ r, s, v string }{
{0x27, 0x9d, 0x94, 0x62, 0x15, 0x58, 0xf7, 0x55, 0x79, 0x68, 0x98, 0xfc, 0x4b, 0xd3, 0x6b, 0x6d, 0x40, 0x7c, 0xae, 0x77, 0x53, 0x78, 0x65, 0xaf, 0xe5, 0x23, 0xb7, 0x9c, 0x74, 0xcc, 0x68, 0xb}: {
Expand Down
4 changes: 3 additions & 1 deletion prover/zkevm/prover/ecdsa/ecdsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ func getEcdataArithmetization(comp *wizard.CompiledIOP) *ecDataSource {
}

func getTxnDataArithmetization(comp *wizard.CompiledIOP) *txnData {
return &txnData{
td := &txnData{
fromHi: comp.Columns.GetHandle("txndata.FROM_HI"),
fromLo: comp.Columns.GetHandle("txndata.FROM_LO"),
ct: comp.Columns.GetHandle("txndata.CT"),
}
td.csTxnData(comp)
return td
}

func getRlpTxnArithmetization(comp *wizard.CompiledIOP) generic.GenDataModule {
Expand Down
7 changes: 5 additions & 2 deletions prover/zkevm/prover/ecdsa/unaligned_gnark.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ type unalignedGnarkDataSource struct {
TxHashLo ifaces.Column
}

type TxSignatureGetter func(txHash []byte) (r, s, v *big.Int, err error)
// TxSignatureGetter is a function that is expected a signature for a transaction
// hash and/or a integer id. In production, the function returns the signature
// from the transaction id but uses the txHash as a sanity-check.
type TxSignatureGetter func(i int, txHash []byte) (r, s, v *big.Int, err error)

func newUnalignedGnarkData(comp *wizard.CompiledIOP, size int, src *unalignedGnarkDataSource) *UnalignedGnarkData {
createCol := createColFn(comp, NAME_UNALIGNED_GNARKDATA, size)
Expand Down Expand Up @@ -176,7 +179,7 @@ func (d *UnalignedGnarkData) assignUnalignedGnarkData(run *wizard.ProverRuntime,
txHighBts := txHigh.Bytes()
copy(prehashedMsg[:16], txHighBts[16:])
copy(prehashedMsg[16:], txLowBts[16:])
r, s, v, err = txSigs(prehashedMsg[:])
r, s, v, err = txSigs(txCount, prehashedMsg[:])
if err != nil {
utils.Panic("error getting tx-signature err=%v, txNum=%v", err, txCount)
}
Expand Down
29 changes: 21 additions & 8 deletions prover/zkevm/witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/consensys/zkevm-monorepo/prover/backend/ethereum"
"github.com/consensys/zkevm-monorepo/prover/backend/execution/statemanager"
"github.com/consensys/zkevm-monorepo/prover/utils"
"github.com/ethereum/go-ethereum/common"
)

Expand All @@ -16,21 +17,33 @@ type Witness struct {
// proof trace generation.
ExecTracesFPath string
// StateManager traces
SMTraces [][]statemanager.DecodedTrace
TxSignatures map[[32]byte]ethereum.Signature
SMTraces [][]statemanager.DecodedTrace
// TxSignatures lists the signatures of the transaction as found
// chronologically in the block.
TxSignatures []ethereum.Signature
// TxHashes lists the hash of the transactions in the order found in the
// block.
TxHashes [][32]byte
L2BridgeAddress common.Address
ChainID uint
}

func (w Witness) TxSignatureGetter(txHash []byte) (r, s, v *big.Int, err error) {
var (
sig, found = w.TxSignatures[[32]byte(txHash)]
)
// TxSignatureGetter implements the ecdsa.TxSignatureGetter interface
func (w Witness) TxSignatureGetter(i int, txHash []byte) (r, s, v *big.Int, err error) {

if !found {
return nil, nil, nil, fmt.Errorf("could not find signature for tx hash = 0x%x", txHash)
if i > len(w.TxHashes) {
return nil, nil, nil, fmt.Errorf("requested txID outgoes the total number of transactions we found in the conflation")
}

if utils.HexEncodeToString(txHash) != utils.HexEncodeToString(w.TxHashes[i][:]) {
return nil, nil, nil, fmt.Errorf(
"requested txID=%v while txnrlp expects it to have it for txhash=%v but the blocks transaction has hash=%v",
i, utils.HexEncodeToString(w.TxHashes[i][:]), utils.HexEncodeToString(txHash),
)
}

sig := w.TxSignatures[i]

r, _ = new(big.Int).SetString(sig.R, 0)
s, _ = new(big.Int).SetString(sig.S, 0)
v, _ = new(big.Int).SetString(sig.V, 0)
Expand Down

0 comments on commit bc631a1

Please sign in to comment.