return error if the the check is not pass
What changed, and why it matters
This commit fixes a bug in the Solana address generation code for the Keystone 3 hardware wallet. Previously, if a public key was the wrong length (not 32 bytes), the code would create an error message but then ignore it and continue, producing an address from bad input. Now it correctly stops and returns the error. This prevents malformed or attacker-chosen keys from being silently accepted and turned into a Solana address.
Review whether any other blockchain address modules in the firmware have similar error-construction-without-return patterns. Verify the regression test runs and consider adding boundary tests for empty, 31-byte, 33-byte, and non-hex inputs.
Security signals we found
Missing return of error value allows invalid public key length to be silently encoded
Address derivation from malformed input could produce invalid or attacker-influenced addresses
Added regression test for short public key rejection
Evidence from the diff
In rust/apps/solana/src/address.rs, get_address() previously called SolanaError::AddressError(…) without returning it, so execution fell through to Ok(base58::encode(pubkey.as_slice())). The patch adds return Err(…) so invalid-length pubkeys are rejected. A unit test for a 16-byte (too short) pubkey now expecting an AddressError was added. This is a straightforward correctness fix for an error-handling omission that could have allowed non-conforming public keys to be encoded as addresses.
Changed components
rust/apps/solana/src/address.rsSolana address generation function get_address()Inspect captured patch +10 / −2
diff --git a/rust/apps/solana/src/address.rs b/rust/apps/solana/src/address.rs
index 1c5d29b..355937e 100644
--- a/rust/apps/solana/src/address.rs
+++ b/rust/apps/solana/src/address.rs
@@ -6,9 +6,9 @@ use bitcoin::base58;
pub fn get_address(pub_key: &String) -> Result<String> {
let pubkey = hex::decode(pub_key)?;
if pubkey.len() != 32 {
- SolanaError::AddressError(format!("bad public key {pub_key:?}"));
+ return Err(SolanaError::AddressError(format!("bad public key {:?}", pub_key)));
}
- Ok(base58::encode(pubkey.as_slice()))
+ return Ok(base58::encode(pubkey.as_slice()));
}
#[cfg(test)]
@@ -89,6 +89,14 @@ mod tests {
.unwrap()
);
}
+ {
+ let result = get_address(
+ &"0102030405060708090a0b0c0d0e0f10"
+ .to_string()
+ );
+ assert!(result.is_err());
+ assert!(matches!(result, Err(SolanaError::AddressError(_))));
+ }
}
}
}
Why this scored 60/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.