Skip to content

message hash: faster impl for AbortingHypercubeMessageHash#40

Merged
tcoratger merged 6 commits intoleanEthereum:mainfrom
tcoratger:aborting
Mar 17, 2026
Merged

message hash: faster impl for AbortingHypercubeMessageHash#40
tcoratger merged 6 commits intoleanEthereum:mainfrom
tcoratger:aborting

Conversation

@tcoratger
Copy link
Contributor

With the following benchmark file:

use std::hint::black_box;

use criterion::{Criterion, SamplingMode};
use rand::Rng;

use leansig::{
    MESSAGE_LENGTH,
    signature::{
        SignatureScheme, SignatureSchemeSecretKey,
        generalized_xmss::instantiations_aborting::lifetime_2_to_the_6::SIGAbortingLifetime6Dim64Base8,
    },
};

pub fn bench_function_aborting(c: &mut Criterion) {
    type Sig = SIGAbortingLifetime6Dim64Base8;

    let mut group = c.benchmark_group("Aborting: Lifetime 2^6, Dim64, Base8");
    group.sampling_mode(SamplingMode::Flat);

    let mut rng = rand::rng();

    // keygen (small sample — it's slow)
    group.sample_size(10);
    group.bench_function("- gen", |b| {
        b.iter(|| {
            let _ = Sig::key_gen(black_box(&mut rng), 0, Sig::LIFETIME as usize);
        });
    });

    // sign
    group.sample_size(100);
    let (pk, sk) = Sig::key_gen(&mut rng, 0, Sig::LIFETIME as usize);
    let prepared_interval = sk.get_prepared_interval();

    group.bench_function("- sign", |b| {
        b.iter(|| {
            let message = rng.random();
            let epoch =
                rng.random_range(prepared_interval.start as u32..prepared_interval.end as u32);
            let _ = Sig::sign(black_box(&sk), black_box(epoch), black_box(&message));
        });
    });

    // verify
    let precomputed: Vec<(u32, [u8; MESSAGE_LENGTH], <Sig as SignatureScheme>::Signature)> =
        (0..500)
            .map(|_| {
                let message = rng.random();
                let epoch = rng
                    .random_range(prepared_interval.start as u32..prepared_interval.end as u32);
                let signature = Sig::sign(&sk, epoch, &message).expect("Signing should succeed");
                (epoch, message, signature)
            })
            .collect();

    group.bench_function("- verify", |b| {
        b.iter(|| {
            let (epoch, message, signature) =
                black_box(&precomputed[rng.random_range(0..precomputed.len())]);
            let _ = Sig::verify(
                black_box(&pk),
                *epoch,
                black_box(message),
                black_box(signature),
            );
        });
    });

    group.finish();
}
image

tcoratger and others added 6 commits March 16, 2026 16:37
Keep our optimized array-based apply implementation over the upstream
Vec-based version. Add a criterion benchmark for the aborting
instantiation (Lifetime 2^6, Dim64, Base8) to measure keygen/sign/verify.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tcoratger tcoratger requested a review from TomWambsgans March 16, 2026 16:57
@tcoratger tcoratger merged commit f477348 into leanEthereum:main Mar 17, 2026
2 checks passed
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