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

RISC-V machine: Use dynamic VADCOP #1683

Merged
merged 10 commits into from
Aug 15, 2024
Merged

RISC-V machine: Use dynamic VADCOP #1683

merged 10 commits into from
Aug 15, 2024

Conversation

georgwiese
Copy link
Collaborator

@georgwiese georgwiese commented Aug 13, 2024

Builds on #1687
Fixed #1572

With this PR, we are using dynamic VADCOP in the RISC-V zk-VM.

There were a few smaller fixes needed to make this work. In summary, the changes are as follows:

  • We set the degree the main machine to None, and all fixed lookup machines to the appropriate size. As a consequence, the CPU, all block machines & memory have a dynamic size.
  • As a consequence, I had to adjust some tests (set the size of all machines, so they can still be run with monolithic provers) and was able to remove the Memory_<size> machines 🎉
  • With the main machine being of flexible size, the prover can chose for how long to run it. We run it for 1 << (MAX_DEGREE_LOG - 2) steps and compute the bootloader inputs accordingly. With this choice, we can guarantee that the register memory (which can be up to 4x larger than the main machine) does not run out of rows.

Note that while we do access MAX_DEGREE_LOG in a bunch of places now, this will go away once #1667 is merged, which will allow us to configure the degree range in ASM and for each machine individually.

Example:

export MAX_LOG_DEGREE=18
cargo run -r --bin powdr-rs compile riscv/tests/riscv_data/many_chunks -o output --continuations
cargo run -r --bin powdr-rs execute output/many_chunks.asm -o output --continuations -w
cargo run -r --features plonky3,halo2 prove output/many_chunks.asm -d output/chunk_0 --field gl --backend plonky3-composite

This leads to the following output:

== Proving machine: main (size 65536), stage 0
==> Proof stage computed in 1.918317417s
== Proving machine: main__rom (size 8192), stage 0
==> Proof stage computed in 45.847375ms
== Proving machine: main_binary (size 1024), stage 0
==> Proof stage computed in 27.718416ms
== Proving machine: main_bit2 (size 4), stage 0
==> Proof stage computed in 15.280667ms
== Proving machine: main_bit6 (size 64), stage 0
==> Proof stage computed in 17.449875ms
== Proving machine: main_bit7 (size 128), stage 0
==> Proof stage computed in 20.717834ms
== Proving machine: main_bootloader_inputs (size 262144), stage 0
==> Proof stage computed in 524.013375ms
== Proving machine: main_byte (size 256), stage 0
==> Proof stage computed in 17.280167ms
== Proving machine: main_byte2 (size 65536), stage 0
==> Proof stage computed in 164.709625ms
== Proving machine: main_byte_binary (size 262144), stage 0
==> Proof stage computed in 504.743917ms
== Proving machine: main_byte_compare (size 65536), stage 0
==> Proof stage computed in 169.881542ms
== Proving machine: main_byte_shift (size 65536), stage 0
==> Proof stage computed in 146.235916ms
== Proving machine: main_memory (size 32768), stage 0
==> Proof stage computed in 326.522167ms
== Proving machine: main_poseidon_gl (size 16384), stage 0
==> Proof stage computed in 1.324662625s
== Proving machine: main_regs (size 262144), stage 0
==> Proof stage computed in 2.009408667s
== Proving machine: main_shift (size 32), stage 0
==> Proof stage computed in 13.71825ms
== Proving machine: main_split_gl (size 16384), stage 0
==> Proof stage computed in 108.019334ms
Proof generation took 7.364567s
Proof size: 8432928 bytes
Writing output/chunk_0/many_chunks_proof.bin.

Note that main_bootloader_inputs is still equal to the maximum size, we should fix that in a following PR!

@georgwiese georgwiese changed the base branch from main to fix-range-constraint-detection August 14, 2024 13:29
@georgwiese georgwiese force-pushed the fix-range-constraint-detection branch from 080adf2 to e17c57b Compare August 14, 2024 13:36
github-merge-queue bot pushed a commit that referenced this pull request Aug 14, 2024
When making fixed lookup machines smaller in the RISC-V VM (#1683), I
came across the issue that range-constraint lookups (e.g. `[two_bits] in
[TWO_BITS]` where `TWO_BITS = [0, 1, 2, 3]`) where not recognized as
such if the fixed column was *just* the right size (in the above
example, `TWO_BITS = [0, 1, 2, 3, 0]` would have worked).
Base automatically changed from fix-range-constraint-detection to main August 14, 2024 14:26
@georgwiese georgwiese force-pushed the riscv-dynamic-vadcop branch 2 times, most recently from 197047e to a022fa3 Compare August 14, 2024 14:37
@georgwiese georgwiese changed the base branch from main to fake-byte2 August 14, 2024 14:37
Comment on lines -378 to -388
if let Some(external_values) = &external_values {
if external_values.len() != poly.degree.unwrap() as usize {
log::debug!(
"External witness values for column {} were only partially provided \
(length is {} but the degree is {})",
name,
external_values.len(),
poly.degree.unwrap()
);
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can't really check this easily anymore with dynamic sizes, and it was only a debug log anyway.

@@ -11,7 +11,7 @@ on:
env:
CARGO_TERM_COLOR: always
POWDR_GENERATE_PROOFS: "true"
MAX_DEGREE_LOG: "10"
MAX_DEGREE_LOG: "20"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Had to increase, because otherwise the RISC-V tests would run only for 256 rows... Now, it is $2^{18}$, as before this PR. It doesn't seem like it has a big impact on test time (we don't have too many dynamic VADCOP tests and the RISC-V tests are slow anyway).

Copy link
Member

Choose a reason for hiding this comment

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

we should also add log 22 tests at some point

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

After #1667, we can configure the range for each test and machine individually, should be much better than this global setting.

@georgwiese georgwiese changed the title [WIP] RISC-V machine: Use dynamic VADCOP RISC-V machine: Use dynamic VADCOP Aug 14, 2024
@georgwiese georgwiese marked this pull request as ready for review August 14, 2024 20:11
@@ -66,17 +66,17 @@ pub struct VmProcessor<'a, 'b, 'c, T: FieldElement, Q: QueryCallback<T>> {
}

impl<'a, 'b, 'c, T: FieldElement, Q: QueryCallback<T>> VmProcessor<'a, 'b, 'c, T, Q> {
#[allow(clippy::too_many_arguments)]
Copy link
Member

Choose a reason for hiding this comment

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

aha

leonardoalt
leonardoalt previously approved these changes Aug 15, 2024
Copy link
Member

@leonardoalt leonardoalt left a comment

Choose a reason for hiding this comment

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

Awesome!

github-merge-queue bot pushed a commit that referenced this pull request Aug 15, 2024
Pulled out of #1683 

Because our memory machine requires a `Byte2` machine to range-check
some values, we need to provide that machine in any test that uses
memory. But that machine needs a size of $2^{16}$, which is a lot for
just some simple tests.

Previously, the `Byte2` machine did not have a size set (this will
change in #1683), so it would just get the size of the main machine.
This works because in our simple tests, the values are small enough in
practice. But really, this breaks an assumption of the `Byte2` machine.

With this PR, this is explicit, with all the affected test (that we want
to keep small) using `std::machines::test_util::FakeByte2` instead of
`std::machines::range::Byte2`. Note that this is exploiting the fact
that we're not type checking the machine passed to memory. But the
alternative would be to copy the memory machine and use that in the
test.
Base automatically changed from fake-byte2 to main August 15, 2024 09:08
@leonardoalt leonardoalt dismissed their stale review August 15, 2024 09:08

The base branch was changed.

@leonardoalt
Copy link
Member

has conflicts now

@georgwiese
Copy link
Collaborator Author

has conflicts now

I rebased onto main (works much better than merge when a branch you were building on was merged...)

@georgwiese georgwiese added this pull request to the merge queue Aug 15, 2024
Merged via the queue into main with commit 34fdbd1 Aug 15, 2024
14 checks passed
@georgwiese georgwiese deleted the riscv-dynamic-vadcop branch August 15, 2024 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic VADCOP
2 participants