Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Add an assert that there is no placeholder in a public input location (
Browse files Browse the repository at this point in the history
…#12)

# What ❔

This PR adds an assert that there is no placeholder in a public input
location.

## Why ❔

When there is a mismatch between the setup and the witness data a
placeholder index can appear in a public input location and generate a
generic index out of bounds error. This adds an explicit check with a
descriptive error message.

## Checklist

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Code has been formatted via `cargo fmt` and linted via `cargo
check`.
  • Loading branch information
robik75 authored Nov 13, 2023
1 parent 937b5e8 commit bb3d4ad
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ pub fn gpu_prove_from_external_witness_data<
.cloned()
{
let variable_idx = setup.variables_hint[col][row].clone() as usize;
assert_eq!(
variable_idx & (1 << 31),
0,
"placeholder found in a public input location"
);
let value = external_witness_data.all_values[variable_idx];
public_inputs_with_locations.push((col, row, value));
}
Expand Down
45 changes: 45 additions & 0 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,51 @@ mod zksync {
compare_proofs(&reference_proof, &actual_proof);
}

#[serial]
#[test]
#[ignore]
#[should_panic]
fn test_public_input_placeholder_fail() {
let (setup_cs, finalization_hint) = init_cs_for_sha256::<DevCSConfig>(None);
let worker = Worker::new();
let proof_config = init_proof_cfg();
let (setup_base, _, vk, setup_tree, vars_hint, wits_hint) = setup_cs.get_full_setup(
&worker,
proof_config.fri_lde_factor,
proof_config.merkle_tree_cap_size,
);
let domain_size = setup_cs.max_trace_len;
let _ctx = ProverContext::dev(domain_size).expect("init gpu prover context");
let (mut proving_cs, _) = init_cs_for_sha256::<ProvingCSConfig>(finalization_hint.as_ref());
let mut witness = proving_cs.materialize_witness_vec();
let mut gpu_setup = GpuSetup::<Global>::from_setup_and_hints(
setup_base.clone(),
clone_reference_tree(&setup_tree),
vars_hint.clone(),
wits_hint.clone(),
&worker,
)
.expect("gpu setup");
witness.public_inputs_locations = vec![(0, 0)];
gpu_setup.variables_hint[0][0] = 1 << 31;
let _ = gpu_prove_from_external_witness_data::<
_,
DefaultTranscript,
DefaultTreeHasher,
NoPow,
Global,
>(
&proving_cs,
&witness,
proof_config.clone(),
&gpu_setup,
&vk,
(),
&worker,
)
.expect("gpu proof");
}

#[serial]
#[test]
#[ignore]
Expand Down

0 comments on commit bb3d4ad

Please sign in to comment.