Skip to content

Commit

Permalink
feat: Enable rug feature for wnfs tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus23 committed Dec 6, 2023
1 parent b56d567 commit 6f58ac0
Show file tree
Hide file tree
Showing 7 changed files with 454 additions and 420 deletions.
4 changes: 2 additions & 2 deletions wnfs-nameaccumulator/src/name.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(not(feature = "rug"))]
#[cfg(feature = "num-bigint-dig")]
use crate::BigNumDig;
#[cfg(feature = "rug")]
#[cfg(not(feature = "num-bigint-dig"))]
use crate::BigNumRug;
use crate::{
error::VerificationError,
Expand All @@ -24,11 +24,11 @@ const L_HASH_DSI: &str = "wnfs/1.0/PoKE*/l 128-bit hash derivation";
// Type Definitions
//--------------------------------------------------------------------------------------------------

#[cfg(not(feature = "rug"))]
#[cfg(feature = "num-bigint-dig")]
pub type DefaultBig = BigNumDig;

#[cfg(feature = "rug")]
#[cfg(not(feature = "num-bigint-dig"))]
pub type DefaultBig = BigNumRug;

/// A WNFS name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ source: wnfs-nameaccumulator/src/name.rs
expression: name
---
{
"cid": "bafyr4ifk4gn3ikouj2hr6otqcrvczkzoez7f3nbsdhrn66lsulgouus4x4",
"value": {
"/": {
"bytes": "QJGrxttvHTU78j/tJnSVMV+P/9eqtVs+5/MZFGwT+Fp5OeAeYYkTdROGIU1QBThKsKXTxagSECZN+AkULPOERVK/6n2UrWBYdj89gXBHMsVzzKRSi1V2gv9KjsI8bxbVM5b1M3YAGixO7vlAWZOREWRK82XHaaQnbrnENoFvjtXpKp7ZeW7bdWKXsa3gz891zlMb4SjudlQJYbz4LxfaYCvFo77/x5lN8Nr5B5aDJbgG+Hkgk0h3v/hEkZV+xjfhhtVaQ8qULLK4YlWZhyz/9Vg4YS/NuJvaEfCbfEBJksOnRJg9tMT7ckzjnz6WH7NKFt5TPMZwQEqLNQGHhtim4g"
Expand Down
39 changes: 35 additions & 4 deletions wnfs-nameaccumulator/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ impl Big for BigNumRug {
}

fn from_bytes_be(bytes: &[u8]) -> Self::Num {
Integer::from_digits(bytes, Order::MsfBe)
Integer::from_digits(bytes, Order::MsfLe)
}

fn to_bytes_be<const N: usize>(n: &Self::Num) -> [u8; N] {
let vec = n.to_digits(Order::MsfBe);
let vec = n.to_digits(Order::MsfLe);
let mut bytes = [0u8; N];
let zero_bytes = N - vec.len();
bytes[zero_bytes..].copy_from_slice(&vec);
Expand All @@ -260,8 +260,10 @@ impl Big for BigNumRug {

fn rand_rsa_modulus(rng: &mut impl CryptoRngCore) -> Self::Num {
let mut rng = Self::setup_rand_state(rng);
let p: Integer = Integer::random_bits(1024, &mut rng).into();
let q: Integer = Integer::random_bits(1024, &mut rng).into();
let p_pre: Integer = Integer::random_bits(1024, &mut rng).into();
let q_pre: Integer = Integer::random_bits(1024, &mut rng).into();
let p = p_pre.next_prime();
let q = q_pre.next_prime();
p * q
}

Expand All @@ -284,3 +286,32 @@ impl BigNumRug {
rng
}
}

#[cfg(feature = "rug")]
#[cfg(test)]
mod rug_tests {
use crate::{Big, BigNumRug};
use rand_chacha::ChaCha12Rng;
use rand_core::SeedableRng;

/// We need this property for snapshot testing
#[test]
fn rand_prime_is_deterministic() {
let run_one = BigNumRug::rand_prime_256bit(&mut ChaCha12Rng::seed_from_u64(0));
let run_two = BigNumRug::rand_prime_256bit(&mut ChaCha12Rng::seed_from_u64(0));
assert_eq!(run_one, run_two);
let run_three = BigNumRug::rand_prime_256bit(&mut ChaCha12Rng::seed_from_u64(1));
assert_ne!(run_one, run_three);
}

/// We need this property for snapshot testing
#[test]
fn rand_below_is_deterministic() {
let ceiling = BigNumRug::rand_prime_256bit(&mut ChaCha12Rng::seed_from_u64(0));
let run_one = BigNumRug::rand_below(&ceiling, &mut ChaCha12Rng::seed_from_u64(0));
let run_two = BigNumRug::rand_below(&ceiling, &mut ChaCha12Rng::seed_from_u64(0));
assert_eq!(run_one, run_two);
let run_three = BigNumRug::rand_below(&ceiling, &mut ChaCha12Rng::seed_from_u64(1));
assert_ne!(run_one, run_three);
}
}
2 changes: 1 addition & 1 deletion wnfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ test-strategy = "0.3"
testresult = "0.3.0"
tiny-bip39 = "1.0"
wnfs-common = { path = "../wnfs-common", features = ["test_utils"] }
wnfs-nameaccumulator = { path = "../wnfs-nameaccumulator", version = "=0.1.25", default-features = false, features = ["num-bigint-dig"] }
wnfs-nameaccumulator = { path = "../wnfs-nameaccumulator", version = "=0.1.25", default-features = false, features = ["rug"] }

[lib]
name = "wnfs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ source: wnfs/src/private/forest/hamt.rs
expression: store
---
{
"cid": "bafyr4idfgswgdwgzkqwq2xdcvwre2qp56ycn3buuzgc6c6pgft3knuqpoe",
"cid": "bafyr4iewia5aiw5jxi3ojkkwogwrrq4x2bfqskeg2zbq45gvrlqm4up2ua",
"value": {
"accumulator": {
"generator": {
"/": {
"bytes": "rGCe5WHIjiZjiFxYSolBMJVjSSp2tGS18oeHuU2n0RFR3k5UcbjIjxzCF03Lsndi4sCURnnka6qzIs9sl96XpmOG3b+ds6Kn2sdqnw22vdIWYjL5J63NtT26i09JMi8JWNYiF8aNRLSdXGg+TZTd1pN4Kao7k6ThdaPENnQeQB4IzzkputboM2ZUTu6Jxg4teVO5D1yXImQfJ1VgOGwWBC0j4xuRRZ9STH3tZw+boy4oC584XoRpagF0B+PM7/r8Pjmz/Bb2qVA3tTebeY6ZUeftEvodt/DPiEsvKvag2SdwzuPQ3IVTZOnNF3CZSy5G+W1WwLbMl3yXDxO4yMmcPA"
"bytes": "DnwXmD/vORPcLzdf1evo7nGljNInOtYHpODrD3+82Nnpu0qfQPxFLKSB2dhylrLkh4UmTnLZtphq+jBbSjrWkqRf6C/qEToqzAhkAPtkF048lnLaI3UjBCXagQjJv8boXybWdaxiKxTFN2nu9B2vzNyUl1QqO9wXmNkzWM1P4T8lIm6FTjWSbHg/TVTXkpv8nTgQIUA1A0Kk7jEtjb/Vl8VdTZ2UgBywKE1Pvf8HbmXDc6Cjg0K5+XXC6SW1Bk71iLdLM174Mu8KWDjb3qotRpqrGGeSIv1KI1v1VWCI8ZuohkVe4zT5JvzyKIizsVDKcPTKGR60H6enSeQZgShFww"
}
},
"modulus": {
Expand All @@ -20,15 +20,15 @@ expression: store
"root": [
{
"/": {
"bytes": "EIg"
"bytes": "IgQ"
}
},
[
[
[
{
"/": {
"bytes": "PysK81Y28dr+hdj3ik9MSrpRvYt/c53mpys0bVn8NSeklT2ELDB39dn82P0lBBeE/Y0vMHJIXYqSlmS3hY1qjcdzJhgPXSPZgUnM9/ZgE/IHlMGDNf2v87kzKQR6EsEPG5J3vhj9NKTY8X0NwYH3HW5REIDqJcmLfOxQctKG0PvS6t+NEeepocm6ljn6OMjGoivcpr5VYV1/GI+Ut6vrTfITxU6S1dJNpC8Ov/YvbxNQWd3OXOEnR0yXd/7OtXhCRPDgnp0KZ6GlYUfgfa7J3DzX+SjJBkyKn4vCyV9HIFtraBIA/mBuUcicg+Q+EEI2afXSC4F/xE6RZM7CddgH/Q"
"bytes": "WzUFTg2et93G6urhSL2Viqdf49sAgAv0vv8SE1SgzA2V80ukVHaZR6+PcbbkvJa7kqRzKbUJ8si3pckU/2L30Kmr+JVM38v6cQAT5N0y9KiTmXX6EyUIkQ5r+zfH8xybEhJ00mPJbRpB76OgZ24z9a1VLWQCcenR6GsrPWUkU94p3r8XBQtIBni/uHjKlpFvR/Csq+pmoBqK5qOYaDsgWn6nV8pgMIIRFifu6S7bw9SSMtRUrW/FFfcu1GjRHeq7UV71wyUGGB2gpC4Ekm8Y/tri1S3zHbLnh54ck+tjUZM0MMRSWnL+FvwXcYKaxfRmxooi0Jajw3zF+xGdW8hlnw"
}
},
[
Expand All @@ -42,7 +42,7 @@ expression: store
[
{
"/": {
"bytes": "BUpE9eho+KEgskxrwd9+4wlYCt/yfYKjub7PRSDxbG5oYpw/3YLg0D4Y+sNtAJWqqmq5RHiXMvdTpW0BI39W9C3j/jIJV3cK+/bbJTMR8/vtppzG1L75UlgVSa/Ld7ng2lj18N1iYfbzXGVvGw3yX+5i+syy6HED7LmjKaZkgDBPzlmvs1m3NdTluSTePUWfYL5YX6ASbSg0yqtW2+K1FwOmUKXJ1k50GmqJGUb7jvZg3bsOvbKBJfCTZP973McYlISdptaPNIvjVshSotvay15XaBwNUFRfxVvfCDxXRxisqqGzG9HUslUclQSvFdR2WssN64lHatfeIurB4AIhLQ"
"bytes": "JpTYbHBVDGw5673kIA4lqeXDoKce4FWIcUzot6Dz7jlQu9P/oIsgyVqxOsyywQNdzwbCXdzscWCzafaoX46arhINT9o9aB2e88mQLJrs3Q19cVojT1MNS0ozckERxcmJdarrm3SQMX61pyRK796Su33+5bKZ2QfVQwlhpQ6zC6bFrsXNtcM+xk82MgpFkhNNg7vP+LRUVzmRgk8bdsnHypPQE0jAOS/tn93KMV4aA32KNeZdxDwvFDJ/BFqQ0X0uhs0NA1xQbNqlUOfLvfKa2ADlU+Gn+wilPLwjnelZbuQSu78e+Y1kGDuYJPYG5aCYKlNlYfjV/V2BqvTgY6Qt7w"
}
},
[
Expand All @@ -56,7 +56,7 @@ expression: store
[
{
"/": {
"bytes": "NLRQaY7/LIeJkeF481XbATcYyftYoXn2UUgae0yxgkAlNOZb8e9bQyIX8WYBUeXR4PxQVJBoc64r4nkj0xYD5V8uRk+bKebOW9CiIDWj0kDF/E/ydUXMA6YzGsZuMM9mQEsomU+1501wnwVc/WDzn16FQFCDVf/URVC919Hr8OCG3drnZ2yMtGiszZqqECbM0u70CZVhk8deTWmwrjf1H1PSacmK6Z9CroQMBdnIBWBgC4LOK5TPsm0fTTdqMEkcbSJHokThy1eKAlXVficzX/T+OWq8/TkXp/qQQWS7wF3tE7GHWcIG4IBT+DRxm+p9SYowZq8IVfRhfOHZRTcc3w"
"bytes": "PIhixhlMETh9BGn4lF0klTdOCHH3/JngF0bGUZZg3HO25Qqp4c5K3eOyAohQYWIhyxgbOhkvzeVtG5oDNSVLcgd+6lMULgXBEEhavSX6CFLnxVoKLFqvvt7dxh5dUVTSQ6adIIa0E7hzu1Jt9E8mZm3C1rNz8js9+eaQwWzYynyRi78O/ubhgK8W5K1lIKtDdKI6VnOTaUKn/kih2kYhR/exZGWAzk9vwmDlsRRIJLHrTYX3cxZuTlMa2MwFov5WDE5zYSh/qe3jVmIXEhp/ffnWzEjwlbkZi6RpC/cT2NStprki+vwJdV4klvKpSdA8+5Ma+cUZ8PjeEBqLjl10WA"
}
},
[
Expand All @@ -71,5 +71,5 @@ expression: store
"structure": "hamt",
"version": "0.1.0"
},
"bytes": "pGRyb290gkIQiIOBglkBAD8rCvNWNvHa/oXY94pPTEq6Ub2Lf3Od5qcrNG1Z/DUnpJU9hCwwd/XZ/Nj9JQQXhP2NLzBySF2KkpZkt4WNao3HcyYYD10j2YFJzPf2YBPyB5TBgzX9r/O5MykEehLBDxuSd74Y/TSk2PF9DcGB9x1uURCA6iXJi3zsUHLShtD70urfjRHnqaHJupY5+jjIxqIr3Ka+VWFdfxiPlLer603yE8VOktXSTaQvDr/2L28TUFndzlzhJ0dMl3f+zrV4QkTw4J6dCmehpWFH4H2uydw81/koyQZMip+LwslfRyBba2gSAP5gblHInIPkPhBCNmn10guBf8ROkWTOwnXYB/2B2CpFAAEAAACBglkBAAVKRPXoaPihILJMa8HffuMJWArf8n2Co7m+z0Ug8WxuaGKcP92C4NA+GPrDbQCVqqpquUR4lzL3U6VtASN/VvQt4/4yCVd3Cvv22yUzEfP77aacxtS++VJYFUmvy3e54NpY9fDdYmH281xlbxsN8l/uYvrMsuhxA+y5oymmZIAwT85Zr7NZtzXU5bkk3j1Fn2C+WF+gEm0oNMqrVtvitRcDplClydZOdBpqiRlG+472YN27Dr2ygSXwk2T/e9zHGJSEnabWjzSL41bIUqLb2steV2gcDVBU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