axelarnetwork / tofn

A threshold cryptography library in Rust
Apache License 2.0
112 stars 23 forks source link

Compressing PartyShareCounts and SignParties for more elegant testing #200

Closed leontiad closed 4 months ago

leontiad commented 2 years ago

Would be more elegant in terms of testing to compress the assignment of total shares per party to an agreed convention instead of expanding the entire vector with indices. The conversion for testing purposes can be 1 share per physical entity, e.g: to instantiate a local network with 20 shares and 1 share per participant with threshold equals 12 - meaning 13 shares are needed - code looks likes that:

https://github.com/axelarnetwork/tofn/blob/main/tests/integration/single_thread/mod.rs#L42:

let party_share_counts = PartyShareCounts::from_vec(vec![1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,]).unwrap(); // 20 total shares

let mut sign_parties = SignParties::with_max_size(party_share_counts.party_count());
        sign_parties.add(TypedUsize::from_usize(0)).unwrap();
        sign_parties.add(TypedUsize::from_usize(1)).unwrap();
        sign_parties.add(TypedUsize::from_usize(2)).unwrap();
        sign_parties.add(TypedUsize::from_usize(3)).unwrap();
        sign_parties.add(TypedUsize::from_usize(4)).unwrap();
        sign_parties.add(TypedUsize::from_usize(5)).unwrap();
        sign_parties.add(TypedUsize::from_usize(6)).unwrap();
        sign_parties.add(TypedUsize::from_usize(7)).unwrap();
        sign_parties.add(TypedUsize::from_usize(8)).unwrap();
        sign_parties.add(TypedUsize::from_usize(9)).unwrap();
        sign_parties.add(TypedUsize::from_usize(10)).unwrap();
        sign_parties.add(TypedUsize::from_usize(11)).unwrap();
        sign_parties.add(TypedUsize::from_usize(12)).unwrap();
       sign_parties
    };

that could be compressed in pseudocode in sth like that:

party_share_counts = 20 // in the backend a 20 length vector is being unwrapped
sign_parties = 13 // a random selection of 13 physical entities each one holding 1 share is selected

that is sth minor