Skip to content

Commit

Permalink
FMT
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-valerio committed Oct 16, 2024
1 parent b565286 commit 97cb74e
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
- name: Run AFL++ configuration
run:
cargo afl config --build --plugins --verbose --force
sudo cargo-afl afl system-config
e

- name: Compile samples in `sample`
working-directory: ./sample
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload entire repository
# Upload entire documentation
path: './book/documentation'
- name: Deploy to GitHub Pages
id: deployment
Expand Down
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ RUN rustup default nightly \
# Clone and build the project
WORKDIR /phink

RUN git clone https://github.com/srlabs/phink . \
&& cargo update \
&& cargo build --release
RUN git clone https://github.com/srlabs/phink . && cargo build --release

RUN cargo afl config --build --plugins --verbose --force

Expand Down
8 changes: 2 additions & 6 deletions README.Docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ includes:
- LLVM 19 and Clang 19 are installed

2. **Setting Up Rust**:
- This Dockerfile sets Rust to nightly version (`nightly`) to ensure compatibility with Phink's
- This Dockerfile sets Rust to nightly version (`nightly`) to ensure compatibility with Phink's
codebase.
- Additional Rust components and tools such as `rust-src`, `cargo-afl`, `honggfuzz`, `grcov`, and `cargo-contract`
are installed to support fuzzing and coverage instrumentation.
Expand Down Expand Up @@ -52,15 +52,11 @@ includes:

To fuzz your instrumented ink! smart-contract:
```bash
docker run --rm phink fuzz <path_to_instrumented_contract>
docker run --rm phink fuzz
```
Please, note that `path_to_instrumented_contract` corresponds to the directory created after the instrumentation
step (as shown above). `path_to_instrumented_contract` is *not* the same path as `path_to_your_contract` !

### Notes

- **No files copied into `/bin`**: The Dockerfile intentionally avoids copying files into `/bin` to keep the
`phink.toml` configuration and `sample/` directory accessible for user interaction within the container.

- **Minimal image size**: Unnecessary files, such as package lists, are removed during the build to reduce the image
size.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ _Refer to [README.Docker.md](README.Docker.md) for more detailed instructions on

```bash
phink instrument path/to/ink_contract
phink fuzz /tmp/ink_fuzzed_Bb9Zp # you can get this path by reading the output of the previous command
phink fuzz
```

## Example
Expand Down
31 changes: 31 additions & 0 deletions sample/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
echo "$SCRIPT_DIR"
cd "$SCRIPT_DIR" || exit

echo "We're building every contract :-)"
for dir in */; do
# Remove trailing slash from directory name
dir=${dir%/}

echo "Building $dir..."

# Ensure we have a Cargo.toml file in the directory before proceeding
if [ -f "$dir/Cargo.toml" ]; then
if [ "$dir" = "multi-contract-caller" ]; then
# Execute build-all.sh for multi-contract-caller
(cd "$dir" && ./build-all.sh)
else
# Execute cargo contract build for other directories
(cd "$dir" && cargo clean)
fi
echo "Finished building $dir"
else
echo "Skipping $dir: Cargo.toml not found."
fi

echo
done

echo "All builds completed."
2 changes: 1 addition & 1 deletion src/cli/ui/monitor/corpus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl FromPath for CorpusWatcher {
}
}

fn get_pfile_type() -> PFiles {
fn get_filetype() -> PFiles {
PFiles::CorpusPath
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/cli/ui/monitor/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,13 @@ impl Debug for AFLDashboard {
let mut reader = BufReader::new(file);
reader.seek(SeekFrom::Start(0)).map_err(|_| fmt::Error)?;

if let Ok(lines) = reader.lines().collect() {
let last_20_lines = lines.iter().rev().take(20).cloned().collect::<Vec<_>>();
if let Ok(lines) = reader.lines().collect::<io::Result<Vec<String>>>() {
let last_20_lines = lines
.iter()
.rev()
.take(20)
.cloned()
.collect::<Vec<String>>();
for line in last_20_lines.iter().rev() {
writeln!(f, "{line}")?;
}
Expand All @@ -169,7 +174,7 @@ impl FromPath for AFLDashboard {
AFLDashboard { log_fullpath }
}

fn get_pfile_type() -> PFiles {
fn get_filetype() -> PFiles {
PFiles::AFLLog
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/cli/ui/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub trait FromPath {
}

fn from_output(output: PathBuf) -> anyhow::Result<Self::Output> {
let path = PhinkFiles::new(output).path(Self::get_pfile_type());
let path = PhinkFiles::new(output).path(Self::get_filetype());

match path.exists() {
true => Self::from_fullpath(path),
Expand All @@ -33,5 +33,5 @@ pub trait FromPath {

fn create_instance(path: PathBuf) -> Self::Output;

fn get_pfile_type() -> PFiles;
fn get_filetype() -> PFiles;
}
4 changes: 2 additions & 2 deletions src/fuzzer/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ pub fn parse_input(bytes: &[u8], manager: CampaignManager) -> OneInput {

input.messages.push(Message {
is_payable,
payload: encoded_message.into(),
payload: encoded_message,
value_token,
message_metadata,
origin,
Expand All @@ -274,7 +274,7 @@ pub fn decode_contract_message(
use contract_transcode::Map;
use std::io::Read;

let mut data_as_slice = data.as_slice().clone();
let mut data_as_slice = data.as_slice();
let mut msg_selector: [u8; 4] = [0u8; 4];
data_as_slice.read_exact(&mut msg_selector)?;
let msg_spec = guard
Expand Down
5 changes: 3 additions & 2 deletions src/instrumenter/instrumentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ impl Instrumenter {
} else {
bail!(
"{stderr} - {stdout} It seems that your instrumented smart contract did not compile properly. \
Please go to `{p_display}`, edit the source code, and run `cargo contract build --features phink` again. It might be because your contract has a bug inside, or because you haven't created any invariants for instance.\
Also, make sur that your Cargo.toml contains the `phink` feature.\nMore informations in the stacktrace above.",
Please go to `{p_display}`, edit the source code, and run `cargo contract build --features phink` again. It might be because your contract has a bug inside, or because you haven't created any invariants for instance. \
Also, make sur that your Cargo.toml contains the `phink` feature. Sometimes it's because you need to recompile the contract, as you've changed the toolchain.\
\nMore informations in the stacktrace above.",
)
}

Expand Down
6 changes: 1 addition & 5 deletions tests/cli_fuzz_integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ mod tests {
fs,
time::Duration,
};
use tempfile::{
tempdir,
tempdir_in,
TempDir,
};
use tempfile::tempdir;

#[test]
#[cfg_attr(target_os = "macos", ignore)]
Expand Down
4 changes: 2 additions & 2 deletions tests/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
gnupg \
software-properties-common \
ca-certificates \
sudo \
&& wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \
&& echo "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-19 main" >> /etc/apt/sources.list.d/llvm.list \
&& apt-get update && apt-get install -y --no-install-recommends \
Expand Down Expand Up @@ -47,5 +48,4 @@ RUN chmod 777 build.sh && bash build.sh

WORKDIR /phink
ENV RUST_BACKTRACE=1
CMD ["cargo", "test", "--no-fail-fast", "--", "--show-output", "--test-threads=1"]
#CMD ["cargo", "run"]
CMD ["cargo", "test", "--no-fail-fast", "--", "--show-output", "--test-threads=1"]
5 changes: 1 addition & 4 deletions tests/shared/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ use anyhow::{
Result,
};
use assert_cmd::Command;
use phink_lib::{
cli::config::Configuration,
instrumenter::path::InstrumentedPath,
};
use phink_lib::cli::config::Configuration;

use assert_cmd::assert::Assert;
use std::{
Expand Down

0 comments on commit 97cb74e

Please sign in to comment.