Skip to content

Commit 1012099

Browse files
format
1 parent 6e6d9c0 commit 1012099

6 files changed

Lines changed: 67 additions & 28 deletions

File tree

forester-utils/src/account_zero_copy.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ pub enum AccountZeroCopyError {
1919
AccountNotFound(Pubkey),
2020
}
2121

22+
fn copy_hash_set_from_account_bytes(bytes: &[u8]) -> Result<HashSet, light_hash_set::HashSetError> {
23+
let mut owned = bytes.to_vec();
24+
// SAFETY: We pass an owned, mutable copy of bytes that are expected to contain a serialized
25+
// hash set account image.
26+
unsafe { HashSet::from_bytes_copy(&mut owned) }
27+
}
28+
2229
/// Fetches the given account, then copies and serializes it as a `HashSet`.
2330
pub async fn get_hash_set<T, R: Rpc>(
2431
rpc: &mut R,
@@ -29,7 +36,7 @@ pub async fn get_hash_set<T, R: Rpc>(
2936
.await
3037
.map_err(|e| AccountZeroCopyError::RpcError(e.to_string()))?
3138
.ok_or(AccountZeroCopyError::AccountNotFound(pubkey))?;
32-
HashSet::from_bytes_copy_safe(&account.data[8 + mem::size_of::<T>()..])
39+
copy_hash_set_from_account_bytes(&account.data[8 + mem::size_of::<T>()..])
3340
.map_err(|e| AccountZeroCopyError::RpcError(format!("HashSet parse error: {:?}", e)))
3441
}
3542

@@ -131,5 +138,5 @@ pub fn parse_hash_set_from_bytes<T>(data: &[u8]) -> Result<HashSet, light_hash_s
131138
if data.len() <= offset {
132139
return Err(light_hash_set::HashSetError::BufferSize(offset, data.len()));
133140
}
134-
HashSet::from_bytes_copy_safe(&data[offset..])
141+
copy_hash_set_from_account_bytes(&data[offset..])
135142
}

program-tests/utils/src/e2e_test_env.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ where
819819
let client = Client::new();
820820
let circuit_inputs_new_root =
821821
bigint_to_be_bytes_array::<32>(&inputs.new_root).unwrap();
822-
let inputs = to_json(&inputs);
822+
let inputs = to_json(&inputs).unwrap();
823823

824824
let response_result = client
825825
.post(format!("{}{}", SERVER_ADDRESS, PROVE_PATH))
@@ -835,9 +835,9 @@ where
835835
.map_err(|error| RpcError::CustomError(error.to_string()))
836836
.unwrap();
837837
let (proof_a, proof_b, proof_c) =
838-
proof_from_json_struct(proof_json);
838+
proof_from_json_struct(proof_json).unwrap();
839839
let (proof_a, proof_b, proof_c) =
840-
compress_proof(&proof_a, &proof_b, &proof_c);
840+
compress_proof(&proof_a, &proof_b, &proof_c).unwrap();
841841
let instruction_data = InstructionDataBatchNullifyInputs {
842842
new_root: circuit_inputs_new_root,
843843
compressed_proof: CompressedProof {
@@ -1279,7 +1279,8 @@ where
12791279
.get_state_merkle_trees_mut()
12801280
.push(StateMerkleTreeBundle {
12811281
rollover_fee: state_tree_account
1282-
.deserialized()
1282+
.try_deserialized()
1283+
.unwrap()
12831284
.metadata
12841285
.rollover_metadata
12851286
.rollover_fee as i64,
@@ -1378,7 +1379,8 @@ where
13781379
})
13791380
.unwrap();
13801381
bundle.rollover_fee = queue_account
1381-
.deserialized()
1382+
.try_deserialized()
1383+
.unwrap()
13821384
.metadata
13831385
.rollover_metadata
13841386
.rollover_fee as i64;

program-tests/utils/src/mock_batched_forester.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,17 @@ impl<const HEIGHT: usize> MockBatchedAddressForester<HEIGHT> {
270270
low_element_indices.push(non_inclusion_proof.leaf_index);
271271
low_element_next_indices.push(non_inclusion_proof.next_index);
272272
low_element_next_values.push(non_inclusion_proof.leaf_higher_range_value);
273-
let proof = non_inclusion_proof.merkle_proof.as_slice().try_into().map_err(|_| {
274-
ProverClientError::InvalidProofData(format!(
275-
"invalid low element proof length: expected {}, got {}",
276-
HEIGHT,
277-
non_inclusion_proof.merkle_proof.len()
278-
))
279-
})?;
273+
let proof = non_inclusion_proof
274+
.merkle_proof
275+
.as_slice()
276+
.try_into()
277+
.map_err(|_| {
278+
ProverClientError::InvalidProofData(format!(
279+
"invalid low element proof length: expected {}, got {}",
280+
HEIGHT,
281+
non_inclusion_proof.merkle_proof.len()
282+
))
283+
})?;
280284
low_element_proofs.push(proof);
281285
}
282286
let subtrees = self.merkle_tree.merkle_tree.get_subtrees();

program-tests/utils/src/test_batch_forester.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub async fn create_append_batch_ix_data<R: Rpc>(
167167
let proof_client = ProofClient::local();
168168
let inputs_json = BatchAppendInputsJson::from_inputs(&circuit_inputs)
169169
.to_string()
170-
;
170+
.unwrap();
171171

172172
match proof_client.generate_proof(inputs_json).await {
173173
Ok(compressed_proof) => (
@@ -298,7 +298,7 @@ pub async fn get_batched_nullify_ix_data<R: Rpc>(
298298
let proof_client = ProofClient::local();
299299
let circuit_inputs_new_root =
300300
bigint_to_be_bytes_array::<32>(&inputs.new_root.to_biguint().unwrap()).unwrap();
301-
let inputs_json = update_inputs_string(&inputs);
301+
let inputs_json = update_inputs_string(&inputs).unwrap();
302302
let new_root = bundle.merkle_tree.root();
303303

304304
assert_eq!(circuit_inputs_new_root, new_root);
@@ -719,7 +719,7 @@ pub async fn create_batch_update_address_tree_instruction_data_with_proof<R: Rpc
719719

720720
let proof_client = ProofClient::local();
721721
let circuit_inputs_new_root = bigint_to_be_bytes_array::<32>(&inputs.new_root).unwrap();
722-
let inputs_json = to_json(&inputs);
722+
let inputs_json = to_json(&inputs).unwrap();
723723

724724
match proof_client.generate_proof(inputs_json).await {
725725
Ok(compressed_proof) => {

sdk-libs/client/src/interface/load_accounts.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,9 @@ fn build_transfer2(
408408
fee_payer: Pubkey,
409409
) -> Result<Instruction, LoadAccountsError> {
410410
let mut packed = PackedAccounts::default();
411-
let packed_trees = proof.pack_tree_infos(&mut packed);
411+
let packed_trees = proof
412+
.pack_tree_infos(&mut packed)
413+
.map_err(|e| LoadAccountsError::BuildInstruction(e.to_string()))?;
412414
let tree_infos = packed_trees
413415
.state_trees
414416
.as_ref()

sdk-libs/program-test/src/indexer/test_indexer.rs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,7 +2171,10 @@ impl TestIndexer {
21712171
InclusionProofInputs::new(inclusion_proofs.as_slice()).unwrap();
21722172
(
21732173
Some(
2174-
BatchInclusionJsonStruct::from_inclusion_proof_inputs(&inclusion_proof_inputs),
2174+
BatchInclusionJsonStruct::from_inclusion_proof_inputs(
2175+
&inclusion_proof_inputs,
2176+
)
2177+
.map_err(|e| IndexerError::CustomError(e.to_string()))?,
21752178
),
21762179
None,
21772180
)
@@ -2182,7 +2185,8 @@ impl TestIndexer {
21822185
Some(
21832186
BatchInclusionJsonStructLegacy::from_inclusion_proof_inputs(
21842187
&inclusion_proof_inputs,
2185-
),
2188+
)
2189+
.map_err(|e| IndexerError::CustomError(e.to_string()))?,
21862190
),
21872191
)
21882192
} else {
@@ -2261,7 +2265,8 @@ impl TestIndexer {
22612265
Some(
22622266
BatchNonInclusionJsonStructLegacy::from_non_inclusion_proof_inputs(
22632267
&non_inclusion_proof_inputs,
2264-
),
2268+
)
2269+
.map_err(|e| IndexerError::CustomError(e.to_string()))?,
22652270
),
22662271
)
22672272
} else if tree_heights[0] == 40 {
@@ -2271,7 +2276,8 @@ impl TestIndexer {
22712276
Some(
22722277
BatchNonInclusionJsonStruct::from_non_inclusion_proof_inputs(
22732278
&non_inclusion_proof_inputs,
2274-
),
2279+
)
2280+
.map_err(|e| IndexerError::CustomError(e.to_string()))?,
22752281
),
22762282
None,
22772283
)
@@ -2358,12 +2364,21 @@ impl TestIndexer {
23582364
)
23592365
.await?;
23602366
if let Some(payload) = payload {
2361-
(indices, Vec::new(), payload.to_string())
2367+
(
2368+
indices,
2369+
Vec::new(),
2370+
payload
2371+
.to_string()
2372+
.map_err(|e| IndexerError::CustomError(e.to_string()))?,
2373+
)
23622374
} else {
23632375
(
23642376
indices,
23652377
Vec::new(),
2366-
payload_legacy.unwrap().to_string(),
2378+
payload_legacy
2379+
.unwrap()
2380+
.to_string()
2381+
.map_err(|e| IndexerError::CustomError(e.to_string()))?,
23672382
)
23682383
}
23692384
}
@@ -2375,9 +2390,14 @@ impl TestIndexer {
23752390
)
23762391
.await?;
23772392
let payload_string = if let Some(payload) = payload {
2378-
payload.to_string()
2393+
payload
2394+
.to_string()
2395+
.map_err(|e| IndexerError::CustomError(e.to_string()))?
23792396
} else {
2380-
payload_legacy.unwrap().to_string()
2397+
payload_legacy
2398+
.unwrap()
2399+
.to_string()
2400+
.map_err(|e| IndexerError::CustomError(e.to_string()))?
23812401
};
23822402
(Vec::new(), indices, payload_string)
23832403
}
@@ -2454,6 +2474,7 @@ impl TestIndexer {
24542474
non_inclusion: non_inclusion_payload.inputs,
24552475
}
24562476
.to_string()
2477+
.map_err(|e| IndexerError::CustomError(e.to_string()))?
24572478
} else if let Some(non_inclusion_payload) = non_inclusion_payload_legacy {
24582479
CombinedJsonStructLegacy {
24592480
circuit_type: ProofType::Combined.to_string(),
@@ -2463,6 +2484,7 @@ impl TestIndexer {
24632484
non_inclusion: non_inclusion_payload.inputs,
24642485
}
24652486
.to_string()
2487+
.map_err(|e| IndexerError::CustomError(e.to_string()))?
24662488
} else {
24672489
panic!("Unsupported tree height")
24682490
};
@@ -2487,9 +2509,11 @@ impl TestIndexer {
24872509
if response_result.status().is_success() {
24882510
let body = response_result.text().await.unwrap();
24892511
let proof_json = deserialize_gnark_proof_json(&body).unwrap();
2490-
let (proof_a, proof_b, proof_c) = proof_from_json_struct(proof_json);
2512+
let (proof_a, proof_b, proof_c) = proof_from_json_struct(proof_json)
2513+
.map_err(|e| IndexerError::CustomError(e.to_string()))?;
24912514
let (proof_a, proof_b, proof_c) =
2492-
compress_proof(&proof_a, &proof_b, &proof_c);
2515+
compress_proof(&proof_a, &proof_b, &proof_c)
2516+
.map_err(|e| IndexerError::CustomError(e.to_string()))?;
24932517
return Ok(ValidityProofWithContext {
24942518
accounts: account_proof_inputs,
24952519
addresses: address_proof_inputs,

0 commit comments

Comments
 (0)