Crates.io | phink |
lib.rs | phink |
version | |
source | src |
created_at | 2024-10-17 15:18:05.346422 |
updated_at | 2024-10-28 11:39:59.09296 |
description | π Phink, a ink! smart-contract property-based and coverage-guided fuzzer |
homepage | https://srlabs.github.io/phink/ |
repository | https://github.com/kevin-valerio/phink |
max_upload_size | |
id | 1413347 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Phink is a blazing-fastβ‘, property-based, coverage-guided fuzzer for ink! smart contracts. It enables developers to embed inviolable properties into their smart contract testing workflows, equipping them with automatic tools to detect vulnerabilities and ensure contract reliability before deployment. Please, read the documentation in order to properly use Phink.
β οΈ This project is actively under development with new features and improvements being made regularly. Contributions and feedback are welcome!
For documentation, visit our documentation site here. If you have any question, feedback, features suggestion, join our Discord.
cargo install --force ziggy cargo-afl honggfuzz grcov cargo-contract --locked
cargo afl config --build --plugins --verbose --force # don't use `--plugins` if you're on macOS
sudo cargo-afl afl system-config
cargo install --git https://github.com/srlabs/phink
phink --help
If you prefer to install Phink manually, follow these steps:
git clone https://github.com/kevin-valerio/phink
cd phink/ && cargo build --release
./target/release/phink --help
Alternatively, you can use Docker to set up and run Phink without needing to manually install dependencies. Detailed instructions are available in README.Docker.md. To build the Docker image:
docker build -t phink .
phink instrument path/to/ink_contract
phink generate-seed path/to/ink_contract #optional
phink fuzz
To use Phink via Docker, you can run:
docker run --rm phink
For instrumenting a contract:
docker run --rm phink instrument path/to/ink_contract
Refer to README.Docker.md for more detailed instructions on using Phink with Docker.
Below are some invariants created for the dns contract.
phink
feature to your Cargo.toml
[features]
phink = []
#[cfg(feature = "phink")]
#[ink(impl)]
impl DomainNameService {
// This invariant ensures that `domains` doesn't contain the forbidden domain that nobody should regsiter
#[ink(message)]
#[cfg(feature = "phink")]
pub fn phink_assert_hash42_cant_be_registered(&self) {
for i in 0..self.domains.len() {
if let Some(domain) = self.domains.get(i) {
// Invariant triggered! We caught an invalid domain in the storage...
assert_ne!(domain.clone().as_mut(), FORBIDDEN_DOMAIN);
}
}
}
// This invariant ensures that nobody registed the forbidden number
#[ink(message)]
#[cfg(feature = "phink")]
pub fn phink_assert_dangerous_number(&self) {
let forbidden_number = 42;
assert_ne!(self.dangerous_number, forbidden_number);
}
}
phink execute output/phink/crashes/<timestamp>/<id:000x:seed>
Below, the trace after executing the crash:
π Now fuzzing `/tmp/ink_fuzzed_XqUCn/target/ink/transfer.json` (5H31F11yQUkqugbgC7ur4rT2WLKSkZKAZUfcmHkKoLkaRaZ4)!
π€― An invariant got caught! Let's dive into it
π«΅ This was caused by `phink_assert_cannot_transfer_1337`
π Find below the trace that caused that invariant
π± Executing new seed
+---------+-------------------------------------------------------------------+
| Message | Details |
+---------+-------------------------------------------------------------------+
| pay_me | β½οΈ Gas required : Weight(ref_time: 591391866, proof_size: 28781) |
| | π₯ Gas consumed : Weight(ref_time: 582570121, proof_size: 12443) |
| | πΎ Storage deposit : StorageDeposit::Charge(0) |
| | πΈ Message was payable, and 1809739 units were transferred |
+---------+-------------------------------------------------------------------+
You can find various sample ink! smart-contracts in the sample/
directory. For detailed descriptions of these samples
and
instructions on how to instrument them for testing with Phink, please refer to the sample's README
file.