-
Notifications
You must be signed in to change notification settings - Fork 156
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
Expects negative public inputs #717
Comments
the above example does not reproduce the bug since it appends the public input to the circuit in its negative form and so the returned public inputs can be expected to be negative as well. to reproduce run: use dusk_plonk::prelude::*;
use rand::rngs::StdRng;
use rand::SeedableRng;
#[derive(Debug, Default)]
pub struct TestCircuit {
a: BlsScalar,
b: BlsScalar,
c: BlsScalar,
}
impl Circuit for TestCircuit {
fn circuit<C>(&self, composer: &mut C) -> Result<(), Error>
where
C: Composer,
{
let a = composer.append_witness(self.a);
let b = composer.append_witness(self.b);
// append the gate a + b = c twice in a slightly different way:
// This will result in a positive public input value
let constraint = Constraint::new().left(1).right(1).a(a).b(b).public(self.c);
composer.gate_add(constraint);
// This will result in a negative public input value
let c = composer.append_public(self.c);
let constraint = Constraint::new().left(1).right(1).a(a).b(b);
let result = composer.gate_add(constraint);
composer.assert_equal(result, c);
Ok(())
}
}
fn main() {
let label = b"transcript-arguments";
let mut rng = StdRng::seed_from_u64(0xbeef);
let pp = PublicParameters::setup(1 << 5, &mut rng).expect("failed to setup");
let (prover, verifier) =
Compiler::compile::<TestCircuit>(&pp, label).expect("failed to compile circuit");
let circuit = TestCircuit {
a: BlsScalar::from(2),
b: BlsScalar::from(2),
c: BlsScalar::from(4),
};
// Generate the proof and its public inputs
let (proof, pi) = prover.prove(&mut rng, &circuit).expect("failed to prove");
// Here the inconsistency becomes apparent:
// the first public input is as it should, the second is negated
assert_eq!(pi[0], BlsScalar::from(4));
assert_eq!(pi[1], -BlsScalar::from(4));
// Verify the generated proof
verifier
.verify(&proof, &pi)
.expect("failed to verify proof");
} |
In my example above, we want to express the same constraint In the first gate, we append the public input value In the second gate we first append the public value to the circuit and then constrain it to be This shows that the use of public inputs is inconsistent which results in unexpected behavior. |
See also plonk issue [#717](dusk-network/plonk#717)
See also: plonk issue [#717](dusk-network/plonk#717) phoenix-core issue [#123](dusk-network/phoenix#123)
Describe the bug
The current implementation will produce negative public inputs(PIs). This is incredibly confusing and unexpected. The proving algorithm in the
Prover::prove
functions produces PIs that are the negative of what is expected, andVerifier::verify
expects them to be negative as well.To Reproduce
Run
cargo t
with this code to reproduce:Expected behaviour
I would expect the test to fail on the
assert_eq
marked with theFIXME
comment, but this is not the case.Additional context
This was discovered during an effort to port of the transfer contract to
piecrust
.The text was updated successfully, but these errors were encountered: