Skip to content

Commit b295c04

Browse files
Fix fuzzer
1 parent b590580 commit b295c04

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

tests/fuzzer/fuzz/fuzz_targets/system_functions/ecrecover.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,24 @@ use zk_ee::reference_implementations::BaseResources;
88
use zk_ee::system::SystemFunction;
99
use zk_ee::system::Resource;
1010
use zk_ee::reference_implementations::DecreasingNative;
11+
use zk_ee::system::logger::NullLogger;
1112

1213
const ECRECOVER_SRC_REQUIRED_LENGTH: usize = 128;
1314

15+
struct DummyOracle;
16+
17+
impl zk_ee::oracle::IOOracle for DummyOracle {
18+
type RawIterator<'a> = Box<dyn ExactSizeIterator<Item = usize> + 'static>;
19+
20+
fn raw_query<'a, I: zk_ee::oracle::usize_serialization::UsizeSerializable + zk_ee::oracle::usize_serialization::UsizeDeserializable>(
21+
&'a mut self,
22+
_query_type: u32,
23+
_input: &I,
24+
) -> Result<Self::RawIterator<'a>, zk_ee::system::errors::internal::InternalError> {
25+
unreachable!("oracle should not be consulted on native targets");
26+
}
27+
}
28+
1429
fn fuzz(data: &[u8]) {
1530
let u = &mut Unstructured::new(data);
1631
let src = u
@@ -32,7 +47,7 @@ fn fuzz(data: &[u8]) {
3247

3348
let mut dst = dst.clone();
3449

35-
let _ = EcRecoverImpl::execute(&src.as_slice()[0..n], &mut dst, &mut resource, allocator);
50+
let _ = EcRecoverImpl::execute(&src.as_slice()[0..n], &mut dst, &mut resource, &mut DummyOracle, &mut NullLogger, allocator)
3651
}
3752

3853
fuzz_target!(|data: &[u8]| {

tests/fuzzer/fuzz/wrappers/fuzz_precompiles_forward/src/precompiles.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ use zk_ee::reference_implementations::DecreasingNative;
1414
use zk_ee::system::errors::subsystem::SubsystemError;
1515
use zk_ee::system::base_system_functions::{Bn254AddErrors,Sha256Errors,RipeMd160Errors,Keccak256Errors,
1616
Bn254MulErrors,P256VerifyErrors,Secp256k1ECRecoverErrors,Bn254PairingCheckErrors,PointEvaluationErrors};
17+
use zk_ee::system::logger::NullLogger;
18+
19+
struct DummyOracle;
20+
21+
impl zk_ee::oracle::IOOracle for DummyOracle {
22+
type RawIterator<'a> = Box<dyn ExactSizeIterator<Item = usize> + 'static>;
23+
24+
fn raw_query<'a, I: zk_ee::oracle::usize_serialization::UsizeSerializable + zk_ee::oracle::usize_serialization::UsizeDeserializable>(
25+
&'a mut self,
26+
_query_type: u32,
27+
_input: &I,
28+
) -> Result<Self::RawIterator<'a>, zk_ee::system::errors::internal::InternalError> {
29+
unreachable!("oracle should not be consulted on native targets");
30+
}
31+
}
1732

1833
pub fn ecadd(src: &[u8], dst: &mut Vec<u8>) -> Result<(), SubsystemError<Bn254AddErrors>> {
1934
let allocator = std::alloc::Global;
@@ -54,7 +69,7 @@ pub fn p256_verify(src: &[u8], dst: &mut Vec<u8>) -> Result<(), SubsystemError<P
5469
pub fn ecrecover(src: &[u8], dst: &mut Vec<u8>) -> Result<(), SubsystemError<Secp256k1ECRecoverErrors>> {
5570
let allocator = std::alloc::Global;
5671
let mut resource = <BaseResources<DecreasingNative> as Resource>::FORMAL_INFINITE;
57-
EcRecoverImpl::execute(&src, dst, &mut resource, allocator)
72+
EcRecoverImpl::execute(&src, dst, &mut resource, &mut DummyOracle, &mut NullLogger, allocator)
5873
}
5974

6075
pub fn pairing(src: &[u8], dst: &mut Vec<u8>) -> Result<(), SubsystemError<Bn254PairingCheckErrors>> {

0 commit comments

Comments
 (0)