Skip to content

Add various protocol writing helpers from synedrion - #113

Merged
fjarri merged 6 commits into
entropyxyz:masterfrom
fjarri:protocol-helpers
Sep 12, 2025
Merged

Add various protocol writing helpers from synedrion#113
fjarri merged 6 commits into
entropyxyz:masterfrom
fjarri:protocol-helpers

Conversation

@fjarri

@fjarri fjarri commented Jun 2, 2025

Copy link
Copy Markdown
Contributor
  • Added dev::check_evidence_with_extension() and check_evidence_with_extensions() that are used to write misbehavior tests (to be renamed depending on what we decide regarding the Extend/Misbehave)
  • Added utils::Without trait (implemented for BTreeSet and BTreeMap). Fixes Make without available in manul #108
  • Added MapValues and MapValuesRef (separate traits because the latter needs a bound on keys being cloneable)
  • Added verify_that()
  • Added GetOrLocalError and GetOrInvalidEvidence traits to streamline map lookups in protocols and evidence verification code

This takes care of #81 except the items 7 and 8

@fjarri fjarri self-assigned this Jun 2, 2025
@fjarri
fjarri force-pushed the protocol-helpers branch 2 times, most recently from 68a7e8c to b9d9a96 Compare June 2, 2025 20:11
@coveralls

coveralls commented Jun 3, 2025

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 17520327573

Details

  • 112 of 156 (71.79%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.8%) to 67.524%

Changes Missing Coverage Covered Lines Changed/Added Lines %
manul/src/utils/traits.rs 15 35 42.86%
manul/src/dev/misbehave.rs 90 114 78.95%
Totals Coverage Status
Change from base Build 17417800938: 0.8%
Covered Lines: 2414
Relevant Lines: 3575

💛 - Coveralls

@fjarri
fjarri force-pushed the protocol-helpers branch 2 times, most recently from 6c5309f to f868868 Compare June 6, 2025 18:41
@fjarri
fjarri marked this pull request as ready for review June 6, 2025 18:44
@fjarri

fjarri commented Jun 6, 2025

Copy link
Copy Markdown
Contributor Author

Marking as ready for review to start the conversation about naming, I expect we'll have a lot of back and forth on this.

@fjarri
fjarri requested a review from dvdplm June 6, 2025 18:44

@dvdplm dvdplm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

First read, focusing on docs/comments and some general remarks. Will loop back and think about naming.

Comment thread manul/src/dev/misbehave.rs Outdated
/// Executes the sessions for the given entry points,
/// making one party (first in alphabetical order) the malicious one with the wrapper `M` and the given `behavior`.
#[allow(clippy::type_complexity)]
pub fn run_with_one_malicious_party<SP, M, B>(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this method is doing more work than it should. How about we change it to take a list of entry points and return a new list with the first malicious? The it's the caller's job to call run_sync with it (or run_async).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good option. Gotta think of a name though, taint_entry_points? :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

misbehaviorize?

@dvdplm dvdplm Jul 1, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thinking out loud here. Maybe it would be good to make the application of the corrupt behaviour explicit. What if we had a dyn Behavior (or a dyn Misbehavior) that we could apply() to a mutable ref to an EntryPoint?

Something like so:

    let misbehaving_id = ids
        .first()
        .ok_or_else(|| LocalError::new("Entry points list cannot be empty"))?;
    // Make it very clear what kind of misbehavior we are using and on which EntryPoint
    InvalidMessageOverride::apply(misbehaving_id, &mut entry_points);
    let execution_result = run_sync(rng, entry_points)?;

I think it'd require some re-jigging and perhaps some renaming here and there, but the idea is: less automation and use explicit calls using the "thing" that defines what the misbehavior is we are applying.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Pushed a new commit splitting out the preparation stage and the checking to separate methods. What do you think?

Comment thread manul/src/dev/misbehave.rs Outdated
Comment on lines +38 to +44
let modified_entry_points = entry_points
.into_iter()
.map(|(signer, entry_point)| {
let id = signer.verifying_key();
let maybe_behavior = if &id == misbehaving_id {
Some(behavior.clone())
} else {
None
};
let entry_point = MisbehavingEntryPoint::<SP::Verifier, B, M>::new(entry_point, maybe_behavior);
(signer, entry_point)
})
.collect();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's a bit annoying to have to use 12 lines of code to do this job. We know it's the first entry, can't we mutate in place somehow?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We are mutating all of them, it's just the maybe_behavior argument that changes. They all have to be wrapped in the same MisbehavingEntryPoint type.

Comment thread manul/src/dev/misbehave.rs Outdated
Comment thread manul/src/dev/misbehave.rs Outdated
Comment thread manul/src/dev/misbehave.rs Outdated
Comment thread manul/src/dev/misbehave.rs Outdated
Comment thread manul/src/utils/traits.rs
Comment thread manul/src/utils/traits.rs Outdated
Comment thread manul/src/utils/traits.rs Outdated
Comment thread manul/src/utils/traits.rs Outdated
@fjarri
fjarri force-pushed the protocol-helpers branch from f868868 to f99de62 Compare July 21, 2025 21:54
@fjarri
fjarri force-pushed the protocol-helpers branch 3 times, most recently from 6f702a5 to 45e147e Compare July 28, 2025 20:04
@fjarri
fjarri force-pushed the protocol-helpers branch 3 times, most recently from adfada9 to d99bc69 Compare August 31, 2025 21:08

@dvdplm dvdplm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is good to go now, modulo the protocol error question, which can perhaps be tweaked separately?

@fjarri
fjarri force-pushed the protocol-helpers branch 2 times, most recently from 51939fa to 6b4aac3 Compare September 2, 2025 22:58
@fjarri
fjarri merged commit 4bed194 into entropyxyz:master Sep 12, 2025
9 checks passed
@fjarri
fjarri deleted the protocol-helpers branch September 12, 2025 16:30
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.

Make without available in manul

3 participants