You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
During the work on entropyxyz/synedrion#170, a number of repeating patterns in the protocols and evidence verification came up. These can be wrapped in helper methods/traits somehow, to make protocols easier to write and read.
BTreeMap access in the protocols. You would want to return LocalError if the key is not there. The repeating pattern is
some_map.get(key).ok_or_else(|| LocalError::new(format!("{key} is not found in `some_map`")))?
Updates for CGGMP'24 synedrion#170 introduces a trait that provides a safe_get() method for maps that returns a LocalError with the provided error message. This flattens the code with multiple map accesses (which are pretty common).
BTreeMap access in evidence verification. The pattern is the same, except here if the key is not found it is almost always InvalidEvidence, not a LocalError, so it will require a separate method.
Downcasting a BTreeMap<Id, Payload> (or Artifact) to a map of typed payloads, needed in pretty much every finalize(). synedrion has a trait providing downcast_all() for maps.
Getting the data for a specific round from previous_messages and combined_echos in verify_messages_constitute_error(), returning InvalidEvidence if the corresponding key is not present. While it's not that much to write, it repeats so many times in the evidence verification code that it's worth simplifying. This also makes the code flatter and easier to read.
Deserializing all echos from combined_echos and returning InvalidEvidence on error.
Flattening error checks in evidence verification. For example, instead of
if r2_message.data.hash(&sid_hash, guilty_party) != r1_message.cap_v{Ok(())}else{Err(ProtocolValidationError::InvalidEvidence("The received hash is valid".into(),))}
(a pattern that repeats for every error, and there can be a dozen of them) it would be nice to write
Note that we don't really need to provide an error message here because there's only one error like that per variant of the error enum, which is already documented.
Alternatively, this can be a method on bool instead of a function.
Declaring the required messages for evidence verification. Can we make the following example simpler?
In particular, should we add RequiredMessageParts::without_normal_broadcast() etc, to cover all the remaining combinations of (echo_broadcast, normal_broadcast, direct_message)?
Currently these are all implemented in entropyxyz/synedrion#170, but I wonder if it is worth moving these traits to manul. An alternative to traits is custom types, but protocol already exports a huge number of types, so I don't know if that would be a good idea.
The text was updated successfully, but these errors were encountered:
During the work on entropyxyz/synedrion#170, a number of repeating patterns in the protocols and evidence verification came up. These can be wrapped in helper methods/traits somehow, to make protocols easier to write and read.
BTreeMap
access in the protocols. You would want to returnLocalError
if the key is not there. The repeating pattern isUpdates for CGGMP'24 synedrion#170 introduces a trait that provides a
safe_get()
method for maps that returns aLocalError
with the provided error message. This flattens the code with multiple map accesses (which are pretty common).BTreeMap
access in evidence verification. The pattern is the same, except here if the key is not found it is almost alwaysInvalidEvidence
, not aLocalError
, so it will require a separate method.Downcasting a
BTreeMap<Id, Payload>
(orArtifact
) to a map of typed payloads, needed in pretty much everyfinalize()
.synedrion
has a trait providingdowncast_all()
for maps.Getting the data for a specific round from
previous_messages
andcombined_echos
inverify_messages_constitute_error()
, returningInvalidEvidence
if the corresponding key is not present. While it's not that much to write, it repeats so many times in the evidence verification code that it's worth simplifying. This also makes the code flatter and easier to read.Deserializing all echos from
combined_echos
and returningInvalidEvidence
on error.Flattening error checks in evidence verification. For example, instead of
(a pattern that repeats for every error, and there can be a dozen of them) it would be nice to write
Note that we don't really need to provide an error message here because there's only one error like that per variant of the error enum, which is already documented.
Alternatively, this can be a method on
bool
instead of a function.Declaring the required messages for evidence verification. Can we make the following example simpler?
In particular, should we add
RequiredMessageParts::without_normal_broadcast()
etc, to cover all the remaining combinations of(echo_broadcast, normal_broadcast, direct_message)
?Currently these are all implemented in entropyxyz/synedrion#170, but I wonder if it is worth moving these traits to
manul
. An alternative to traits is custom types, butprotocol
already exports a huge number of types, so I don't know if that would be a good idea.The text was updated successfully, but these errors were encountered: