Skip to content

Commit

Permalink
Mint fuzzing (#1236)
Browse files Browse the repository at this point in the history
* Adds an `openPair` function

* Removes some outdated comments

* Added governance fees to the mint function

* Updated the implementation of `HyperdrivePair`

* Updated the `mint` logic and wired it up

* Added unit test cases for the `mint` function

* Adds comprehensive unit tests for the mint function

* Adds a `minOutput` parameter to `mint`

* Wrote a comprehensive integration test suite for the `mint` function

* Started implementing `burn`

* Made some targeted fixes to `mint`

* Added zombie interest to the `burn` flow and cleaned up `HyperdrivePair`

* Started adding a test suite for the `burn` function

* Added the remaining test cases. Some of them are broken.

* Fixed the remaining `burn` unit tests

* Added an integration test suite for `burn`

* Bumping solidity version of mint to match rest of repo (#1235)

* Added tests for zombie interest for `mint` and `burn`

* Added more integration tests for `mint` and `burn`

* Added a negative interest test for `mint`

* Addressed review feedback from @Sean329

* Adding script for mint fuzz

* Adding git ignore for agent0 output

* Removing unused imports and using option field in burn

* Adding fixme comment

* Another fixme comment

* Adding readme to python fuzzing

* Pointing agent0 req to pypi

* Committed incremental progress

* Added more `mint` and `burn` related cases to the `InstanceTest` suite

* Fixed the failing `test_burn_with_base` tests

* Added another instance test and got all of the tests working

* Uncommented and fixed another test

* Uncommented the remaining test

* Fixed the code size issue

* Removed fixmes -- the investigation showed that the calculations worked correctly

* Fixed some of the CI jobs

* Fixed the LPWithdrawal tests

* Attempted to fix the code coverage job

* Removed the code coverage badge

* Fuzzing notes

* Got a working prototype of the `mint` and `burn` fuzzing working

* Added the `burn` route to the fuzz bots

* Updated remaining FIXMEs

* Removed newlines

---------

Co-authored-by: Alex Towle <[email protected]>
Co-authored-by: Sheng Lundquist <[email protected]>
  • Loading branch information
3 people authored Jan 25, 2025
1 parent 3497650 commit 2894b11
Show file tree
Hide file tree
Showing 8 changed files with 378 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ etherscan_requests/

# todos
TODO.md

# Agent0 fuzzing output files
.crash_report
4 changes: 2 additions & 2 deletions contracts/src/interfaces/IHyperdriveEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ interface IHyperdriveEvents is IMultiTokenEvents {
);

/// @notice Emitted when a pair of long and short positions are minted.
event Mint(
event MintBonds(
address indexed longTrader,
address indexed shortTrader,
uint256 indexed maturityTime,
Expand All @@ -117,7 +117,7 @@ interface IHyperdriveEvents is IMultiTokenEvents {
);

/// @notice Emitted when a pair of long and short positions are burned.
event Burn(
event BurnBonds(
address indexed trader,
address indexed destination,
uint256 indexed maturityTime,
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/internal/HyperdrivePair.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ abstract contract HyperdrivePair is IHyperdriveEvents, HyperdriveLP {
uint256 bondAmount_ = bondAmount; // avoid stack-too-deep
uint256 amount = _amount; // avoid stack-too-deep
IHyperdrive.PairOptions calldata options = _options; // avoid stack-too-deep
emit Mint(
emit MintBonds(
options.longDestination,
options.shortDestination,
maturityTime,
Expand Down Expand Up @@ -252,7 +252,7 @@ abstract contract HyperdrivePair is IHyperdriveEvents, HyperdriveLP {
// Emit a Burn event.
uint256 bondAmount = _bondAmount; // avoid stack-too-deep
IHyperdrive.Options calldata options = _options; // avoid stack-too-deep
emit Burn(
emit BurnBonds(
msg.sender,
options.destination,
_maturityTime,
Expand Down
32 changes: 32 additions & 0 deletions python-fuzz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Python fuzzing for mint/burn

This directory details how to install and run fuzzing on hyperdrive with mint/burn.

## Installation

First, compile the solidity contracts and make python types locally via `make`.

Next, follow the prerequisites installation instructions of [agent0](https://github.com/delvtech/agent0/blob/main/INSTALL.md).
Then install [uv](https://github.com/astral-sh/uv) for package management. No need to clone the repo locally
(unless developing on agent0).

From the base directory of the `hyperdrive` repo, set up a python virtual environment:

```
uv venv --python 3.10 .venv
source .venv/bin/activate
```

From here, you can install the generated python types and agent0 via:

```
uv pip install -r python-fuzz/requirements.txt
```

## Running fuzzing

To run fuzzing, simply run the `fuzz_mint_burn.py` script:

```
python fuzz_mint_burn.py
```
Loading

0 comments on commit 2894b11

Please sign in to comment.