Add bounds check to Assignment::query_instance impls.

This commit is contained in:
Sean Bowe 2021-07-10 08:25:00 -06:00
parent c4e2554654
commit 9023161988
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
4 changed files with 13 additions and 3 deletions

View File

@ -297,6 +297,10 @@ impl<F: Field + Group> Assignment<F> for MockProver<F> {
}
fn query_instance(&self, column: Column<Instance>, row: usize) -> Result<Option<F>, Error> {
if !self.usable_rows.contains(&row) {
return Err(Error::BoundsFailure);
}
self.instance
.get(column.index())
.and_then(|column| column.get(row))

View File

@ -308,8 +308,6 @@ impl<F: Field> Assignment<F> for Layout {
self.assign_fixed(annotation, selector.0, row, || Ok(F::one()))
}
/// Query the value of the cell of an instance column at a particular
/// absolute row, if known.
fn query_instance(&self, _: Column<Instance>, _: usize) -> Result<Option<F>, Error> {
Ok(None)
}

View File

@ -83,7 +83,11 @@ impl<F: Field> Assignment<F> for Assembly<F> {
self.assign_fixed(annotation, selector.0, row, || Ok(F::one()))
}
fn query_instance(&self, _: Column<Instance>, _: usize) -> Result<Option<F>, Error> {
fn query_instance(&self, _: Column<Instance>, row: usize) -> Result<Option<F>, Error> {
if !self.usable_rows.contains(&row) {
return Err(Error::BoundsFailure);
}
// There is no instance in this context.
Ok(None)
}

View File

@ -166,6 +166,10 @@ pub fn create_proof<
column: Column<Instance>,
row: usize,
) -> Result<Option<F>, Error> {
if !self.usable_rows.contains(&row) {
return Err(Error::BoundsFailure);
}
self.instances
.get(column.index())
.and_then(|column| column.get(row))