Skip to content

Commit

Permalink
presignature bad parameters error check
Browse files Browse the repository at this point in the history
  • Loading branch information
volovyks committed Oct 15, 2024
1 parent 0102d1f commit 3d5796b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
17 changes: 6 additions & 11 deletions chain-signatures/node/src/protocol/presignature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ pub enum GenerationError {
PresignatureIsMissing(PresignatureId),
#[error("presignature {0} is in garbage collection")]
PresignatureIsGarbageCollected(TripleId),
#[error("presignature bad parameters")]
PresignatureBadParameters,
}

/// Abstracts how triples are generated by providing a way to request a new triple that will be
Expand Down Expand Up @@ -511,17 +513,10 @@ impl PresignatureManager {
private_share: &SecretKeyShare,
cfg: &ProtocolConfig,
) -> Result<&mut PresignatureProtocol, GenerationError> {
// TODO: why do we need to pass the id here? Double check.
let expected_id = hash_as_id(triple0, triple1);
if id != expected_id {
tracing::warn!(
id,
expected_id,
"presignature id does not match the hash of the triples"
);
return Err(GenerationError::PresignatureIsMissing(id));
}
if self.contains(&id).await {
if id != hash_as_id(triple0, triple1) {
tracing::error!(id, "presignature id does not match the expected hash");
return Err(GenerationError::PresignatureBadParameters);
} else if self.contains(&id).await {
tracing::debug!(id, "presignature already generated");
Err(GenerationError::AlreadyGenerated)
} else if self.gc.contains_key(&id) {
Expand Down
2 changes: 0 additions & 2 deletions chain-signatures/node/src/storage/presignature_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ impl RedisPresignatureStorage {
}
}

// Note: it is possible to use a Lua script to make all operations atomic
// TODO: add logs and better error handling
#[async_trait]
impl PresignatureStorage for RedisPresignatureStorage {
fn insert(&mut self, presignature: Presignature) -> PresigResult<()> {
Expand Down

0 comments on commit 3d5796b

Please sign in to comment.