Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

MPT Sync#81

Open
CeciliaZ030 wants to merge 19 commits into
taikoxyz:mpt-syncfrom
CeciliaZ030:mpt-sync
Open

MPT Sync#81
CeciliaZ030 wants to merge 19 commits into
taikoxyz:mpt-syncfrom
CeciliaZ030:mpt-sync

Conversation

@CeciliaZ030

@CeciliaZ030 CeciliaZ030 commented Apr 29, 2023

Copy link
Copy Markdown

Issue Link

MPT Review

Type of change

  • State machine constraint
  • Standalone circuit tools
  • CachedRegion
  • PhaseConfig generated from LookupTable
  • Cell Manager with context

More to come ...

@CeciliaZ030 CeciliaZ030 changed the title state machine constraints & dev-graph plots MPT Sync May 3, 2023

@Brechtpd Brechtpd left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Generally looks good I think!

Comment thread zkevm-circuits/src/circuit_tools/cached_region.rs Outdated

/// Returns the random linear combination of the inputs.
/// Encoding is done as follows: v_0 * R^0 + v_1 * R^1 + ...
pub(crate) mod rlc {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bit of a strange place to put, maybe just a temp location?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yea, I put it here because it's being called here

Comment on lines +321 to +322
// Replace a CellType_::Storage by CellType_::StoragePermutation if the later has
// better height

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe a bit optimistic to do this here because the cell manager doesn't know what cells will be requested afterwards, so could make a bad (or of course also a good one) decision by doing this? Seems like this decision could only really be moade after all cells have been queried.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed. This is from evm-circuit as well, they probably do it because there's not much copy constraints. I feel like optimization like this can be done afterwards, at least for a general purpose circuit-tool it shouldn't make such assumption.

require!(a!(state_machine.is_start) => true);
}};
// Main state machine
let sum_states = a!(state_machine.is_start) + a!(state_machine.is_branch) + a!(state_machine.is_account) + a!(state_machine.is_storage);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think sum_states checks can be removed because already done by matchx!?

for node in nodes.iter() {
// Assign bytes
let mut rlp_values = Vec::new();
let mut cahced_region = CachedRegion::new(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
let mut cahced_region = CachedRegion::new(
let mut cached_region = CachedRegion::new(

Comment thread zkevm-circuits/src/mpt_circuit.rs Outdated
// println!("{}: start", offset);
assign!(region, (self.state_machine.is_start, offset) => true.scalar())?;
self.state_machine.start_config.assign(
let mut cahced_region = CachedRegion::new(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Instead of making a cached region per state, maybe just make one (with max height of states) and use it in each state?

let q_enable = meta.fixed_column();
let q_first = meta.fixed_column();
let q_last = meta.fixed_column();
let rows_left_in_state = meta.fixed_column();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should be advice no? (values depend on which nodes are inserted in the circuit)

}

pub trait CustomTable: Clone + Copy + Debug + PartialEq + Eq + PartialOrd + Ord + Hash{
fn matches_to(&self, other: &Self) -> bool;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I guess matches_to can be removed because == is used directly (and should be as flexible)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

True, in fact CustomTable is just a marker trait because we need a type parameter for generic tables. It kind of make sense to me seeing specific tools bounded by specific table and config:

pub struct ConstraintBuilder<F, T: CustomTable> {
    constraints: Vec<(&'static str, Expression<F>)>,
    max_degree: usize,
    conditions: Vec<Expression<F>>,
    pub lookups: Vec<LookupData<F>>,
    pub lookup_tables: Vec<LookupData<F>>,
    pub cell_manager: Option<CellManager<F, T>>,
}

pub struct CellManager<F, T: CustomTable> {
    pub(crate) width: usize,
    pub(crate) height: usize,
    pub(crate) cells: Vec<Cell<F>>,
    pub(crate) columns: Vec<CellColumn<F, T>>,
    pub(crate) phase_config: PhaseConfig<T>,
    pub(crate) copy_columns: usize,
}

pub struct PhaseConfig<T> {
    phase3: Vec<(T, usize)>, //lookup
    phase2: usize, // rlc
    phase1: usize, // byte
}

Maybe we can also move these functions in CustomTable as well.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Or maybe the opposite, allow LookupTable to be used in the cellmanager as trait instead of CustomTable?

@CeciliaZ030

CeciliaZ030 commented Jun 11, 2023

Copy link
Copy Markdown
Author

New todos:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants