From 233ba86691299a7b4d026f881a6fa40736ae7599 Mon Sep 17 00:00:00 2001
From: STEVAN Antoine <antoine.stevan@isae-supaero.fr>
Date: Wed, 6 Dec 2023 10:03:24 +0000
Subject: [PATCH] run FEC decoding test in a loop (dragoon/komodo!6)

# changelog
- refactor $k$ and $n$ into variables
- run the decoding FEC test in a loop from $(k - 1) \rho + 1$ to $k \rho$, where $\rho$ is the curve number of bytes per scalar field element, e.g. $31$ for _BLS-12-381_
- add a _NOTE_ about having too few bytes and elements, i.e. below $(k - 1) \rho + 1$
- add a _FIXME_ about having too many bytes and elements, i.e. above $k \rho$
---
 src/fec.rs | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/fec.rs b/src/fec.rs
index f152dfed..07647a32 100644
--- a/src/fec.rs
+++ b/src/fec.rs
@@ -339,7 +339,14 @@ mod tests {
 
     #[test]
     fn decoding() {
-        decoding_template::<Bls12_381>(&BYTES[..63], 3, 5);
+        let (k, n) = (3, 5);
+
+        let modulus_byte_size = <Bls12_381 as Pairing>::ScalarField::MODULUS_BIT_SIZE as usize / 8;
+        // NOTE: starting at `modulus_byte_size * (k - 1) + 1` to include at least _k_ elements
+        // FIXME: stopping at k elements, more yields crashes
+        for b in (modulus_byte_size * (k - 1) + 1)..=(modulus_byte_size * k) {
+            decoding_template::<Bls12_381>(&BYTES[..b], k, n);
+        }
     }
 
     fn create_fake_shard<E: Pairing>(
-- 
GitLab