Skip to content

Commit 0b04dbc

Browse files
format
1 parent deed085 commit 0b04dbc

5 files changed

Lines changed: 68 additions & 25 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/test_batch_forester.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ pub async fn create_append_batch_ix_data<R: Rpc>(
165165
bundle.merkle_tree.root()
166166
);
167167
let proof_client = ProofClient::local();
168-
let inputs_json = BatchAppendInputsJson::from_inputs(&circuit_inputs).to_string();
168+
let inputs_json = BatchAppendInputsJson::from_inputs(&circuit_inputs)
169+
.to_string()
170+
.unwrap();
169171

170172
match proof_client.generate_proof(inputs_json).await {
171173
Ok(compressed_proof) => (
@@ -296,7 +298,7 @@ pub async fn get_batched_nullify_ix_data<R: Rpc>(
296298
let proof_client = ProofClient::local();
297299
let circuit_inputs_new_root =
298300
bigint_to_be_bytes_array::<32>(&inputs.new_root.to_biguint().unwrap()).unwrap();
299-
let inputs_json = update_inputs_string(&inputs);
301+
let inputs_json = update_inputs_string(&inputs).unwrap();
300302
let new_root = bundle.merkle_tree.root();
301303

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

718720
let proof_client = ProofClient::local();
719721
let circuit_inputs_new_root = bigint_to_be_bytes_array::<32>(&inputs.new_root).unwrap();
720-
let inputs_json = to_json(&inputs);
722+
let inputs_json = to_json(&inputs).unwrap();
721723

722724
match proof_client.generate_proof(inputs_json).await {
723725
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: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,18 +2170,24 @@ impl TestIndexer {
21702170
let inclusion_proof_inputs =
21712171
InclusionProofInputs::new(inclusion_proofs.as_slice()).unwrap();
21722172
(
2173-
Some(BatchInclusionJsonStruct::from_inclusion_proof_inputs(
2174-
&inclusion_proof_inputs,
2175-
)),
2173+
Some(
2174+
BatchInclusionJsonStruct::from_inclusion_proof_inputs(
2175+
&inclusion_proof_inputs,
2176+
)
2177+
.map_err(|e| IndexerError::CustomError(e.to_string()))?,
2178+
),
21762179
None,
21772180
)
21782181
} else if height == STATE_MERKLE_TREE_HEIGHT as usize {
21792182
let inclusion_proof_inputs = InclusionProofInputsLegacy(inclusion_proofs.as_slice());
21802183
(
21812184
None,
2182-
Some(BatchInclusionJsonStructLegacy::from_inclusion_proof_inputs(
2183-
&inclusion_proof_inputs,
2184-
)),
2185+
Some(
2186+
BatchInclusionJsonStructLegacy::from_inclusion_proof_inputs(
2187+
&inclusion_proof_inputs,
2188+
)
2189+
.map_err(|e| IndexerError::CustomError(e.to_string()))?,
2190+
),
21852191
)
21862192
} else {
21872193
return Err(IndexerError::CustomError(
@@ -2259,7 +2265,8 @@ impl TestIndexer {
22592265
Some(
22602266
BatchNonInclusionJsonStructLegacy::from_non_inclusion_proof_inputs(
22612267
&non_inclusion_proof_inputs,
2262-
),
2268+
)
2269+
.map_err(|e| IndexerError::CustomError(e.to_string()))?,
22632270
),
22642271
)
22652272
} else if tree_heights[0] == 40 {
@@ -2269,7 +2276,8 @@ impl TestIndexer {
22692276
Some(
22702277
BatchNonInclusionJsonStruct::from_non_inclusion_proof_inputs(
22712278
&non_inclusion_proof_inputs,
2272-
),
2279+
)
2280+
.map_err(|e| IndexerError::CustomError(e.to_string()))?,
22732281
),
22742282
None,
22752283
)
@@ -2356,9 +2364,22 @@ impl TestIndexer {
23562364
)
23572365
.await?;
23582366
if let Some(payload) = payload {
2359-
(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+
)
23602374
} else {
2361-
(indices, Vec::new(), payload_legacy.unwrap().to_string())
2375+
(
2376+
indices,
2377+
Vec::new(),
2378+
payload_legacy
2379+
.unwrap()
2380+
.to_string()
2381+
.map_err(|e| IndexerError::CustomError(e.to_string()))?,
2382+
)
23622383
}
23632384
}
23642385
(None, Some(addresses)) => {
@@ -2369,9 +2390,14 @@ impl TestIndexer {
23692390
)
23702391
.await?;
23712392
let payload_string = if let Some(payload) = payload {
2372-
payload.to_string()
2393+
payload
2394+
.to_string()
2395+
.map_err(|e| IndexerError::CustomError(e.to_string()))?
23732396
} else {
2374-
payload_legacy.unwrap().to_string()
2397+
payload_legacy
2398+
.unwrap()
2399+
.to_string()
2400+
.map_err(|e| IndexerError::CustomError(e.to_string()))?
23752401
};
23762402
(Vec::new(), indices, payload_string)
23772403
}
@@ -2448,6 +2474,7 @@ impl TestIndexer {
24482474
non_inclusion: non_inclusion_payload.inputs,
24492475
}
24502476
.to_string()
2477+
.map_err(|e| IndexerError::CustomError(e.to_string()))?
24512478
} else if let Some(non_inclusion_payload) = non_inclusion_payload_legacy {
24522479
CombinedJsonStructLegacy {
24532480
circuit_type: ProofType::Combined.to_string(),
@@ -2457,6 +2484,7 @@ impl TestIndexer {
24572484
non_inclusion: non_inclusion_payload.inputs,
24582485
}
24592486
.to_string()
2487+
.map_err(|e| IndexerError::CustomError(e.to_string()))?
24602488
} else {
24612489
panic!("Unsupported tree height")
24622490
};
@@ -2481,9 +2509,11 @@ impl TestIndexer {
24812509
if response_result.status().is_success() {
24822510
let body = response_result.text().await.unwrap();
24832511
let proof_json = deserialize_gnark_proof_json(&body).unwrap();
2484-
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()))?;
24852514
let (proof_a, proof_b, proof_c) =
2486-
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()))?;
24872517
return Ok(ValidityProofWithContext {
24882518
accounts: account_proof_inputs,
24892519
addresses: address_proof_inputs,

0 commit comments

Comments
 (0)