Skip to content

Conversation

@antoniolocascio
Copy link
Contributor

@antoniolocascio antoniolocascio commented Nov 21, 2025

What ❔

This PR changes the way we compute prover input. Before, we needed to run the slow risc-v simulator to do so.
Now, we can do on native architecture.
This run is also responsible for computing the pubdata.

Why ❔

Is this a breaking change?

  • Yes
  • No

Checklist

  • PR title corresponds to the body of PR (we generate changelog entries from PRs).
  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • Code has been formatted.

@antoniolocascio antoniolocascio marked this pull request as draft November 21, 2025 09:30
@antoniolocascio antoniolocascio force-pushed the alocascio-prover-input-run branch 4 times, most recently from 87e48b7 to b10b28e Compare November 21, 2025 13:13
@antoniolocascio antoniolocascio force-pushed the alocascio-prover-input-run branch from e50f65d to 982db5c Compare November 26, 2025 11:10
@antoniolocascio antoniolocascio marked this pull request as ready for review November 26, 2025 11:11
@antoniolocascio antoniolocascio force-pushed the alocascio-prover-input-run branch from 982db5c to 261e5bf Compare November 26, 2025 11:13
To be used in testing
Copy link
Contributor

@AntonD3 AntonD3 left a comment

Choose a reason for hiding this comment

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

Overall this looks great, left a few minor comments and questions

Comment on lines +60 to +61
zksync_os_evm_errors = { git = "https://github.com/matter-labs/zksync-os-interface", branch = "alocascio-prover-input-gen", default-features = false }
zksync_os_interface = { git = "https://github.com/matter-labs/zksync-os-interface", branch = "alocascio-prover-input-gen", version = "0.0.10"}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thread to remember to merge this and fix here

@antoniolocascio antoniolocascio force-pushed the alocascio-prover-input-run branch 5 times, most recently from 9d6adc3 to 9327836 Compare November 27, 2025 12:41
@antoniolocascio antoniolocascio force-pushed the alocascio-prover-input-run branch from 9327836 to feaf0c4 Compare November 27, 2025 12:47
Copy link
Contributor

@AntonD3 AntonD3 left a comment

Choose a reason for hiding this comment

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

Overall looks good, there are some things that are not very clear for me around arithmetic advice(asked questions in comments), and please consider that it requires non-trivial integration from the platform side - pubdata is now not available from forward run

unsafe {
let num_digits = to_consume.next_multiple_of(8) / 8;
const BIGINT_DIGIT_USIZE_SIZE: usize = U256::BYTES / core::mem::size_of::<usize>();
let num_digits =
Copy link
Contributor

Choose a reason for hiding this comment

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

it's confusing, I see that you haven't change it, but probably better to name this variable num_bigints if I undertand it correctly

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 agree, but I see the term "digit" being used for it in other methods/interface (even on the other modexp impl). If you don't mind, I would not change it here, as the PR is unrelated

}
// We use different advice params depending on architecture
// Both are mostly the same, main difference is the width of pointers
#[cfg(target_arch = "riscv32")]
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe better to have cfg based on pointer width, so it will work on non risc 32 bit architectures

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm we have #[cfg(target_arch = "riscv32")] all over the place, we don't really support other 32 bit arch.

let packed_lens = it.next().expect("packed lengths");
let q_len = (packed_lens & 0xFFFF_FFFF) as usize;
let r_len = (packed_lens >> 32) as usize;
(it, q_len / 2, r_len / 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we have to divide by 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Clarified

pub b_len: u32, // Length of divisor in words
pub modulus_ptr: u32, // Pointer to modulus
pub modulus_len: u32, // Length of modulus in words
pub struct ModExpAdviceParamsGeneric<W> {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we just use usize?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This type is used at the interface of the oracle (it's created in the ArithmeticQuery oracle processor, which runs on native), so I wanted to avoid it being architecture-dependent.

let quotient = strip_leading_zeroes(&self.quotient);
let remainder = strip_leading_zeroes(&self.remainder);

// account for usize being u64 here
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should we assert that usize indeed is 64 bit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This crate is not part of the risc-v binary (and it should never be). We don't really support 32-bit arch for sequencing, so I would say it's not needed

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

Benchmark report

Benchmark Symbol Base Eff Head Eff (%) Base Raw Head Raw (%) Base Blake Head Blake (%) Base Bigint Head Bigint (%)
block_19299001 run_prepared 310,878,540 310,878,786 (+0.00%) 268,212,764 268,213,010 (+0.00%) 410,610 410,610 (+0.00%) 9,024,004 9,024,004 (+0.00%)
block_22244135 run_prepared 191,043,084 191,043,321 (+0.00%) 164,127,024 164,127,261 (+0.00%) 172,020 172,020 (+0.00%) 6,040,935 6,040,935 (+0.00%)
precompiles bn254_ecadd 53,197 53,197 (+0.00%) 47,745 47,745 (+0.00%) 0 0 (+0.00%) 1,363 1,363 (+0.00%)
precompiles bn254_ecmul 731,034 731,034 (+0.00%) 566,846 566,846 (+0.00%) 0 0 (+0.00%) 41,047 41,047 (+0.00%)
precompiles bn254_pairing 72,689,618 72,689,618 (+0.00%) 58,161,474 58,161,474 (+0.00%) 0 0 (+0.00%) 3,632,036 3,632,036 (+0.00%)
precompiles ecrecover 480,358 480,152 (-0.04%) 311,626 311,568 (-0.02%) 0 0 (+0.00%) 42,183 42,146 (-0.09%)
precompiles id 933 933 (+0.00%) 933 933 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%)
precompiles keccak 137,578 137,578 (+0.00%) 137,578 137,578 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%)
precompiles modexp 32,084,944 32,084,944 (+0.00%) 21,427,124 21,427,124 (+0.00%) 0 0 (+0.00%) 2,664,455 2,664,455 (+0.00%)
precompiles p256_verify 750,769 750,769 (+0.00%) 472,077 472,077 (+0.00%) 0 0 (+0.00%) 69,673 69,673 (+0.00%)
precompiles point_evaluation 51,158,394 51,158,394 (+0.00%) 39,535,766 39,535,766 (+0.00%) 0 0 (+0.00%) 2,905,657 2,905,657 (+0.00%)
precompiles process_transaction 73,838,983 73,833,959 (-0.01%) 59,134,563 59,137,827 (+0.01%) 160 160 (+0.00%) 3,675,465 3,673,393 (-0.06%)
precompiles ripemd 8,028 8,028 (+0.00%) 8,028 8,028 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%)
precompiles run_prepared 148,160,585 148,149,815 (-0.01%) 118,676,585 118,682,675 (+0.01%) 5,070 5,050 (-0.39%) 7,350,720 7,346,585 (-0.06%)
precompiles sha256 13,167 13,167 (+0.00%) 13,167 13,167 (+0.00%) 0 0 (+0.00%) 0 0 (+0.00%)
precompiles verify_and_apply_batch 131,323 132,170 (+0.64%) 96,923 97,450 (+0.54%) 2,150 2,170 (+0.93%) 0 0 (+0.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.

2 participants