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

Bring in QED-it Tests #93

Merged
merged 29 commits into from
Oct 8, 2019
Merged

Bring in QED-it Tests #93

merged 29 commits into from
Oct 8, 2019

Conversation

defuse
Copy link
Contributor

@defuse defuse commented Jul 25, 2019

This PR was originally submitted here: zcash/sapling-crypto#101

This pulls in a bunch of tests QED-it wrote during their audit that were spread across many branches in their sapling-crypto-internal repository. I've left their history intact so the best way to review it is to just look at the final diff, except for...

  • This commit, which includes changes outside of tests, and
  • This commit, which is my attempt to fix the broken linear relation testing in that commit (the check in that commit effectively just checks that p1 != p2 again, not what it was intended to do).
  • I deleted a find_group_hash test since it didn't look like it was doing anything useful, and I don't want merging to block on me figuring out how to implement that test well. Raise a separate issue and assign me if you would like some find_group_hash unit tests!

I did not bring in this change to the circuit code, because I don't understand it. I also did not bring in a bunch of changes to comments and variable renamings in the aurel_comments branch and the sum_bug branch, but I did bring in the new tests from those branches.

@defuse defuse self-assigned this Jul 25, 2019
@defuse
Copy link
Contributor Author

defuse commented Jul 25, 2019

This needs some cleanup and improvements before it can be merged. In particular the group_hash tests are incomplete. Edit: Done!

@defuse defuse changed the title Bring in QED-it Tests [WIP] Bring in QED-it Tests Jul 25, 2019
Copy link
Contributor Author

@defuse defuse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK. I didn't spend too long looking for errors in the tests, just made sure they are all doing something sane.


// take all the points from the script
// assert should be different than multiplying by cofactor, which is the solution
// is user input verified? https://github.com/zcash/librustzcash/blob/f5d2afb4eabac29b1b1cc860d66e45a5b48b4f88/src/rustzcash.rs#L299
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is talking about how we're missing an explicit check that ask != 0 in our code? Should I just delete these comments?

@defuse defuse changed the title [WIP] Bring in QED-it Tests Bring in QED-it Tests Jul 25, 2019
@defuse defuse removed their assignment Jul 26, 2019
@defuse
Copy link
Contributor Author

defuse commented Aug 1, 2019

Uh oh I accidentally pushed the branch to this repo, deleted it, then rebased and now Travis is broken: https://travis-ci.org/zcash/librustzcash/builds/566534948?utm_source=github_status&utm_medium=notification

$ git clone --depth=50 --branch=qed-it-lrz https://github.com/zcash/librustzcash.git zcash/librustzcash
Cloning into 'zcash/librustzcash'...
warning: Could not find remote branch qed-it-lrz to clone.
fatal: Remote branch qed-it-lrz not found in upstream origin

Why does it think there should be a qed-it-lrz in zcash/librustzcash?

@str4d
Copy link
Contributor

str4d commented Aug 19, 2019

Now that #104 has been merged, this PR needs to be refactored to account for sapling-crypto being split up. I can do this @defuse if you don't have time.

@str4d
Copy link
Contributor

str4d commented Aug 22, 2019

I've started rebasing this, and I've decided that I'm not going to preserve all history because there is a lot of cruft within the commits, and in particular there are some commits that are clearly mislabeled (the code they refer to appears in an adjacent commit, or spread across several commits). I will refactor retaining the intention of the changes, and as much authorship as I can.

@str4d str4d added this to the v0.1.0 milestone Aug 22, 2019
@str4d
Copy link
Contributor

str4d commented Aug 23, 2019

Rebased on master, cleaned up some of the commits (so they match what they say on the tin), and formatted most of the commits. The PR will probably need to be rebased again once #113 lands.

@str4d str4d requested review from ebfull, Eirik0 and str4d and removed request for ebfull August 24, 2019 00:05
Copy link
Contributor Author

@defuse defuse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK modulo my question about using just the first pedersen hash test vector.

zcash_primitives/src/pedersen_hash.rs Outdated Show resolved Hide resolved
@defuse
Copy link
Contributor Author

defuse commented Aug 29, 2019

Added a commit to make use of all the test vectors. That required increasing the number of Pedersen hash generators to 6. Someone should check that I did so correctly. Alternatively I can delete the test vectors that are too long.

I ran the entire suite of tests and they pass. :-)

Edit: Errrr what? I guess not?? Edit2: Oh, Travis is testing the merge with master not the PR by itself, it just needs to be rebased again (there are a few places crate:: needs to be prefixed to a use).

Copy link
Contributor

@Eirik0 Eirik0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was broken by #113. I added my suggestions locally and rebased on to master and was able to build without error.

zcash_primitives/src/pedersen_hash.rs Outdated Show resolved Hide resolved
zcash_primitives/src/test_vectors/pedersen_hash_vectors.rs Outdated Show resolved Hide resolved
zcash_primitives/src/test_vectors/pedersen_hash_vectors.rs Outdated Show resolved Hide resolved
let domain = domains[i];
let msg = msgs[i];

let gh: edwards::Point<Bls12, _> = find_group_hash(&msg, &domain, &params);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unused. The test appears to actually be testing that edwards::Point::get_for_y returns one of the expected x-coordinates, and not the output of find_group_hash at all.

(Edit: I see the test is deleted later.)

.write_u32::<LittleEndian>(m)
.unwrap();
let p: edwards::Point<Bls12, _> =
find_group_hash(&segment_number, b"Zcash_PH", &params);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p is unused.

(Edit: I see the test is deleted later.)

zcash_primitives/src/pedersen_hash.rs Outdated Show resolved Hide resolved
@@ -0,0 +1,716 @@
//! Test vectors from https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/sapling_pedersen.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually this means that the linked file can be used to generate the test vectors. We don't have the generation process for these test vectors yet; it would be good to find it. Non-blocking, because we can always update the test vectors later if there is a mismatch (although note that one of the commits from the audit explicitly tweaked some test vectors to test edge cases, so there may not be a simple generation process).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check_small_order_from_strs(
"948411088638444611740115537621561973758360269817276634325562542866802143934",
"19260245455242183936012133194672327304390353749328020389743628630787497879844",
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could extend this to test all points in all small-order subgroups, since there are so few of them (i.e. raise this to the power of 0..8 and check each one).

bellman/src/gadgets/boolean.rs Show resolved Hide resolved
zcash_primitives/src/jubjub/mod.rs Show resolved Hide resolved
}

// check for a generator being the sum of any other two
for (j, p2) in pedersen_hash_generators.iter().enumerate() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I experimented with trying to combine this loop with the one above, but wasn't able to get it to work properly. If this function were performance critical, we could first add all of the items to a HashSet, and then check if combinations of p1+p2 were in that set.

Copy link
Contributor

@Eirik0 Eirik0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK. I did not verify all of the test vectors, but I went through the changes to the production code, and everything looks good.

@str4d str4d merged commit 2399d9f into zcash:master Oct 8, 2019
ebfull pushed a commit to ebfull/librustzcash that referenced this pull request Mar 4, 2020
ebfull added a commit to ebfull/librustzcash that referenced this pull request Mar 4, 2020
2279da4 Merge pull request zcash#38 from debris/docs
2e57190 Remove documentation entry from Cargo.toml
346d540 bellman 0.2.0
8d79665 Merge pull request zcash#93 from defuse/qed-it-lrz
f50079f Crate docs
701cb2b Update READMEs
ccf1ee9 CI: Check intra-doc links
ddd390a Add READMEs to Cargo.toml files
54d3122 Add missing cs.is_satisfied() to bellman test
52bf23c Fix build warnings
581ad35 boolean: adds tests for alloc_conditionally
0403396 blake2s: adds test vectors from go-jubjub
9f24e47 Fix blake2s test data length assertion.
42d5b3b Add blake2s test vectors for varying sizes from go-jubjub
b2597de pedersen_hash: removes debug prints
c903fad pedersen hashes: example of size limit bug
bc697c1 bellman: Fix compile errors without multicore feature
a4e5df9 Upgrade to hex-literal 0.2
c063509 Migrate bellman to crossbeam 0.7
1775843 Take self directly in into_* functions
614d784 Rename into_ -> to_ where &self is used.
08664b1 Address various clippy warnings/errors in bellman
bb11ef2 cargo fmt
cff2e2f cargo fix --edition-idioms for bellman
dc2a280 Add edition = 2018
1a2bc19 cargo fmt
ad37878 cargo fix --edition for bellman
e73d1a2 cargo fmt bellman
dfb86fc Move generic circuit gadgets into bellman
9b3d766 Migrate to rand 0.7
055280f Migrate ff, group, pairing, and bellman to rand 0.6
533d586 Migrate bellman to rand 0.5
bfa9aaf Merge pull request zcash#61 from rex4539/fix-typos
3dd8490 Place bellman multicore operations behind a (default) feature flag
955e679 Merge pull request zcash#46 from str4d/ff-traits
d4ddaa9 Fix typos
12f93f2 Add ff and group crates to Cargo workspace
2e35a32 Update sapling-crypto crate to use ff crate
2019e63 Update workspace after pulling in external crates

git-subtree-dir: bellman
git-subtree-split: 2279da4
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 this pull request may close these issues.

6 participants