Skip to content

Implement "glue" for publicinput module over koalabear field #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: feature/sha2
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions prover/zkevm/prover/common/flatten_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
const (
// NbLimbU32 represents the number of 16-bit limbs for a 32-bit integer.
NbLimbU32 = 2
// NbLimbU48 represents the number of 16-bit limbs for a 48-bit integer.
NbLimbU48 = 3
// NbLimbU64 represents the number of 16-bit limbs for a 64-bit integer.
NbLimbU64 = 4
// NbLimbEthAddress represents the number of 16-bit limbs for an Ethereum address (160 bits).
Expand Down
121 changes: 79 additions & 42 deletions prover/zkevm/prover/publicInput/arith_struct/arith_struct.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package arith_struct

import (
"fmt"
"github.com/consensys/linea-monorepo/prover/protocol/ifaces"
"github.com/consensys/linea-monorepo/prover/protocol/wizard"
"github.com/consensys/linea-monorepo/prover/utils/csvtraces"
"github.com/consensys/linea-monorepo/prover/zkevm/prover/common"
)

// BlockDataCols models the arithmetization's BlockData module
Expand All @@ -14,30 +16,45 @@ type BlockDataCols struct {
Inst ifaces.Column
// Ct is a counter column
Ct ifaces.Column
// DataHi/DataLo encode the data, for example the timestamps
DataHi, DataLo ifaces.Column
// DataHi/DataLo encode the data, for example the timestamps.
// It's divided into 16 16-bit limb columns. 256 bits in total.
Data [common.NbLimbU256]ifaces.Column
// FirstBlock contains the absolute ID of the first block
FirstBlock ifaces.Column
// It's divided into 3 16-bit limb columns. 48 bits in total.
FirstBlock [common.NbLimbU48]ifaces.Column

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I understand that as an optimization to use 3 limbs instead of 4 as the number of block will never realistically go over 2**48?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

// TxnData models the arithmetization's TxnData module
type TxnData struct {
AbsTxNum, AbsTxNumMax ifaces.Column // Absolute number of the transaction (starts from 1 and acts as an Active Filter), and the maximum number of transactions
RelTxNum, RelTxNumMax ifaces.Column // Relative TxNum inside the block,
FromHi, FromLo ifaces.Column // Sender address
IsLastTxOfBlock ifaces.Column // 1 if this is the last transaction inside the block
RelBlock ifaces.Column // Relative Block number inside the batch
Ct ifaces.Column
// Absolute number of the transaction (starts from 1 and acts as an Active Filter), and the maximum number of
// transactions
AbsTxNum, AbsTxNumMax ifaces.Column
// Relative TxNum inside the block,
RelTxNum, RelTxNumMax ifaces.Column
// Sender address. It's divided into 10 16-bit limb columns. 160 bits in total.
From [common.NbLimbEthAddress]ifaces.Column
// 1 if this is the last transaction inside the block
IsLastTxOfBlock ifaces.Column
// Relative Block number inside the batch
RelBlock ifaces.Column
Ct ifaces.Column
}

// RlpTxn models the arithmetization's RlpTxn module
type RlpTxn struct {
AbsTxNum, AbsTxNumMax ifaces.Column // Absolute number of the transaction (starts from 1 and acts as an Active Filter), and the maximum number of transactions
ToHashByProver ifaces.Column // Relative TxNum inside the block,
Limb ifaces.Column
NBytes ifaces.Column // the number of bytes to load from the limb
Done ifaces.Column // indicator column which we will use to obtain the ChainID
IsPhaseChainID ifaces.Column // indicator column which we will use to obtain the ChainID
// Absolute number of the transaction (starts from 1 and acts as an Active Filter), and the maximum number of transactions
AbsTxNum, AbsTxNumMax ifaces.Column
// Relative TxNum inside the block,
ToHashByProver ifaces.Column
// Limbs are columns that is used to store the RLP data.
// It represents a single 128-bit limb, which is divided into 8 16-bit columns.
Limbs [common.NbLimbU128]ifaces.Column
// the number of bytes to load from the limb
NBytes ifaces.Column
// indicator column which we will use to obtain the ChainID
Done ifaces.Column
// indicator column which we will use to obtain the ChainID
IsPhaseChainID ifaces.Column
}

// DefineTestingArithModules defines the BlockDataCols, TxnData and RlpTxn modules based on csv traces.
Expand All @@ -48,14 +65,20 @@ func DefineTestingArithModules(b *wizard.Builder, ctBlockData, ctTxnData, ctRlpT
txnDataCols *TxnData
rlpTxn *RlpTxn
)

if ctBlockData != nil {
blockDataCols = &BlockDataCols{
RelBlock: ctBlockData.GetCommit(b, "REL_BLOCK"),
Inst: ctBlockData.GetCommit(b, "INST"),
Ct: ctBlockData.GetCommit(b, "CT"),
DataHi: ctBlockData.GetCommit(b, "DATA_HI"),
DataLo: ctBlockData.GetCommit(b, "DATA_LO"),
FirstBlock: ctBlockData.GetCommit(b, "FIRST_BLOCK_NUMBER"),
RelBlock: ctBlockData.GetCommit(b, "REL_BLOCK"),
Inst: ctBlockData.GetCommit(b, "INST"),
Ct: ctBlockData.GetCommit(b, "CT"),
}

for i := range blockDataCols.FirstBlock {
blockDataCols.FirstBlock[i] = ctBlockData.GetCommit(b, fmt.Sprintf("FIRST_BLOCK_NUMBER_%d", i))
}

for i := range blockDataCols.Data {
blockDataCols.Data[i] = ctBlockData.GetCommit(b, fmt.Sprintf("DATA_%d", i))
}
}
if ctTxnData != nil {
Expand All @@ -65,22 +88,27 @@ func DefineTestingArithModules(b *wizard.Builder, ctBlockData, ctTxnData, ctRlpT
RelTxNum: ctTxnData.GetCommit(b, "TD.REL_TX_NUM"),
RelTxNumMax: ctTxnData.GetCommit(b, "TD.REL_TX_NUM_MAX"),
Ct: ctTxnData.GetCommit(b, "TD.CT"),
FromHi: ctTxnData.GetCommit(b, "TD.FROM_HI"),
FromLo: ctTxnData.GetCommit(b, "TD.FROM_LO"),
IsLastTxOfBlock: ctTxnData.GetCommit(b, "TD.IS_LAST_TX_OF_BLOCK"),
RelBlock: ctTxnData.GetCommit(b, "TD.REL_BLOCK"),
}

for i := range txnDataCols.From {
txnDataCols.From[i] = ctTxnData.GetCommit(b, fmt.Sprintf("TD.FROM_%d", i))
}
}
if ctRlpTxn != nil {
rlpTxn = &RlpTxn{
AbsTxNum: ctRlpTxn.GetCommit(b, "RT.ABS_TX_NUM"),
AbsTxNumMax: ctRlpTxn.GetCommit(b, "RT.ABS_TX_NUM_MAX"),
ToHashByProver: ctRlpTxn.GetCommit(b, "RL.TO_HASH_BY_PROVER"),
Limb: ctRlpTxn.GetCommit(b, "RL.LIMB"),
NBytes: ctRlpTxn.GetCommit(b, "RL.NBYTES"),
Done: ctRlpTxn.GetCommit(b, "RL.DONE"),
IsPhaseChainID: ctRlpTxn.GetCommit(b, "RL.IS_PHASE_CHAIN_ID"),
}

for i := range rlpTxn.Limbs {
rlpTxn.Limbs[i] = ctRlpTxn.GetCommit(b, fmt.Sprintf("RL.LIMB_%d", i))
}
}

return blockDataCols, txnDataCols, rlpTxn
Expand All @@ -91,41 +119,50 @@ func DefineTestingArithModules(b *wizard.Builder, ctBlockData, ctTxnData, ctRlpT
func AssignTestingArithModules(run *wizard.ProverRuntime, ctBlockData, ctTxnData, ctRlpTxn *csvtraces.CsvTrace) {
// assign the CSV data for the mock BlockData, TxnData and RlpTxn arithmetization modules
if ctBlockData != nil {
ctBlockData.Assign(
run,
"REL_BLOCK",
"INST",
"CT",
"DATA_HI",
"DATA_LO",
"FIRST_BLOCK_NUMBER",
)
toAssign := []string{"REL_BLOCK", "INST", "CT"}

for i := range common.NbLimbU256 {
toAssign = append(toAssign, fmt.Sprintf("DATA_%d", i))
}

for i := range common.NbLimbU48 {
toAssign = append(toAssign, fmt.Sprintf("FIRST_BLOCK_NUMBER_%d", i))
}

ctBlockData.Assign(run, toAssign...)
}
if ctTxnData != nil {
ctTxnData.Assign(
run,
toAssign := []string{
"TD.ABS_TX_NUM",
"TD.ABS_TX_NUM_MAX",
"TD.REL_TX_NUM",
"TD.REL_TX_NUM_MAX",
"TD.CT",
"TD.FROM_HI",
"TD.FROM_LO",
"TD.IS_LAST_TX_OF_BLOCK",
"TD.REL_BLOCK",
)
}

for i := range common.NbLimbEthAddress {
toAssign = append(toAssign, fmt.Sprintf("TD.FROM_%d", i))
}

ctTxnData.Assign(run, toAssign...)
}
if ctRlpTxn != nil {
ctRlpTxn.Assign(
run,
toAssign := []string{
"RT.ABS_TX_NUM",
"RT.ABS_TX_NUM_MAX",
"RL.TO_HASH_BY_PROVER",
"RL.LIMB",
"RL.NBYTES",
"RL.DONE",
"RL.IS_PHASE_CHAIN_ID",
)
}

for i := range common.NbLimbU128 {
toAssign = append(toAssign, fmt.Sprintf("RL.LIMB_%d", i))
}

ctRlpTxn.Assign(run, toAssign...)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ The number of transactions in the block (2 bytes), the block timestamp (4 bytes)
and then for each transaction tx_i, the sender address (20 bytes) and the transaction RLP.
We then continue analogously for each block.

Due to design choices in the arithmetization and other submodules, we can only load at most 16 bytes
at a time. For this reason, blockhash is divided into two columns: BlockHashHi (16 bytes) and BlockHashLo (16 bytes).
Similarly, the sender address is divided into AddrHi (4 bytes) and AddrLo (16 bytes).
Due to design choices in the arithmetization and other submodules, we can only load at most 2 bytes
at a time. For this reason, blockhash is divided into 8 columns: [16]BlockHash (32 bytes in total).
Similarly, the sender address is divided into 10 columns: [10]Addr (20 bytes in total).


Finally, the RLP data for each transaction is stored in the RLPTXN module. We use an intermediary fetcher
Expand Down
Loading