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

feat: Enable more optional tables #724

Merged
merged 142 commits into from
Oct 18, 2024
Merged

feat: Enable more optional tables #724

merged 142 commits into from
Oct 18, 2024

Conversation

sai-deng
Copy link
Contributor

@sai-deng sai-deng commented Oct 14, 2024

In addition to Keccak tables #620 , this PR enables BytePacking, Logic, MemAfter, and Poseidon tables as optional tables in the root circuit, reducing table proving time and recursion time.

Root circuit size change:

Before this PR

Degree before blinding & padding: 39137
Degree after blinding & padding: 65536

After this PR

Degree before blinding & padding: 43738
Degree after blinding & padding: 65536

Recursion Proving Time After this PR:

CPU halted after 255 cycles
CPU halted after 255 cycles
CPU trace padded to 256 cycles
Keccak table not in use
KeccakSponge table not in use
Logic table not in use
Trace lengths (before padding): TraceCheckpoint { arithmetic_len: 65, byte_packing_len: 2, cpu_len: 256, keccak_len: 0, keccak_sponge_len: 0, logic_len: 0, memory_len: 65443 }, mem_before_len: 64547, mem_after_len: 64557
4.2065s to Recursion Time
 | 0.9084s to Normal recursion
 | 0.3007s to Normal recursion
 | 0.2974s to Normal recursion
 | 0.0007s to Dummy recursion
 | 0.0001s to Dummy recursion
 | 0.0002s to Dummy recursion
 | 0.8890s to Normal recursion
 | 0.8868s to Normal recursion
 | 0.9231s to Normal recursion

CPU halted after 255 cycles
CPU halted after 255 cycles
CPU trace padded to 256 cycles
Trace lengths (before padding): TraceCheckpoint { arithmetic_len: 62, byte_packing_len: 4, cpu_len: 256, keccak_len: 24, keccak_sponge_len: 1, logic_len: 5, memory_len: 65455 }, mem_before_len: 64557, mem_after_len: 64558
9.5262s to Recursion Time
 | 0.9100s to Normal recursion
 | 0.3236s to Normal recursion
 | 0.3210s to Normal recursion
 | 2.8789s to Normal recursion
 | 1.5076s to Normal recursion
 | 0.8986s to Normal recursion
 | 0.9040s to Normal recursion
 | 0.8762s to Normal recursion
 | 0.9063s to Normal recursion

Base automatically changed from sai/refactor_optional_table_proving to develop October 15, 2024 22:20
@sai-deng
Copy link
Contributor Author

I have successfully tested this PR on block 448 in the test chain.

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.

LGTM, thanks! Just a couple of nits

evm_arithmetization/src/fixed_recursive_verifier.rs Outdated Show resolved Hide resolved
evm_arithmetization/src/fixed_recursive_verifier.rs Outdated Show resolved Hide resolved
evm_arithmetization/src/generation/mod.rs Outdated Show resolved Hide resolved
evm_arithmetization/src/proof.rs Outdated Show resolved Hide resolved
evm_arithmetization/src/testing_utils.rs Outdated Show resolved Hide resolved
@sai-deng
Copy link
Contributor Author

LGTM, thanks! Just a couple of nits

Thank you for the careful review!

Copy link
Collaborator

@Nashtare Nashtare left a comment

Choose a reason for hiding this comment

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

Thanks Sai, nice improvement overall! Just a couple nitpicky comments for readabily, otherwise looks good

let mut table_in_use = [true; NUM_TABLES];
if state.traces.keccak_inputs.is_empty() && OPTIONAL_TABLE_INDICES.contains(&Table::Keccak) {
assert!(OPTIONAL_TABLE_INDICES.contains(&Table::KeccakSponge));
info!("Keccak and KeccakSponge tables not in use");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think my outdated comment got lost during refactoring, I was suggesting to remove all these info! messages as they can get a bit noisy and are sharing information that is already guessable from the TraceCheckpoint displayed on every segment proof.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, they serve different purposes. We have the config to choose which table should be optional, but I’m fine with changing them to log::debug.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I'd rather at least put them one level lower, to Debug. Info should really be only for meaningful outputs.

Comment on lines 623 to 626
if final_len == 0 && OPTIONAL_TABLE_INDICES.contains(&MemAfter) {
info!("MemAfter table not in use");
table_in_use[*MemAfter] = false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: we don't need to expose final_len. MemAfter is empty when there is nothing to propagate (final segment), which can be retrieved as so:

Suggested change
if final_len == 0 && OPTIONAL_TABLE_INDICES.contains(&MemAfter) {
info!("MemAfter table not in use");
table_in_use[*MemAfter] = false;
}
let is_last_segment = next_data.registers_after.program_counter == KERNEL.global_labels["halt"];
if is_last_segment && OPTIONAL_TABLE_INDICES.contains(&MemAfter) {
table_in_use[*MemAfter] = false;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The bool table_in_use is directly dependent on the length of trace rows. If there’s any change between is_last_segment and the length of trace rows (although it’s unlikely), then mem_after will not be empty, and we might encounter some bugs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm I can't see why we would ever get a non-empty final MemAfter, as there is nothing to propagate though, and we would catch the discrepancy anyway as we'd have conflicts in the challenges

&ctl_data_per_table[*$table],
ctl_challenges,
challenger,
if !OPTIONAL_TABLE_INDICES.contains(&$table) || table_in_use[*$table] {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if !OPTIONAL_TABLE_INDICES.contains(&$table) || table_in_use[*$table] {
if table_in_use[*$table] {

slightly more concise, and the shortcut from the first bool condition is not significant enough

@Nashtare
Copy link
Collaborator

I forgot to mention it in the review, but a next step could be to also skip altogether the commit phase for each of these tables, especially as some of these tables are padded to a default value larger than the cap length due to their permutation argument.

@sai-deng
Copy link
Contributor Author

I forgot to mention it in the review, but a next step could be to also skip altogether the commit phase for each of these tables, especially as some of these tables are padded to a default value larger than the cap length due to their permutation argument.

Yes, this would require a significant refactor of how CTL works, including changes to Plonky2, with minimal performance gains. I’ll work on it, but I believe it’s a low priority for now

@Nashtare
Copy link
Collaborator

I forgot to mention it in the review, but a next step could be to also skip altogether the commit phase for each of these tables, especially as some of these tables are padded to a default value larger than the cap length due to their permutation argument.

Yes, this would require a significant refactor of how CTL works, including changes to Plonky2, with minimal performance gains. I’ll work on it, but I believe it’s a low priority for now

Yeah we can just make it a tracking ticket for now.

@sai-deng sai-deng merged commit ae6c3c4 into develop Oct 18, 2024
20 checks passed
@sai-deng sai-deng deleted the sai/more_optional_tables branch October 18, 2024 18:21
@sai-deng
Copy link
Contributor Author

Thanks for reviewing! Comments are addressed, and the PR is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate: evm_arithmetization Anything related to the evm_arithmetization crate.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants