Skip to content
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

Relax restriction to a single looked table for CTL #1575

Conversation

matthiasgoergens
Copy link
Contributor

@matthiasgoergens matthiasgoergens commented Apr 22, 2024

EDIT: it's perhaps better to get #1577 in first, and then I rebase this PR.

In our use of plonky2, we have a few instances where we need both several looked and several looking tables. Think of these lookups as many-to-many multiplexers, or a kind of bus. Looking tables can be thought of as pushing values with an obligation to process them onto the bus, looked tables can be seen as pulling values to discharge that obligation.

My first attempt changed from looked_table to looked_tables, but then I noticed that thanks to logup, we don't need this complication: looked_tables are just looking_tables with negative multiplicities.

Thus we can get a simpler system by just removing looked_table completely, and giving people tools to negate the multiplicities of their lookup tables.

We also preserve the old CrossTableLookup::new, which applies the negation to the passed looked_table automatically to keep the API as compatible as possible.

This PR only touches cross table lookups. We could do the same for the intra-table lookups in starky/src/lookup.rs. But that's for a separate PR.

},
) in cross_table_lookups.iter().enumerate()
{
for (index, CrossTableLookup { looking_tables }) in cross_table_lookups.iter().enumerate() {
// Get elements looking into `looked_table` that are not associated to any STARK.
let extra_sum_vec: &[F] = ctl_extra_looking_sums
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ctl_extra_looking_sums are now indexed the same as cross_table_lookups, not like looked tables.

@@ -1041,26 +971,21 @@ pub mod debug_utils {
}
}

fn check_ctl<F: Field>(
fn check_ctl<F: PrimeField64>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure these functions are actually in use anywhere? They don't seem to have been updated to reflect the greater capabilities of logup vs the old product argument.

Copy link
Collaborator

Choose a reason for hiding this comment

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

They are being used on the zk_evm side here: prover.rs

@matthiasgoergens matthiasgoergens changed the title Relax restriction to a single looked table Relax restriction to a single looked table for CTL Apr 22, 2024
@matthiasgoergens matthiasgoergens force-pushed the matthias/looked-tables-upstream branch 2 times, most recently from a274126 to 2e21697 Compare April 22, 2024 04:43
In our use of plonky2, we have a few instances where we need both
several looked and several looking tables.  Think of these lookups as
many-to-many multiplexers, or a kind of bus.  Looking tables can be
thought of as pushing values with an obligation to process them onto the
bus, looked tables can be seen as pulling values to discharge that
obligation.

My first attempt changed from `looked_table` to `looked_tables`, but
then I noticed that thanks to logup, we don't need this complication:
looked_tables are just looking_tables with negative multiplicities.

Thus we can get a simpler system by just removing `looked_table`
completely, and giving people tools to negate the multiplicities of
their lookup tables.

We also preserve the old `CrossTableLookup::new`, which applies the
negation to the passed `looked_table` automatically to keep the API as
compatible as possible.
@matthiasgoergens matthiasgoergens force-pushed the matthias/looked-tables-upstream branch from 2e21697 to 6ef8270 Compare April 22, 2024 04:48
Copy link
Contributor

@LindaGuiga LindaGuiga left a comment

Choose a reason for hiding this comment

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

Thank you @matthiasgoergens , it's a good idea!
But I tried running this PR against the integration tests in zk_evm (for example add11_yml), and CTLs and Lookups failed. So I was wondering whether this was also the case for you or if maybe I had messed something up when testing?

@Nashtare
Copy link
Collaborator

Thank you @matthiasgoergens , it's a good idea!
But I tried running this PR against the integration tests in zk_evm (for example add11_yml), and CTLs and Lookups failed. So I was wondering whether this was also the case for you or if maybe I had messed something up when testing?

This branch is based on an older version of #1577 which was broken (and that @matthiasgoergens now fixed). After rebasing this should go away I believe.

@LindaGuiga
Copy link
Contributor

Thank you @matthiasgoergens , it's a good idea!
But I tried running this PR against the integration tests in zk_evm (for example add11_yml), and CTLs and Lookups failed. So I was wondering whether this was also the case for you or if maybe I had messed something up when testing?

This branch is based on an older version of #1577 which was broken (and that @matthiasgoergens now fixed). After rebasing this should go away I believe.

Indeed, it works with those changes, thanks!

Copy link
Contributor

@LindaGuiga LindaGuiga left a comment

Choose a reason for hiding this comment

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

The changes look great (once it includes the fix from #1577 ), thank you @matthiasgoergens !

@matthiasgoergens
Copy link
Contributor Author

Could you please tell me how to run the zk_evm tests? Is it just 'cargo test' in there (after fixing the dependencies to point at my plonky2 branch)? Or something more involved? Thanks!

Btw, do you have a way to run some benchmarks for zk_evm? I mean, I found some micro-benchmarks in the repo, but I'm looking for something more substantial that covers more of the system (but hopefully doesn't run for longer than a minute or perhaps five at most for one iteration).

That's because I have some ideas for speeding up plonky2 that work for our system, but I want to make sure they don't make life worse for you.

(And chances are, if it helps two unrelated system, it's probably a good idea in general.)

@Nashtare
Copy link
Collaborator

@matthiasgoergens For testing, yes you can just run cargo --release --test --package evm_arithmetization within zk_evm repo: https://github.com/0xpolygonzero/zk_evm/.

For benchmarking purposes, we usually would do it against real-life examples, with zero-bin: https://github.com/0xpolygonzero/zero-bin/. There you can use the stdio mode to pass a block trace as input, and generate an entire proof for the block. If you need an access endpoint / block traces to play with, feel free to reach me in DM.

field/src/types.rs Outdated Show resolved Hide resolved
starky/src/cross_table_lookup.rs Outdated Show resolved Hide resolved
starky/src/cross_table_lookup.rs Outdated Show resolved Hide resolved
@Nashtare
Copy link
Collaborator

Nashtare commented Jun 4, 2024

@matthiasgoergens Could you address the few comments / rebase with latest main so we can get this into the next release?

@matthiasgoergens matthiasgoergens force-pushed the matthias/looked-tables-upstream branch from 5ef7b30 to e1c2acb Compare June 5, 2024 11:06
@matthiasgoergens
Copy link
Contributor Author

@matthiasgoergens Could you address the few comments / rebase with latest main so we can get this into the next release?

Please see the new version.

.map(|table| table.table)
.counts()
.into_iter()
.sorted()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We sort to keep the debug output deterministic.

@Nashtare Nashtare added this to the Cleanups and Misc. milestone Jun 5, 2024
Comment on lines +335 to +344
log::debug!(
"Processing CTL for {:?}",
looking_tables
.iter()
.map(|table| table.table)
.counts()
.into_iter()
.sorted()
.collect::<Vec<_>>()
);
Copy link
Collaborator

@Nashtare Nashtare Jun 5, 2024

Choose a reason for hiding this comment

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

At this point I think I may prefer just specifying for which table the CTL is, i.e.

Suggested change
log::debug!(
"Processing CTL for {:?}",
looking_tables
.iter()
.map(|table| table.table)
.counts()
.into_iter()
.sorted()
.collect::<Vec<_>>()
);
log::debug!(
"Processing CTL for STARK table {:?}",
looking_tables
.last().
.expect("We always have a looked table.")
.table
);

or otherwise removing it altogether. The current display doesn't carry much meaning (especially with the sorting which kind of hides which table is being looked at). For example this is our zkEVM output with this implem:

[DEBUG starky::cross_table_lookup] Processing CTL for [(0, 1), (2, 1)]
[DEBUG starky::cross_table_lookup] Processing CTL for [(1, 1), (2, 4)]
[DEBUG starky::cross_table_lookup] Processing CTL for [(2, 1), (4, 1)]
[DEBUG starky::cross_table_lookup] Processing CTL for [(3, 1), (4, 1)]
[DEBUG starky::cross_table_lookup] Processing CTL for [(3, 1), (4, 1)]
[DEBUG starky::cross_table_lookup] Processing CTL for [(2, 1), (4, 5), (5, 1)]
[DEBUG starky::cross_table_lookup] Processing CTL for [(1, 32), (2, 7), (4, 136), (6, 1)]

gio256 added a commit to gio256/rizzo that referenced this pull request Jun 18, 2024
@gio256
Copy link
Contributor

gio256 commented Jun 18, 2024

@matthiasgoergens thanks for this PR.

Can I be of any help getting this across the line? Happy to take it from here or just get it caught up to main.

@Nashtare Nashtare modified the milestones: Misc., System strengthening Jul 12, 2024
@Nashtare
Copy link
Collaborator

Nashtare commented Aug 6, 2024

Closing for inactivity.
@gio256 feel free to pick it up if you want to / have some free time.

@Nashtare Nashtare closed this Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants