Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some better error handling #31

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ Below is a list of the error codes that can be seen in the json output of the cl
- 12 => `FailedToCallRPC`
- 13 => `VerificationKeyHashMismatch`
- 14 => `FailedToDownloadVerificationKey`
- 15=> `FailedToWriteVerificationKeyToDisk`
- 15 => `FailedToWriteVerificationKeyToDisk`
- 16 => `ProofVerificationFailed`
- 17 => `FailedToLoadVerificationKey`,
- 18 => `BadCalldataLength`,
- 19 => `FailedToCallRPCJsonError`,
- 20 => `FailedToCallRPCResponseError`,

# Future plans

Expand Down
4 changes: 4 additions & 0 deletions src/block_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ impl BlockAuxilaryOutput {
pub fn parse_aux_data(func: &Function, calldata: &[u8]) -> Result<BlockAuxilaryOutput, StatusCode> {
use ethers::abi;

if calldata.len() < 5 {
return Err(StatusCode::BadCalldataLength);
}

let mut parsed_calldata = func.decode_input(&calldata[4..]).unwrap();
assert_eq!(parsed_calldata.len(), 2);

Expand Down
4 changes: 4 additions & 0 deletions src/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ pub enum StatusCode {
FailedToDownloadVerificationKey,
FailedToWriteVerificationKeyToDisk,
ProofVerificationFailed,
FailedToLoadVerificationKey,
BadCalldataLength,
FailedToCallRPCJsonError,
FailedToCallRPCResponseError,
}

#[derive(Default)]
Expand Down
13 changes: 8 additions & 5 deletions src/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub async fn fetch_l1_data(
) -> Result<L1BatchAndProofData, StatusCode> {
let commit_data = fetch_l1_commit_data(batch_number, network, rpc_url).await;
if commit_data.is_err() {
return Err(StatusCode::FailedToGetDataFromL1);
return Err(commit_data.err().unwrap());
}

let (batch_l1_data, aux_output) = commit_data.unwrap();
Expand Down Expand Up @@ -112,8 +112,7 @@ pub async fn fetch_l1_commit_data(
let mut curr_batch_commitment = H256::default();
for b_number in [previous_batch_number, batch_number] {
let commit_tx = fetch_batch_commit_tx(b_number, network)
.await
.map_err(|_| StatusCode::FailedToFindCommitTxn);
.await;

if commit_tx.is_err() {
return Err(commit_tx.err().unwrap());
Expand Down Expand Up @@ -363,14 +362,14 @@ pub async fn fetch_batch_commit_tx(
.await;

if json.is_err() {
return Err(StatusCode::FailedToCallRPC);
return Err(StatusCode::FailedToCallRPCJsonError);
}

let json = json.unwrap();

return Ok((json.result.commitTxHash, json.result.proveTxHash));
} else {
return Err(StatusCode::FailedToCallRPC);
return Err(StatusCode::FailedToCallRPCResponseError);
}
}

Expand All @@ -381,6 +380,10 @@ fn find_state_data_from_log(
) -> Result<Option<(u64, Vec<u8>)>, StatusCode> {
use ethers::abi;

if calldata.len() < 5 {
return Err(StatusCode::BadCalldataLength);
}

let mut parsed_input = function.decode_input(&calldata[4..]).unwrap();
assert_eq!(parsed_input.len(), 2);
let second_param = parsed_input.pop().unwrap();
Expand Down
9 changes: 8 additions & 1 deletion src/snark_wrapper_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,16 @@ pub async fn verify_snark(
);

println!("=== Loading verification key.");
let verification_key = &fs::read_to_string(snark_vk_scheduler_key_file.clone());

if verification_key.is_err() {
println!("Unable to load verification key from: {}", snark_vk_scheduler_key_file.clone());
return Err(StatusCode::FailedToLoadVerificationKey);
}

use circuit_definitions::snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::verifier::verify;
let vk_inner : VerificationKey<Bn256, ZkSyncSnarkWrapperCircuit> = serde_json::from_str(
&fs::read_to_string(snark_vk_scheduler_key_file.clone()).unwrap()
&verification_key.as_ref().unwrap()
)
.unwrap();

Expand Down
Loading