Skip to content

Add test vectors for Praos (ver03) #3

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

Merged
merged 8 commits into from
Mar 17, 2025

Conversation

paweljakubas
Copy link
Collaborator

@paweljakubas paweljakubas commented Feb 28, 2025

The PR adds test vectors as checked/generated in cardano-base for VRF:

  • Praos (ver03) - currently in use

The mirror PR generating/checking the added test vectors is here : IntersectMBO/cardano-base#519

@abailly
Copy link

abailly commented Mar 5, 2025

I think only adding test vectors without test runner is a bit odd.

@paweljakubas paweljakubas changed the title Add test vectors Add test vectors for Praos (ver03) Mar 7, 2025
@paweljakubas paweljakubas force-pushed the paweljakubas/2/add-test-vectors branch from 61308ca to e08a12d Compare March 7, 2025 11:01
@paweljakubas paweljakubas requested review from abailly and scarmuega and removed request for AndrewWestberg March 7, 2025 11:01
Copy link

@abailly abailly left a comment

Choose a reason for hiding this comment

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

some improvements suggestion towards more idiomatic Rust :)

src/vrf03.rs Outdated
let output_expected =
hex::decode(test_vector.get("beta").unwrap().as_str().unwrap()).unwrap();

assert_eq!(vrf_name, "PraosVRF");
Copy link

Choose a reason for hiding this comment

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

these assertions seem rather pointless

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

indeed, removed!

src/vrf03.rs Outdated
let test_vector: serde_json::Value =
serde_json::from_reader(file).expect("JSON was not well-formatted");

let vrf_name = test_vector.get("vrf").unwrap().as_str().unwrap();
Copy link

Choose a reason for hiding this comment

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

We should create a VRFTestVector structure and have serve take care of deserialisation, along with proper types for each member. Using automatic derivation should remove quite a lot of boilerplate conversion I think

Copy link

Choose a reason for hiding this comment

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

here is some code I wrote to handle deserialisation from hex encoded string into bytes: https://github.com/pragma-org/amaru/blob/81a72af8a5b145ecfcee9a255d129fb703efdccf/crates/ouroboros/tests/validation.rs#L109

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thank you very much for this remark and request. Used serde and its deserialization as requested!

src/vrf03.rs Outdated

#[test]
fn check_against_cardano_base() {
check_against_golden("./tests/test_vectors/vrf_ver03_generated_1");
Copy link

Choose a reason for hiding this comment

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

create a static const test_vectors : [&'static str; 8] = [ .... ] and then iterate over the vector, eg. a parametric test

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@paweljakubas paweljakubas requested a review from abailly March 13, 2025 17:24
Copy link

@abailly abailly left a comment

Choose a reason for hiding this comment

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

Here is a proposed patch to simplify the deserialisation of test vectors. Also, I wonder what's the relationship between those JSON formatted test vectors and the ones which are inline part of the code?
Last suggestion: instead of adding one file for each test vector, just add one vrf03_golden_tests.json file containing a list.

0001-simplify-deserialization-of-test-vectors.patch

@paweljakubas paweljakubas requested a review from abailly March 17, 2025 11:52
@paweljakubas paweljakubas merged commit 1557d57 into main Mar 17, 2025
5 checks passed
@paweljakubas paweljakubas deleted the paweljakubas/2/add-test-vectors branch March 17, 2025 13:11
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.

2 participants