df-lighter-core 0.0.1-beta

Lighter SDK for Rust: markets, account, trading, transfers, pools and binary options on Lighter and on Robinhood Chain, with exact decimals and the API key signer in Rust. Native and wasm.
Documentation
//! The permutation and the sponge, held to poseidon_crypto's own tests (`poseidon2_test.go`).

use super::*;

fn fps(values: [u64; WIDTH]) -> [Fp; WIDTH] {
    values.map(Fp::new)
}

#[test]
fn the_permutation_is_poseidon_crypto_s() {
    let mut state = fps([
        5417613058500526590,
        2481548824842427254,
        6473243198879784792,
        1720313757066167274,
        2806320291675974571,
        7407976414706455446,
        1105257841424046885,
        7613435757403328049,
        3376066686066811538,
        5888575799323675710,
        6689309723188675948,
        2468250420241012720,
    ]);
    permute(&mut state);
    assert_eq!(
        state,
        fps([
            5364184781011389007,
            15309475861242939136,
            5983386513087443499,
            886942118604446276,
            14903657885227062600,
            7742650891575941298,
            1962182278500985790,
            10213480816595178755,
            3510799061817443836,
            4610029967627506430,
            7566382334276534836,
            2288460879362380348,
        ])
    );
}

#[test]
fn the_sponge_squeezes_past_the_rate_as_poseidon_crypto_does() {
    let input = fps([
        2963773914414780088,
        8389525300242074234,
        3700959901615818008,
        6116199383751757212,
        3418607418699599889,
        8793277256263635044,
        448623437464918480,
        1857310021116627925,
        6145634616307237342,
        1548353948794474539,
        2318110128254703527,
        8347759953730634762,
    ]);
    let out = hash_n_to_m_no_pad(&input, 12);
    assert_eq!(
        out,
        fps([
            3627923032009111551,
            1460752551327577353,
            1084214837491058067,
            1841622875286057462,
            3996252440506437984,
            1276718204392552803,
            8564515621134952155,
            9252927025993202701,
            1147435538714642916,
            16407277821156164797,
            11997661877740155273,
            12485021000320141292,
        ])
    );
    assert_eq!(hash_to_fp5(&input).0, out[..5]);
    assert_eq!(hash_no_pad(&input), out[..4]);
    let (left, right) = (hash_no_pad(&input[..4]), hash_no_pad(&input[4..8]));
    let mut both = left.to_vec();
    both.extend(right);
    assert_eq!(hash_two_to_one(left, right), hash_no_pad(&both));
}