Skip to content

chore: add deserialization tests with corrupted inputs#3391

Merged
nsarlin-zama merged 2 commits intomainfrom
ns/chore/replay_bad_samples
Mar 19, 2026
Merged

chore: add deserialization tests with corrupted inputs#3391
nsarlin-zama merged 2 commits intomainfrom
ns/chore/replay_bad_samples

Conversation

@nsarlin-zama
Copy link
Contributor

@nsarlin-zama nsarlin-zama commented Mar 13, 2026

closes: please link all relevant issues

PR content/description

This PR adds a test that runs known corrupted ct lists to check they are correctly deserialized (meaning errors are caught but does not trigger a panic).

The lfs part (pull, github cache, ...) has been copied from the backward data tests.


This change is Reviewable

@cla-bot cla-bot bot added the cla-signed label Mar 13, 2026
@nsarlin-zama nsarlin-zama force-pushed the ns/chore/replay_bad_samples branch 8 times, most recently from 435a678 to 76777d0 Compare March 16, 2026 12:38
@nsarlin-zama nsarlin-zama marked this pull request as ready for review March 16, 2026 12:44
Copy link
Member

@IceTDrinker IceTDrinker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable, I let the others take a look

thanks !

@IceTDrinker reviewed 21 files and all commit messages, and made 3 comments.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on nsarlin-zama, soonum, and SouchonTheo).


tests/corrupted_inputs_deserialization.rs line 117 at r1 (raw file):

}

fn handle_ct_list(input: &[u8], conformance_params: &CompactCiphertextListConformanceParams) {

could be worth printing to see up to where a list progresses given most of them likely won't make it passed deserialization

same for the proven stuff below


tests/corrupted_inputs_deserialization.rs line 161 at r1 (raw file):

#[test]
#[cfg(feature = "integer")]

I think we can get rid of that feature, to group once #3380 is merged to get rid of ZK and shortint features too I think

@nsarlin-zama nsarlin-zama force-pushed the ns/chore/replay_bad_samples branch 2 times, most recently from a472097 to a19bae9 Compare March 17, 2026 08:58
Copy link
Contributor Author

@nsarlin-zama nsarlin-zama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I added the strings feature to tfhe because one of the samples has a string
  • also added a black_box to explicitly states that the ops should not be optimized away

@nsarlin-zama made 3 comments.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on IceTDrinker, soonum, and SouchonTheo).


tests/corrupted_inputs_deserialization.rs line 117 at r1 (raw file):

Previously, IceTDrinker wrote…

could be worth printing to see up to where a list progresses given most of them likely won't make it passed deserialization

same for the proven stuff below

yes good idea


tests/corrupted_inputs_deserialization.rs line 161 at r1 (raw file):

Previously, IceTDrinker wrote…

I think we can get rid of that feature, to group once #3380 is merged to get rid of ZK and shortint features too I think

I removed it here so that it's less work to do it later

@nsarlin-zama nsarlin-zama force-pushed the ns/chore/replay_bad_samples branch from a19bae9 to 52ae14e Compare March 17, 2026 09:19
@nsarlin-zama nsarlin-zama force-pushed the ns/chore/replay_bad_samples branch from 52ae14e to a8f488d Compare March 17, 2026 10:39
@nsarlin-zama nsarlin-zama force-pushed the ns/chore/replay_bad_samples branch 2 times, most recently from e2e253a to 73f7792 Compare March 17, 2026 10:55
Copy link
Member

@IceTDrinker IceTDrinker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, should we have someone else review the changes ?

Otherwise I can approve

@IceTDrinker partially reviewed 5 files and all commit messages, made 1 comment, and resolved 2 discussions.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on IceTDrinker, mayeul-zama, soonum, SouchonTheo, and tmontaigu).

Copy link
Contributor

@tmontaigu tmontaigu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tmontaigu partially reviewed 21 files and all commit messages, and made 3 comments.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on mayeul-zama, nsarlin-zama, soonum, and SouchonTheo).


tests/corrupted_inputs_deserialization.rs line 60 at r4 (raw file):

fn process_inputs(dir: &Path, mut handler: impl FnMut(&[u8])) -> u64 {
    let mut total_tests = 0;
    let entries: Vec<_> = std::fs::read_dir(dir)

minor, but I dont think we actually need to collect ?


tests/corrupted_inputs_deserialization.rs line 71 at r4 (raw file):

            total_tests += 1;
            let mut input = Vec::new();
            File::open(&path)

std::fs:read exists as a convenient wrapper of this
https://doc.rust-lang.org/std/fs/fn.read.html


tests/corrupted_inputs_deserialization.rs line 82 at r4 (raw file):

}

macro_rules! test_type {

Minor since this is a test, but it can be done without macro

fn test_integer<FheType>(exp: &CompactCiphertextListExpander, i: usize)
where
    FheType: HlExpandable
        + Tagged
        + Clone
        + Add<FheType, Output = FheType>
        + Sub<FheType, Output = FheType>
        + Mul<FheType, Output = FheType>,
{
    let ct = match exp.get::<FheType>(i) {
        Ok(Some(ct)) => ct,
        Ok(None) => {
            println!("No ct found at idx {}\n", i);
            return;
        }
        Err(e) => {
            println!("Error caught while trying to get ct at idx {}:\n{e}\n", i);
            return;
        }
    };
    let res = ct.clone() + ct.clone();
    let res = res * ct.clone();
    let _ = std::hint::black_box(res - ct);
}

@nsarlin-zama nsarlin-zama force-pushed the ns/chore/replay_bad_samples branch from 73f7792 to 2d17498 Compare March 18, 2026 14:33
Copy link
Contributor Author

@nsarlin-zama nsarlin-zama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nsarlin-zama made 3 comments and resolved 1 discussion.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on mayeul-zama, soonum, SouchonTheo, and tmontaigu).


tests/corrupted_inputs_deserialization.rs line 60 at r4 (raw file):

Previously, tmontaigu (tmontaigu) wrote…

minor, but I dont think we actually need to collect ?

done


tests/corrupted_inputs_deserialization.rs line 71 at r4 (raw file):

Previously, tmontaigu (tmontaigu) wrote…

std::fs:read exists as a convenient wrapper of this
https://doc.rust-lang.org/std/fs/fn.read.html

done


tests/corrupted_inputs_deserialization.rs line 82 at r4 (raw file):

Previously, tmontaigu (tmontaigu) wrote…

Minor since this is a test, but it can be done without macro

fn test_integer<FheType>(exp: &CompactCiphertextListExpander, i: usize)
where
    FheType: HlExpandable
        + Tagged
        + Clone
        + Add<FheType, Output = FheType>
        + Sub<FheType, Output = FheType>
        + Mul<FheType, Output = FheType>,
{
    let ct = match exp.get::<FheType>(i) {
        Ok(Some(ct)) => ct,
        Ok(None) => {
            println!("No ct found at idx {}\n", i);
            return;
        }
        Err(e) => {
            println!("Error caught while trying to get ct at idx {}:\n{e}\n", i);
            return;
        }
    };
    let res = ct.clone() + ct.clone();
    let res = res * ct.clone();
    let _ = std::hint::black_box(res - ct);
}

I'm always happy when I can avoid a macro :)
done

@nsarlin-zama nsarlin-zama force-pushed the ns/chore/replay_bad_samples branch from 2d17498 to d988f4c Compare March 18, 2026 14:36
Copy link
Contributor

@tmontaigu tmontaigu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tmontaigu reviewed 1 file and all commit messages, and resolved 2 discussions.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on mayeul-zama, soonum, and SouchonTheo).

@nsarlin-zama nsarlin-zama force-pushed the ns/chore/replay_bad_samples branch from d988f4c to 08749a5 Compare March 19, 2026 13:29
@zama-bot zama-bot removed the approved label Mar 19, 2026
@nsarlin-zama nsarlin-zama force-pushed the ns/chore/replay_bad_samples branch from e4f7eda to e17b210 Compare March 19, 2026 14:06
Copy link
Member

@IceTDrinker IceTDrinker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IceTDrinker reviewed 5 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on mayeul-zama, soonum, and SouchonTheo).

@nsarlin-zama nsarlin-zama merged commit 6f3162f into main Mar 19, 2026
156 checks passed
@nsarlin-zama nsarlin-zama deleted the ns/chore/replay_bad_samples branch March 19, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants