Skip to content

Commit 95f7dd7

Browse files
committed
Add message errors
1 parent b598231 commit 95f7dd7

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

operator/mina/lib/src/lib.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,26 @@ pub extern "C" fn verify_protocol_state_proof_ffi(
2929
public_input_bytes: &[u8; MAX_PUB_INPUT_SIZE],
3030
public_input_len: usize,
3131
) -> bool {
32-
// TODO(xqft): add message errors
33-
let protocol_state_proof =
34-
if let Ok(protocol_state_proof) = parse_protocol_state_proof(&proof_bytes[..proof_len]) {
35-
protocol_state_proof
36-
} else {
32+
let protocol_state_proof = match parse_protocol_state_proof(&proof_bytes[..proof_len]) {
33+
Ok(protocol_state_proof) => protocol_state_proof,
34+
Err(err) => {
35+
eprintln!("Failed to parse protocol state proof: {}", err);
3736
return false;
38-
};
39-
40-
let (protocol_state_hash, protocol_state) = if let Ok(protocol_state_pub) =
41-
parse_protocol_state_pub(&public_input_bytes[..public_input_len])
42-
{
43-
protocol_state_pub
44-
} else {
45-
return false;
37+
}
4638
};
4739

48-
// check that protocol state hash is correct
40+
let (protocol_state_hash, protocol_state) =
41+
match parse_protocol_state_pub(&public_input_bytes[..public_input_len]) {
42+
Ok(protocol_state_pub) => protocol_state_pub,
43+
Err(err) => {
44+
eprintln!("Failed to parse protocol state public inputs: {}", err);
45+
return false;
46+
}
47+
};
48+
4949
// TODO(xqft): this can be a batcher's pre-verification check (but don't remove it from here)
5050
if MinaHash::hash(&protocol_state) != protocol_state_hash {
51+
eprintln!("The protocol state doesn't match the hash provided as public input");
5152
return false;
5253
}
5354

@@ -70,7 +71,7 @@ pub fn parse_protocol_state_proof(
7071
let protocol_state_proof_base64 =
7172
std::str::from_utf8(protocol_state_proof_bytes).map_err(|err| err.to_string())?;
7273
let protocol_state_proof_binprot = BASE64_URL_SAFE
73-
.decode(protocol_state_proof_base64.trim_matches(char::from(0)))
74+
.decode(protocol_state_proof_base64)
7475
.map_err(|err| err.to_string())?;
7576
MinaBaseProofStableV2::binprot_read(&mut protocol_state_proof_binprot.as_slice())
7677
.map_err(|err| err.to_string())

0 commit comments

Comments
 (0)