Skip to content

Commit

Permalink
Move fuzz inside soroban-env-host
Browse files Browse the repository at this point in the history
  • Loading branch information
jayz22 committed Nov 2, 2023
1 parent 9c4f48a commit 3d435ef
Show file tree
Hide file tree
Showing 17 changed files with 30 additions and 1,160 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# target = "triple" # build for the target triple (ignored by `cargo install`)
# target-dir = "target" # path of where to place all generated artifacts
rustflags = [
# "-Dwarnings",
"-Dwarnings",
"-Aclippy::style",
# "-Dclippy::pedantic",
# "-Aclippy::module_name_repetitions",
Expand Down
4 changes: 0 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ members = [
"soroban-test-wasms",
"soroban-synth-wasm",
"soroban-bench-utils",
"soroban-fuzz-host"
]

exclude = ["soroban-test-wasms/wasm-workspace"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub(crate) struct ComputeSha256HashMeasure;
impl HostCostMeasurement for ComputeSha256HashMeasure {
type Runner = ComputeSha256HashRun;

fn new_random_case(host: &Host, _rng: &mut StdRng, input: u64) -> Vec<u8> {
fn new_random_case(_host: &Host, _rng: &mut StdRng, input: u64) -> Vec<u8> {
let size = 1 + input * Self::STEP_SIZE;
(0..size).map(|n| n as u8).collect()
}
Expand Down
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "soroban-fuzz-host-fuzz"
name = "soroban-env-host-fuzz"
version = "0.0.0"
publish = false
edition = "2021"
Expand All @@ -9,9 +9,9 @@ cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
debug_logging = { path = "../debug_logging"}
soroban-env-host = { path = "../../soroban-env-host", features = ["testutils"]}
arbitrary = { version = "1.3.0", features = ["derive"] }
soroban-env-host = { path = "..", features = ["testutils"]}
soroban-synth-wasm = { path = "../../soroban-synth-wasm"}

# Prevent this from interfering with workspaces
[workspace]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![no_main]

use libfuzzer_sys::fuzz_target;
use debug_logging::wasm_module_with_linear_memory_logging;
use arbitrary::Arbitrary;
use soroban_env_host::{Host, Symbol, budget::AsBudget, Env};
use soroban_env_host_fuzz::wasm_module_with_linear_memory_logging;

#[derive(Arbitrary, Debug)]
struct Input {
Expand Down Expand Up @@ -32,5 +32,5 @@ fuzz_target!(|input: Input| {
let cpu = host.as_budget().get_cpu_insns_consumed().unwrap();
let mem = host.as_budget().get_mem_bytes_consumed().unwrap();

assert_eq!((cpu,mem), (1075678, 203437) );
assert_eq!((cpu,mem), (1073488, 203274) );
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use soroban_env_host::{Host, Symbol, SymbolSmall, budget::AsBudget, Env};
use soroban_synth_wasm::{Arity, LocalRef, ModEmitter, Operand};

pub fn wasm_module_with_linear_memory_logging() -> Vec<u8> {
Expand Down
2 changes: 2 additions & 0 deletions soroban-env-host/fuzz/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod debug_log;
pub use debug_log::*;
2 changes: 1 addition & 1 deletion soroban-env-host/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ impl Host {

#[cfg(any(test, feature = "testutils"))]
pub(crate) fn source_account_id(&self) -> Result<Option<AccountId>, HostError> {
Ok(self.try_borrow_source_account()?.metered_clone(self)?)
self.try_borrow_source_account()?.metered_clone(self)
}

#[cfg(any(test, feature = "testutils"))]
Expand Down
21 changes: 10 additions & 11 deletions soroban-env-host/src/testutils.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
use std::{cell::RefCell, collections::BTreeMap, rc::Rc};
use std::{collections::BTreeMap, rc::Rc};

use rand::RngCore;
use soroban_env_common::{
xdr::{
AccountEntry, AccountId, ContractCostType, LedgerEntry, LedgerEntryData, LedgerKey,
PublicKey, ScAddress, ScErrorCode, ScErrorType, ScVal, ScVec, Uint256,
AccountEntry, AccountId, LedgerEntry, LedgerEntryData, LedgerKey, PublicKey, ScAddress,
ScErrorCode, ScErrorType, ScVal, ScVec, Uint256,
},
AddressObject, BytesObject, Env, EnvBase, Symbol, Val, VecObject,
AddressObject, BytesObject, Env, EnvBase, Val, VecObject,
};

use crate::{
budget::{AsBudget, Budget},
host::HostLifecycleEvent,
budget::Budget,
storage::{SnapshotSource, Storage},
xdr, Error, Host, HostError, LedgerInfo,
};


// Test utilities for the host, used in various tests in sub-modules.
pub trait AsScVal {
fn as_scval(&self) -> ScVal;
Expand Down Expand Up @@ -48,13 +46,14 @@ pub fn generate_account_id(host: &Host) -> AccountId {

pub fn generate_bytes_array(host: &Host) -> [u8; 32] {
let mut bytes: [u8; 32] = Default::default();
host.with_test_prng(|chacha| Ok(chacha.fill_bytes(&mut bytes)))
.unwrap();
host.with_test_prng(|chacha| {
chacha.fill_bytes(&mut bytes);
Ok(())
})
.unwrap();
bytes
}



pub struct MockSnapshotSource(BTreeMap<Rc<LedgerKey>, (Rc<LedgerEntry>, Option<u32>)>);

impl MockSnapshotSource {
Expand Down
2 changes: 0 additions & 2 deletions soroban-fuzz-host/.gitignore

This file was deleted.

Loading

0 comments on commit 3d435ef

Please sign in to comment.