Skip to content

Commit

Permalink
Improve a few error messages (MystenLabs#954)
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfind authored Mar 19, 2022
1 parent 7e70f86 commit 380dd98
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
10 changes: 8 additions & 2 deletions sui_core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ impl AuthorityState {
SuiError::UnexpectedSequenceNumber {
object_id,
expected_sequence: object.version(),
given_sequence: sequence_number,
}
);

Expand Down Expand Up @@ -175,14 +176,18 @@ impl AuthorityState {
// Check the owner is the transaction sender.
fp_ensure!(
transaction.sender_address() == owner,
SuiError::IncorrectSigner
SuiError::IncorrectSigner {
error: format!("Object {:?} is owned by account address {:?}, but signer address is {:?}", object.id(), owner, transaction.sender_address()),
}
);
}
Owner::ObjectOwner(owner) => {
// Check that the object owner is another mutable object in the input.
fp_ensure!(
owned_object_authenticators.contains(&owner),
SuiError::IncorrectSigner
SuiError::IncorrectSigner {
error: format!("Object {:?} is owned by object {:?}, which is not in the input", object.id(), owner),
}
);
}
Owner::SharedMutable => {
Expand Down Expand Up @@ -420,6 +425,7 @@ impl AuthorityState {
Some(SuiError::UnexpectedSequenceNumber {
object_id: *object_id,
expected_sequence: shared_locks[object_id],
given_sequence: *version,
})
} else {
None
Expand Down
1 change: 1 addition & 0 deletions sui_core/src/gateway_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ where
SuiError::UnexpectedSequenceNumber {
object_id,
expected_sequence: next_sequence_number,
given_sequence: object_kind.version(),
}
.into()
);
Expand Down
6 changes: 5 additions & 1 deletion sui_core/tests/staged/sui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,9 @@ SuiError:
STRUCT:
- error: STR
10:
IncorrectSigner: UNIT
IncorrectSigner:
STRUCT:
- error: STR
11:
UnknownSigner: UNIT
12:
Expand All @@ -451,6 +453,8 @@ SuiError:
TYPENAME: ObjectID
- expected_sequence:
TYPENAME: SequenceNumber
- given_sequence:
TYPENAME: SequenceNumber
14:
ConflictingTransaction:
STRUCT:
Expand Down
15 changes: 11 additions & 4 deletions sui_types/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl KeyPair {
})
}

// TODO: eradicate uneeded uses (i.e. most)
// TODO: eradicate unneeded uses (i.e. most)
/// Avoid implementing `clone` on secret keys to prevent mistakes.
#[must_use]
pub fn copy(&self) -> KeyPair {
Expand Down Expand Up @@ -216,7 +216,12 @@ impl Signature {
.expect("byte lengths match");
let received_addr = SuiAddress::from(&PublicKeyBytes(public_key_bytes));
if received_addr != author {
return Err(SuiError::IncorrectSigner);
return Err(SuiError::IncorrectSigner {
error: format!(
"Signature check failure. Author is {}, received address is {}",
author, received_addr
),
});
}

// is this a cryptographically correct public key?
Expand Down Expand Up @@ -263,7 +268,9 @@ impl Signature {
.expect("byte lengths match");
let received_addr = SuiAddress::from(&PublicKeyBytes(public_key_bytes));
if received_addr != author {
return Err(SuiError::IncorrectSigner);
return Err(SuiError::IncorrectSigner {
error: format!("Signature get_verification_inputs() failure. Author is {}, received address is {}", author, received_addr)
});
}

// deserialize the signature
Expand Down Expand Up @@ -303,7 +310,7 @@ impl signature::Signature for AuthoritySignature {

impl AuthoritySignature {
/// Signs with the provided Signer
///
///
pub fn new<T>(value: &T, secret: &dyn signature::Signer<AuthoritySignature>) -> Self
where
T: Signable<Vec<u8>>,
Expand Down
7 changes: 4 additions & 3 deletions sui_types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,20 @@ pub enum SuiError {
// Signature verification
#[error("Signature is not valid: {}", error)]
InvalidSignature { error: String },
#[error("Value was not signed by the correct sender")]
IncorrectSigner,
#[error("Value was not signed by the correct sender: {}", error)]
IncorrectSigner { error: String },
#[error("Value was not signed by a known authority")]
UnknownSigner,
// Certificate verification
#[error("Signatures in a certificate must form a quorum")]
CertificateRequiresQuorum,
#[error(
"The given sequence number must match the next expected sequence ({expected_sequence:?}) number of the object ({object_id:?})"
"The given sequence number ({given_sequence:?}) must match the next expected sequence ({expected_sequence:?}) number of the object ({object_id:?})"
)]
UnexpectedSequenceNumber {
object_id: ObjectID,
expected_sequence: SequenceNumber,
given_sequence: SequenceNumber,
},
#[error("Conflicting transaction already received: {pending_transaction:?}")]
ConflictingTransaction {
Expand Down

0 comments on commit 380dd98

Please sign in to comment.