Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
jakehemmerle committed Nov 2, 2023
1 parent ca426ed commit bec010d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
15 changes: 8 additions & 7 deletions examples/barebones-with-extra/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ impl Program for BarebonesWithExtra {
/// This is the only function required by the program runtime. `signature_request` is the preimage of the curve element to be
/// signed, eg. RLP-serialized Ethereum transaction request, raw x86_64 executable, etc.
fn evaluate(signature_request: InitialState) -> Result<(), Error> {
let InitialState { preimage, extra} = signature_request;
let InitialState { preimage, extra } = signature_request;

// our constraint just checks that the length of the signature request is greater than 10
if preimage.len() < 10 {
return Err(Error::Evaluation(
Expand All @@ -27,7 +27,9 @@ impl Program for BarebonesWithExtra {
}

// Just check and make sure the extra field is not empty.
extra.ok_or(Error::Evaluation("This program requires that `extra` be `Some`.".to_string()))?;
extra.ok_or(Error::Evaluation(
"This program requires that `extra` be `Some`.".to_string(),
))?;

Ok(())
}
Expand All @@ -45,7 +47,7 @@ mod tests {
fn test_preimage_length_is_valid() {
let signature_request = InitialState {
preimage: "some_data_longer_than_10_bytes".to_string().into_bytes(),
extra: Some(vec![0x00])
extra: Some(vec![0x00]),
};

assert!(BarebonesWithExtra::evaluate(signature_request).is_ok());
Expand All @@ -56,7 +58,7 @@ mod tests {
let signature_request = InitialState {
// should error since preimage is less than 10 bytes
preimage: "under10".to_string().into_bytes(),
extra: Some(vec![0x00])
extra: Some(vec![0x00]),
};

assert!(BarebonesWithExtra::evaluate(signature_request).is_err());
Expand All @@ -67,10 +69,9 @@ mod tests {
let signature_request = InitialState {
preimage: "some_data_longer_than_10_bytes".to_string().into_bytes(),
// should error since extra field is None
extra: None
extra: None,
};

assert!(BarebonesWithExtra::evaluate(signature_request).is_err());
}

}
4 changes: 2 additions & 2 deletions examples/barebones/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mod tests {
fn test_should_sign() {
let signature_request = InitialState {
preimage: "some_data_longer_than_10_bytes".to_string().into_bytes(),
extra: None
extra: None,
};

assert!(BarebonesProgram::evaluate(signature_request).is_ok());
Expand All @@ -52,7 +52,7 @@ mod tests {
// data being checked is under 10 bytes in length
let signature_request = InitialState {
preimage: "under10".to_string().into_bytes(),
extra: None
extra: None,
};

assert!(BarebonesProgram::evaluate(signature_request).is_err());
Expand Down
23 changes: 16 additions & 7 deletions examples/risczero-zkvm-verification/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,22 @@ pub struct ZkVmVerificationProgram;

impl Program for ZkVmVerificationProgram {
fn evaluate(signature_request: InitialState) -> Result<(), Error> {
let image_id: [u32; 8] = bincode::deserialize(&signature_request.preimage)
.map_err(|_| Error::InvalidTransactionRequest("Could not parse image_id".to_string()))?;
let image_id: [u32; 8] =
bincode::deserialize(&signature_request.preimage).map_err(|_| {
Error::InvalidTransactionRequest("Could not parse image_id".to_string())
})?;

let receipt: Receipt = match signature_request.extra {
Some(serialized_receipt) => bincode::deserialize(&serialized_receipt)
.map_err(|_| Error::InvalidTransactionRequest("Could not parse receipt".to_string()))?,
None => return Err(Error::InvalidTransactionRequest("No receipt provided".to_string())),
Some(serialized_receipt) => {
bincode::deserialize(&serialized_receipt).map_err(|_| {
Error::InvalidTransactionRequest("Could not parse receipt".to_string())
})?
}
None => {
return Err(Error::InvalidTransactionRequest(
"No receipt provided".to_string(),
))
}
};

receipt
Expand Down Expand Up @@ -77,7 +86,7 @@ mod tests {
fn test_should_pass_valid_receipt_and_image_pair() {
let signature_request = InitialState {
preimage: bincode::serialize(&read_test_image_id()).unwrap(),
extra: Some(bincode::serialize(&read_test_receipt()).unwrap())
extra: Some(bincode::serialize(&read_test_receipt()).unwrap()),
};

assert!(ZkVmVerificationProgram::evaluate(signature_request).is_ok());
Expand All @@ -87,7 +96,7 @@ mod tests {
fn test_should_error_with_incorrect_image_id_for_receipt_image_pair() {
let signature_request = InitialState {
preimage: bincode::serialize(&read_erronous_test_image_id()).unwrap(),
extra: Some(bincode::serialize(&read_test_receipt()).unwrap())
extra: Some(bincode::serialize(&read_test_receipt()).unwrap()),
};

assert!(ZkVmVerificationProgram::evaluate(signature_request).is_err());
Expand Down
6 changes: 3 additions & 3 deletions examples/siwe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Nonce: oNCEHm5jzQU2WvuBB
Issued At: 2022-01-28T23:28:16.013Z"
.to_string()
.into_bytes(),
extra: None
extra: None,
};

assert!(Siwe::evaluate(signature_request).is_ok());
Expand All @@ -81,7 +81,7 @@ Nonce: oNCEHm5jzQU2WvuBB
Issued At: 2022-01-28T23:28:16.013Z"
.to_string()
.into_bytes(),
extra: None
extra: None,
};

assert!(Siwe::evaluate(signature_request).is_err());
Expand All @@ -102,7 +102,7 @@ Nonce: oNCEHm5jzQU2WvuBB
Issued At: 2022-01-28T23:28:16.013Z"
.to_string()
.into_bytes(),
extra: None
extra: None,
};

assert!(Siwe::evaluate(signature_request).is_err());
Expand Down
4 changes: 2 additions & 2 deletions runtime/tests/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn test_barebones_component() {
let longer_than_10 = "asdfasdfasdfasdf".to_string();
let initial_state = InitialState {
preimage: longer_than_10.into_bytes(),
extra: None
extra: None,
};

let res = runtime.evaluate(BAREBONES_COMPONENT_WASM, &initial_state);
Expand All @@ -27,7 +27,7 @@ fn test_barebones_component_fails_with_data_length_less_than_10() {
let shorter_than_10 = "asdf".to_string();
let initial_state = InitialState {
preimage: shorter_than_10.into_bytes(),
extra: None
extra: None,
};

let res = runtime.evaluate(BAREBONES_COMPONENT_WASM, &initial_state);
Expand Down

0 comments on commit bec010d

Please sign in to comment.