Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify invalid message evidence verification #82

Open
fjarri opened this issue Jan 4, 2025 · 0 comments
Open

Simplify invalid message evidence verification #82

fjarri opened this issue Jan 4, 2025 · 0 comments
Labels
code quality Making things simpler
Milestone

Comments

@fjarri
Copy link
Member

fjarri commented Jan 4, 2025

Every protocol defines several verify_*_is_invalid to check invalid message evidence. An example implementation looks like this:

fn verify_echo_broadcast_is_invalid(
    deserializer: &Deserializer,
    round_id: &RoundId,
    message: &EchoBroadcast,
) -> Result<(), MessageValidationError> {
    match round_id {
        r if r == &RoundId::new(1) => message.verify_is_not::<Round1EchoBroadcast>(deserializer),
        r if r == &RoundId::new(2) => message.verify_is_not::<Round2EchoBroadcast<P>>(deserializer),
        r if r == &RoundId::new(3) => message.verify_is_some(),
        _ => Err(MessageValidationError::InvalidEvidence("Invalid round number".into())),
    }
}

How can this be simplified? Seems like it'll have to be a macro. Something that seems possible is a macro for every method, something like

echo_broadcast_types! {
    1 => Round1EchoBroadcast,
    2 => Round2EchoBroadcast<P>,
    3 => _,
}

direct_message_types! {
...
}

// etc

Even better, if we could merge all message parts into one macro, something like

message_types! {
    1 => (Round1EchoBroadcast, _, _),
    2 => (Round2EchoBroadcast<P>, _, _),
    3 => (_, _, Round3Broadcast),
}

but I am not sure if it is possible in Rust, because it will require transposing the variable length token sequence.

@fjarri fjarri added the code quality Making things simpler label Jan 4, 2025
@fjarri fjarri added this to the v1.0.0 milestone Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality Making things simpler
Projects
None yet
Development

No branches or pull requests

1 participant