From 90231619888635e13eca0ba6d8b8f378ccc23dc3 Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Sat, 10 Jul 2021 08:25:00 -0600 Subject: [PATCH] Add bounds check to Assignment::query_instance impls. --- src/dev.rs | 4 ++++ src/dev/graph/layout.rs | 2 -- src/plonk/keygen.rs | 6 +++++- src/plonk/prover.rs | 4 ++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/dev.rs b/src/dev.rs index 7bfa869d..ed93f450 100644 --- a/src/dev.rs +++ b/src/dev.rs @@ -297,6 +297,10 @@ impl Assignment for MockProver { } fn query_instance(&self, column: Column, row: usize) -> Result, Error> { + if !self.usable_rows.contains(&row) { + return Err(Error::BoundsFailure); + } + self.instance .get(column.index()) .and_then(|column| column.get(row)) diff --git a/src/dev/graph/layout.rs b/src/dev/graph/layout.rs index 389e721b..bb8cdf7f 100644 --- a/src/dev/graph/layout.rs +++ b/src/dev/graph/layout.rs @@ -308,8 +308,6 @@ impl Assignment 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, _: usize) -> Result, Error> { Ok(None) } diff --git a/src/plonk/keygen.rs b/src/plonk/keygen.rs index 4be0af08..ae2d1488 100644 --- a/src/plonk/keygen.rs +++ b/src/plonk/keygen.rs @@ -83,7 +83,11 @@ impl Assignment for Assembly { self.assign_fixed(annotation, selector.0, row, || Ok(F::one())) } - fn query_instance(&self, _: Column, _: usize) -> Result, Error> { + fn query_instance(&self, _: Column, row: usize) -> Result, Error> { + if !self.usable_rows.contains(&row) { + return Err(Error::BoundsFailure); + } + // There is no instance in this context. Ok(None) } diff --git a/src/plonk/prover.rs b/src/plonk/prover.rs index 82d54750..d3e0ae3a 100644 --- a/src/plonk/prover.rs +++ b/src/plonk/prover.rs @@ -166,6 +166,10 @@ pub fn create_proof< column: Column, row: usize, ) -> Result, Error> { + if !self.usable_rows.contains(&row) { + return Err(Error::BoundsFailure); + } + self.instances .get(column.index()) .and_then(|column| column.get(row))