Skip to content
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

[question]: how to use the borrow instruction #332

Closed
dantengsky opened this issue Aug 1, 2019 · 4 comments · Fixed by #333
Closed

[question]: how to use the borrow instruction #332

dantengsky opened this issue Aug 1, 2019 · 4 comments · Fixed by #333

Comments

@dantengsky
Copy link

Hi,

I am trying to figure out how to use the borrow instruction.

Based on the code of zkvm/tests/zkvm.rs, I added a simple(failed) test case as follows

#[test]
fn borrow_output() {
    //inputs 10 units, borrows 5 units, outputs two (5 units)
    let flv = Scalar::from(1u64);
    let (preds, scalars) = generate_predicates(3);
    let borrow_prog = Program::build(|p| {
        p.input_helper(10, flv, preds[1].clone()) // stack: Value(10,1)
            .push(Commitment::blinded(5u64))      // stack: Value(10,1), qty(5)
            .var()                                // stack: Value(10,1), qty-var(5)
            .push(Commitment::blinded(flv))       // stack: Value(10,1), qty-var(5),   flv(1)
            .var()                                // stack: Value(10,1), qty-var(5),   flv-var(1)
            .borrow()                             // stack: Value(10,1), Value(-5, 1), Value(5,1)
            .output_helper(preds[0].clone())      // stack: Value(10,1), Value(-5, 1); outputs (5,1)
            .cloak_helper(2, vec![(5u64, flv)])   // stack:  Value(5,1)
            .output_helper(preds[2].clone())      // outputs (5,1)
    });
    build_and_verify(borrow_prog, &vec![scalars[1].clone()]).unwrap();
}

cargo test outputs

thread 'xxxx' panicked at 'called `Result::unwrap()` on an `Err` value: InvalidR1CSProof'

Where did I make a mistake?

Thanks a lot!

@oleganza
Copy link
Contributor

oleganza commented Aug 1, 2019

Thanks for reporting, I will look into that!

@oleganza
Copy link
Contributor

oleganza commented Aug 1, 2019

Hi, this PR #333 fixes this bug. Will merge soon.

oleganza added a commit that referenced this issue Aug 1, 2019
* zkvm: fix borrow implementation per #332
* bump rust-toolchain to match bulletproofs
@oleganza
Copy link
Contributor

oleganza commented Aug 1, 2019

This is fixed now, thank you again!

@dantengsky
Copy link
Author

My apologies for the slow reply, really grateful for your help!

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 a pull request may close this issue.

2 participants