Skip to content

Commit

Permalink
Refactor input size check
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbosio committed Sep 19, 2024
1 parent 1c85ce2 commit e46b6f5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
25 changes: 12 additions & 13 deletions operator/mina/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,30 @@ pub extern "C" fn verify_mina_state_ffi(
pub_input_buffer: &[u8; MAX_PUB_INPUT_SIZE],
pub_input_len: usize,
) -> bool {
if proof_len > MAX_PROOF_SIZE {
let Some(proof_buffer_slice) = proof_buffer.get(..proof_len) else {
eprintln!("Proof length argument is greater than max proof size");
return false;
}
};

if pub_input_len > MAX_PUB_INPUT_SIZE {
let Some(pub_input_buffer_slice) = pub_input_buffer.get(..pub_input_len) else {
eprintln!("Public input length argument is greater than max public input size");
return false;
}
};

let proof: MinaStateProof = match bincode::deserialize(&proof_buffer[..proof_len]) {
let proof: MinaStateProof = match bincode::deserialize(proof_buffer_slice) {
Ok(proof) => proof,
Err(err) => {
eprintln!("Failed to deserialize state proof: {}", err);
return false;
}
};
let pub_inputs: MinaStatePubInputs =
match bincode::deserialize(&pub_input_buffer[..pub_input_len]) {
Ok(pub_inputs) => pub_inputs,
Err(err) => {
eprintln!("Failed to deserialize state pub inputs: {}", err);
return false;
}
};
let pub_inputs: MinaStatePubInputs = match bincode::deserialize(pub_input_buffer_slice) {
Ok(pub_inputs) => pub_inputs,
Err(err) => {
eprintln!("Failed to deserialize state pub inputs: {}", err);
return false;
}
};

// Checks the integrity of the public inputs, also checks if the states form a chain.
let (candidate_tip_state, bridge_tip_state, candidate_tip_state_hash) =
Expand Down
12 changes: 6 additions & 6 deletions operator/mina_account/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ pub extern "C" fn verify_account_inclusion_ffi(
pub_input_buffer: &[u8; MAX_PUB_INPUT_SIZE],
pub_input_len: usize,
) -> bool {
if proof_len > MAX_PROOF_SIZE {
let Some(proof_buffer_slice) = proof_buffer.get(..proof_len) else {
eprintln!("Proof length argument is greater than max proof size");
return false;
}
};

if pub_input_len > MAX_PUB_INPUT_SIZE {
let Some(pub_input_buffer_slice) = pub_input_buffer.get(..pub_input_len) else {
eprintln!("Public input length argument is greater than max public input size");
return false;
}
};

let MinaAccountProof {
merkle_path,
account,
} = match bincode::deserialize(&proof_buffer[..proof_len]) {
} = match bincode::deserialize(proof_buffer_slice) {
Ok(proof) => proof,
Err(err) => {
eprintln!("Failed to deserialize account proof: {}", err);
Expand All @@ -42,7 +42,7 @@ pub extern "C" fn verify_account_inclusion_ffi(
let MinaAccountPubInputs {
ledger_hash,
encoded_account,
} = match bincode::deserialize(&pub_input_buffer[..pub_input_len]) {
} = match bincode::deserialize(pub_input_buffer_slice) {
Ok(pub_inputs) => pub_inputs,
Err(err) => {
eprintln!("Failed to deserialize account pub inputs: {}", err);
Expand Down

0 comments on commit e46b6f5

Please sign in to comment.