总体布局
本段介绍结构体PublicCircuitConfig
的列及其含义。
单功能列 Single-purpose columns
下面是public子电路中的单功能的列:
/// various public information tag, e.g. BlockNumber, TxFrom
tag: Column<Instance>,
/// tx_id (start from 1), except for tag=BlockHash, means recent block number diff (1...256)
tx_idx_or_number_diff: Column<Instance>,
pub enum Tag {
#[default]
ChainId
BlockCoinbase,
BlockTimestamp,
BlockNumber,
BlockDifficulty,
BlockGasLimit,
BlockBaseFee,
BlockHash,
TxStatus,
// combine From and Value together to reduce number of lookups
TxFromValue,
// combine To and CallDataLength together to reduce number of lookups
TxToCallDataSize,
TxIsCreate,
TxGasLimit,
TxGasPrice,
TxCalldata, //TODO make sure this equals copy tag PublicCalldata
TxLog,
TxLogSize,
CodeSize,
}
- tx_idx_or_number_diff 指交易id;当该行数据为BlockHash的时候指的是最近的block number
多功能列 Versatile columns
为了减少列的使用,缩减电路规模,设计了多功能的列。在不同的行数据类别下,这些列存放不同的数据。目前设计有4个多功能列,代码里呈现为:
values: [Column<Instance>; NUM_VALUES],
表设计
区块公共数据存放
tag为ChainId时,该行数据值为:
tag |
tx_idx_or_number_diff |
value[0] |
values[1] |
values[2] |
values[3] |
ChainId |
0 |
chain_id[..16] |
chain_id[16..] |
0 |
0 |
tag为BlockCoinbase时,该行数据值为:
tag |
tx_idx_or_number_diff |
value[0] |
values[1] |
values[2] |
values[3] |
BlockCoinbase |
0 |
coinbase[..4] |
coinbase[4..] |
0 |
0 |
tag为BlockTimeStamp时,该行数据值为:
tag |
tx_idx_or_number_diff |
value[0] |
values[1] |
values[2] |
values[3] |
BlockTimestamp |
0 |
BlockTimestamp[..16] |
BlockTimestamp[16..] |
0 |
0 |
tag为BlockNumber时,该行数据值为:
tag |
tx_idx_or_number_diff |
value[0] |
values[1] |
values[2] |
values[3] |
BlockNumber |
0 |
0 |
BlockNumber |
0 |
0 |
tag为BlockDifficulty时,该行数据值为:
tag |
tx_idx_or_number_diff |
value[0] |
values[1] |
values[2] |
values[3] |
BlockDifficulty |
0 |
BlockDifficulty[..16] |
BlockDifficulty[16..] |
0 |
0 |
tag为BlockGasLimit时,该行数据值为:
tag |
tx_idx_or_number_diff |
value[0] |
values[1] |
values[2] |
values[3] |
BlockGasLimit |
0 |
BlockGasLimit[..16] |
BlockGasLimit[16..] |
0 |
0 |
tag为BlockBaseFee时,该行数据值为:
tag |
tx_idx_or_number_diff |
value[0] |
values[1] |
values[2] |
values[3] |
BlockBaseFee |
0 |
BlockBaseFee[..16] |
BlockBaseFee[16..] |
0 |
0 |
tag为BlockHash的时候,遍历最近的history_hash,每行存放数据值如下,其中index代表在history_hash中的次序(也是当前区块number-此区块number的差值),hash为该次序对应的hash值:
tag |
tx_idx_or_number_diff |
value[0] |
values[1] |
values[2] |
values[3] |
BlockHash |
index |
hash[..16] |
hash[16..] |
0 |
0 |
区块交易相关数据存放
对区块中的每一笔交易遍历存放如下数据类型,其中tx_idx为该交易在区块中的交易列表中的序号(从1开始)
tag为TxFromValue时,该行数据值为:
tag |
tx_idx_or_number_diff |
value[0] |
values[1] |
values[2] |
values[3] |
TxFromValue |
tx_idx |
from[..4] |
from[4..] |
value[..16] |
value[16..] |
tag为TxToCallDataSize时,该行数据值为:
tag |
tx_idx_or_number_diff |
value[0] |
values[1] |
values[2] |
values[3] |
TxToCallDataSize |
tx_idx |
to_hi |
to_lo |
0 |
tx.input.len |
tag为TxIsCreate时,该行数值为:
tag |
tx_idx_or_number_diff |
value[0] |
values[1] |
values[2] |
values[3] |
TxIsCreate |
tx_idx |
0 |
1/0(创建合约为1,普通合约调用为0) |
0 |
0 |
tag为TxGasLimit时,该行数值为:
tag |
tx_idx_or_number_diff |
value[0] |
values[1] |
values[2] |
values[3] |
TxGasLimit |
tx_idx |
gas[..16] |
gas[16..] |
0 |
0 |
tag为TxGasPrice时,该行数值为:
tag |
tx_idx_or_number_diff |
value[0] |
values[1] |
values[2] |
values[3] |
TxGasPrice |
tx_idx |
gas_price[..16] |
gas_price[16..] |
0 |
0 |
将合约的输入数据按byte遍历, 每个byte存放进TxCalldata的数据行,其中idx为该byte在合约的输入数据中的次序,byte为该次序对应的byte数据,该行数值为:
tag |
tx_idx_or_number_diff |
value[0] |
values[1] |
values[2] |
values[3] |
TxCalldata |
tx_idx |
idx |
byte |
0 |
0 |
区块log数据存放
区块中每笔交易可以产生多条log,遍历区块中每笔交易的每个log,其中topic_num为该log中topics的数目(不超过4);tx_idx为该log所属的transaction_index;log_index为该log的log_index;address为该log所属的地址;如果topic_num为0的话,log_tag为AddrWith0Topic;如果topic_num为1/2/3/4的话,log_tag为AddrWith1/2/3/4Topic。
tag为TxLog,该行数值为:
tag |
tx_idx_or_number_diff |
value[0] |
values[1] |
values[2] |
values[3] |
TxLog |
tx_idx |
log_index |
log_tag |
address[..4] |
address[4..] |
tag为TxLog的时候,根据topic的数目,依次存放topic1/2/3/4的数据,其中topic_hash为该topic对应的hash,topic_log_tag为Topic1/2/3/4,每行数值为:
tag |
tx_idx_or_number_diff |
value[0] |
values[1] |
values[2] |
values[3] |
TxLog |
tx_idx |
log_index |
topic_log_tag |
topic_hash[..16] |
topic_hash[16..] |
tag为TxLog时候,记录了log的data长度(data_len),该行数值为:
tag |
tx_idx_or_number_diff |
value[0] |
values[1] |
values[2] |
values[3] |
TxLog |
tx_idx |
log_index |
log_tag=DataSize |
0 |
data_len |
将log中的数据按照byte便利,每个byte存放一行,其中data_idx为该byte在数据块中的次序,其中LogTag::Data为该数据类型,每行数值为:
tag |
tx_idx_or_number_diff |
value[0] |
values[1] |
values[2] |
values[3] |
TxLog |
tx_idx |
log_index |
LogTag::Data |
byte |
data_idx |
合约公共数据存放
tag为CodeSize时,该行数据值为:
tag |
tx_idx_or_number_diff |
value[0] |
values[1] |
values[2] |
values[3] |
CodeSize |
0 |
code_addr hi |
code_addr lo |
code_size hi |
code_size lo |