Skip to content

Commit 84a55fd

Browse files
Prover: fix the txnrlp duplicated txnrlp bug
1 parent 31f87f6 commit 84a55fd

File tree

7 files changed

+60
-33
lines changed

7 files changed

+60
-33
lines changed

prover/backend/execution/craft.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,13 @@ func inspectStateManagerTraces(
143143
resp.ParentStateRootHash = firstParent.Hex()
144144
}
145145

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

148148
var (
149-
res = map[[32]byte]ethereum.Signature{}
150-
blocks = req.Blocks()
151-
currTx = 0
149+
signatures = []ethereum.Signature{}
150+
txHashes = [][32]byte{}
151+
blocks = req.Blocks()
152+
currTx = 0
152153
)
153154

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

162-
res[txHash] = txSignature
163+
signatures = append(signatures, txSignature)
164+
txHashes = append(txHashes, txHash)
165+
163166
currTx++
164167
}
165168
}
166169

167-
return res
170+
return signatures, txHashes
168171
}
169172

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

209212
func NewWitness(cfg *config.Config, req *Request, rsp *Response) *Witness {
213+
txSignatures, txHashes := req.collectSignatures()
210214
return &Witness{
211215
ZkEVM: &zkevm.Witness{
212216
ExecTracesFPath: path.Join(cfg.Execution.ConflatedTracesDir, req.ConflatedExecutionTracesFile),
213217
SMTraces: req.StateManagerTraces(),
214-
TxSignatures: req.collectSignatures(),
218+
TxSignatures: txSignatures,
219+
TxHashes: txHashes,
215220
L2BridgeAddress: cfg.Layer2.MsgSvcContract,
216221
ChainID: cfg.Layer2.ChainID,
217222
},

prover/backend/execution/prove.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ func mustProveAndPass(
176176
fullZkEvm := zkevm.FullZkEVMCheckOnly(traces)
177177
// this will panic to alert errors, so there is no need to handle or
178178
// sanity-check anything.
179+
logrus.Infof("Prover starting the prover")
179180
_ = fullZkEvm.ProveInner(w.ZkEVM)
181+
logrus.Infof("Prover checks passed")
180182
return "", ""
181183

182184
default:

prover/zkevm/prover/ecdsa/adress.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,22 @@ func newAddress(comp *wizard.CompiledIOP, size int, ecRec *EcRecover, ac *antich
104104
column.Shift(addr.isAddressHiEcRec, -1), addr.isAddressFromEcRec,
105105
)
106106

107-
td.csTxnData(comp)
108-
109-
// Waiting for the resolution of:
110-
//
111-
// // projection from txn-data to address columns
112-
// projection.InsertProjection(comp, ifaces.QueryIDf("Project_AddressHi_TxnData"),
113-
// []ifaces.Column{td.fromHi}, []ifaces.Column{addr.addressHi},
114-
// td.isFrom, addr.isAddressFromTxnData,
115-
// )
116-
//
117-
// projection.InsertProjection(comp, ifaces.QueryIDf("Project_AddressLO_TxnData"),
118-
// []ifaces.Column{td.fromLo}, []ifaces.Column{addr.addressLo},
119-
// td.isFrom, addr.isAddressFromTxnData,
120-
// )
107+
// projection from txn-data to address columns
108+
projection.InsertProjection(comp, ifaces.QueryIDf("Project_AddressHi_TxnData"),
109+
[]ifaces.Column{td.fromHi}, []ifaces.Column{addr.addressHi},
110+
td.isFrom, addr.isAddressFromTxnData,
111+
)
112+
113+
// projection from txn-data to address columns
114+
projection.InsertProjection(comp, ifaces.QueryIDf("Project_AddressHi_TxnData"),
115+
[]ifaces.Column{td.fromHi}, []ifaces.Column{addr.addressHi},
116+
td.isFrom, addr.isAddressFromTxnData,
117+
)
118+
119+
projection.InsertProjection(comp, ifaces.QueryIDf("Project_AddressLO_TxnData"),
120+
[]ifaces.Column{td.fromLo}, []ifaces.Column{addr.addressLo},
121+
td.isFrom, addr.isAddressFromTxnData,
122+
)
121123

122124
// impose that hashNum = ac.ID + 1
123125
comp.InsertGlobal(0, ifaces.QueryIDf("Hash_NUM_IS_ID"),

prover/zkevm/prover/ecdsa/antichamber_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func TestAntichamber(t *testing.T) {
9999
}
100100
}
101101

102-
func dummyTxSignatureGetter(txHash []byte) (r, s, v *big.Int, err error) {
102+
func dummyTxSignatureGetter(i int, txHash []byte) (r, s, v *big.Int, err error) {
103103
// some dummy values from the traces
104104
m := map[[32]byte]struct{ r, s, v string }{
105105
{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}: {

prover/zkevm/prover/ecdsa/ecdsa.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ func getEcdataArithmetization(comp *wizard.CompiledIOP) *ecDataSource {
4949
}
5050

5151
func getTxnDataArithmetization(comp *wizard.CompiledIOP) *txnData {
52-
return &txnData{
52+
td := &txnData{
5353
fromHi: comp.Columns.GetHandle("txndata.FROM_HI"),
5454
fromLo: comp.Columns.GetHandle("txndata.FROM_LO"),
5555
ct: comp.Columns.GetHandle("txndata.CT"),
5656
}
57+
td.csTxnData(comp)
58+
return td
5759
}
5860

5961
func getRlpTxnArithmetization(comp *wizard.CompiledIOP) generic.GenDataModule {

prover/zkevm/prover/ecdsa/unaligned_gnark.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ type unalignedGnarkDataSource struct {
5454
TxHashLo ifaces.Column
5555
}
5656

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

5962
func newUnalignedGnarkData(comp *wizard.CompiledIOP, size int, src *unalignedGnarkDataSource) *UnalignedGnarkData {
6063
createCol := createColFn(comp, NAME_UNALIGNED_GNARKDATA, size)
@@ -176,7 +179,7 @@ func (d *UnalignedGnarkData) assignUnalignedGnarkData(run *wizard.ProverRuntime,
176179
txHighBts := txHigh.Bytes()
177180
copy(prehashedMsg[:16], txHighBts[16:])
178181
copy(prehashedMsg[16:], txLowBts[16:])
179-
r, s, v, err = txSigs(prehashedMsg[:])
182+
r, s, v, err = txSigs(txCount, prehashedMsg[:])
180183
if err != nil {
181184
utils.Panic("error getting tx-signature err=%v, txNum=%v", err, txCount)
182185
}

prover/zkevm/witness.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/consensys/linea-monorepo/prover/backend/ethereum"
88
"github.com/consensys/linea-monorepo/prover/backend/execution/statemanager"
9+
"github.com/consensys/linea-monorepo/prover/utils"
910
"github.com/ethereum/go-ethereum/common"
1011
)
1112

@@ -16,21 +17,33 @@ type Witness struct {
1617
// proof trace generation.
1718
ExecTracesFPath string
1819
// StateManager traces
19-
SMTraces [][]statemanager.DecodedTrace
20-
TxSignatures map[[32]byte]ethereum.Signature
20+
SMTraces [][]statemanager.DecodedTrace
21+
// TxSignatures lists the signatures of the transaction as found
22+
// chronologically in the block.
23+
TxSignatures []ethereum.Signature
24+
// TxHashes lists the hash of the transactions in the order found in the
25+
// block.
26+
TxHashes [][32]byte
2127
L2BridgeAddress common.Address
2228
ChainID uint
2329
}
2430

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

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

38+
if utils.HexEncodeToString(txHash) != utils.HexEncodeToString(w.TxHashes[i][:]) {
39+
return nil, nil, nil, fmt.Errorf(
40+
"requested txID=%v while txnrlp expects it to have it for txhash=%v but the blocks transaction has hash=%v",
41+
i, utils.HexEncodeToString(w.TxHashes[i][:]), utils.HexEncodeToString(txHash),
42+
)
43+
}
44+
45+
sig := w.TxSignatures[i]
46+
3447
r, _ = new(big.Int).SetString(sig.R, 0)
3548
s, _ = new(big.Int).SetString(sig.S, 0)
3649
v, _ = new(big.Int).SetString(sig.V, 0)

0 commit comments

Comments
 (0)