-
Notifications
You must be signed in to change notification settings - Fork 125
Standalone circuit tools #92
Standalone circuit tools #92
Comments
circuit tools #123 |
This code provides a basic structure and methods for managing cells, memory, and cached regions within the Circuit-tools project. Actual implementation will depend on specific project requirements and architecture. // Example structure for managing cells impl CellManager {
} // Example circuit! macros for providing branching logic and optimizing cell allocation // Example structure MemoryBank for memory management impl MemoryBank {
} // Example structure CachedRegion for caching region data impl CachedRegion {
} |
Make Circuit-tools a standalone repo that has components & APIs to support Halo2 development.
The current Halo2 APIs apply constraints within
Gate
which defines expression across polynomial columns, and assign circuit withRegion
which are independent areas that resembles integrated chip design. However, these features are not fine-grained enough for zkevm development which requires controls over specific cells. In addition, the two-phase process are separated from each other, and no current tools exists to leverage constraints defined in configuration phase to speed up the assignment phase.Thus we came up with a bucket of toolkits to fill in the blank as we work on the #39 MPT circuit. The toolkits mimics RAM and ROM assess with
Cell
andLookup
, aiming to exploit the full expressive power of PLONKish arithemetization. The Circuit-tools include:CellManager
cell_type
,num_columns
,phase
, andpermutable
, then init the section according toCellConfig<C: CellType>
.ifx!
andmatchx!
.circuit!
macrosmeta: &mut VirtualCells<F>
andcb: ConstraintBuilder<F, T>
for inner code to call Halo2 APIs,meta
captured (f!
,a!
, andx!
).ifx!
,elsex!
, andmatchx!
), incorporates CellManager's context to optimize cell allocation.require!
can enforce equality between$lhs
and$rhs
, constrain a value to be boolean, or even perform lookups with intuitive syntax sugar (require!((a, b) => @KECCAK
).MemoryBank
MemoryBank
basically initiate Advice lookups into itself to encode R/W logic as part of the proof. It also contains a columns to enforce R/W operations happen at expected place.store(values: &[Expression<F>])
puts lookup table tuples intocb
(resembling memory write), whileload(values: &[Expression<F>])
should use the exact same tuples as lookup data (resembling memory read). Proving that stored expressions exist in loaded expression at expected rows would prove R/W correctness.witness_store(offset: usize, values: &[F])
in fact cached the witness tuple inMemoryBank
(instead of assigning it to Cells) and record the stored row index, thenwitness_load(offset: usize, values: &[F])
takes out those previously cached values and finally assign them to satisfy the self-lookup constraints.assign()
function of 'MemoryBank' itself should be call at the end stage of entire circuit assignment, this will write down the recorded row index at Read time into Bank's Advice column.CachedRegion
Region
withVec<Vec<T>>
so when user put for instanceValue::known(3)
in Cell A andValue::known(7)
in Cell B with constraint A + BB = C, then we can get 3 and 7 out from theCachedRegion
and evaluate the stored constraint as 3 + 7*7 = 52 to assign Cell C.StoreExpression
at config time. It's mostly used for lookups in the evm_circuit, because the evm_circuit first combine lookup tuple into rlc corresponding to table values that are also combined as rlc, so that we only has oneCellType::Lookup
to lookup SomeTable.The text was updated successfully, but these errors were encountered: