Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(MToken): handle mint reverts in Portal #189

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
name: Forge Integration Tests

on:
push:
branches:
- main
- spoke
pull_request:

permissions: write-all

jobs:
check:
name: Integration Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Run Forge build
run: |
forge --version
make sizes
id: build

- name: Run Forge integration tests
run: make integration profile=ci
# name: Forge Integration Tests
#
# on:
# push:
# branches:
# - main
# - spoke
# pull_request:
#
# permissions: write-all
#
# jobs:
# check:
# name: Integration Tests
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# with:
# submodules: recursive
#
# - name: Install Foundry
# uses: foundry-rs/foundry-toolchain@v1
#
# - name: Run Forge build
# run: |
# forge --version
# make sizes
# id: build
#
# - name: Run Forge integration tests
# run: make integration profile=ci
72 changes: 36 additions & 36 deletions .github/workflows/test-invariant.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
name: Forge Invariant Tests

on:
push:
branches:
- main
- spoke
pull_request:

permissions: write-all

jobs:
check:
name: Invariant Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Run Forge build
run: |
forge --version
make sizes
id: build

- name: Run Forge invariant tests
run: make invariant profile=ci
env:
# make fuzzing semi-deterministic to avoid noisy gas cost estimation
# due to non-deterministic fuzzing (but still use pseudo-random fuzzing seeds)
FOUNDRY_FUZZ_SEED: 0x${{ github.event.pull_request.base.sha || github.sha }}
MNEMONIC: ${{ secrets.MNEMONIC_FOR_TESTS }}
# name: Forge Invariant Tests
#
# on:
# push:
# branches:
# - main
# - spoke
# pull_request:
#
# permissions: write-all
#
# jobs:
# check:
# name: Invariant Tests
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# with:
# submodules: recursive
#
# - name: Install Foundry
# uses: foundry-rs/foundry-toolchain@v1
#
# - name: Run Forge build
# run: |
# forge --version
# make sizes
# id: build
#
# - name: Run Forge invariant tests
# run: make invariant profile=ci
# env:
# # make fuzzing semi-deterministic to avoid noisy gas cost estimation
# # due to non-deterministic fuzzing (but still use pseudo-random fuzzing seeds)
# FOUNDRY_FUZZ_SEED: 0x${{ github.event.pull_request.base.sha || github.sha }}
# MNEMONIC: ${{ secrets.MNEMONIC_FOR_TESTS }}
2 changes: 1 addition & 1 deletion script/DeployBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity 0.8.26;

import { ContractHelper } from "../lib/common/src/ContractHelper.sol";
import { ContractHelper } from "../lib/common/src/libs/ContractHelper.sol";

import { MToken } from "../src/MToken.sol";

Expand Down
23 changes: 2 additions & 21 deletions src/MToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ contract MToken is IMToken, ContinuousIndexing, ERC20Extended {
* @param amount_ The present amount to burn.
*/
function _burn(address account_, uint256 amount_) internal {
_revertIfInsufficientAmount(amount_);
if (amount_ == 0) revert InsufficientAmount(amount_);

emit Transfer(account_, address(0), amount_);

Expand All @@ -199,9 +199,6 @@ contract MToken is IMToken, ContinuousIndexing, ERC20Extended {
* @param amount_ The present amount to mint.
*/
function _mint(address recipient_, uint256 amount_) internal {
_revertIfInsufficientAmount(amount_);
_revertIfInvalidRecipient(recipient_);

emit Transfer(address(0), recipient_, amount_);

uint240 safeAmount_ = UIntMath.safe240(amount_);
Expand Down Expand Up @@ -327,7 +324,7 @@ contract MToken is IMToken, ContinuousIndexing, ERC20Extended {
* @param amount_ The present amount to transfer.
*/
function _transfer(address sender_, address recipient_, uint256 amount_) internal override {
_revertIfInvalidRecipient(recipient_);
if (recipient_ == address(0)) revert InvalidRecipient(recipient_);

emit Transfer(sender_, recipient_, amount_);

Expand Down Expand Up @@ -411,22 +408,6 @@ contract MToken is IMToken, ContinuousIndexing, ERC20Extended {
return RegistrarReader.isEarnersListIgnored(registrar) || RegistrarReader.isApprovedEarner(registrar, account_);
}

/**
* @dev Reverts if the amount of a `mint` or `burn` is equal to 0.
* @param amount_ Amount to check.
*/
function _revertIfInsufficientAmount(uint256 amount_) internal pure {
if (amount_ == 0) revert InsufficientAmount(amount_);
}

/**
* @dev Reverts if the recipient of a `mint` or `transfer` is address(0).
* @param recipient_ Address of the recipient to check.
*/
function _revertIfInvalidRecipient(address recipient_) internal pure {
if (recipient_ == address(0)) revert InvalidRecipient(recipient_);
}

/// @dev Reverts if the caller is not the portal.
function _revertIfNotPortal() internal view {
if (msg.sender != portal) revert NotPortal();
Expand Down
14 changes: 0 additions & 14 deletions test/MToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,6 @@ contract MTokenTests is TestUtils {
_mToken.mint(_alice, 0, 0);
}

function test_mint_insufficientAmount() external {
vm.expectRevert(abi.encodeWithSelector(IERC20Extended.InsufficientAmount.selector, 0));

vm.prank(_portal);
_mToken.mint(_alice, 0, 0);
}

function test_mint_invalidRecipient() external {
vm.expectRevert(abi.encodeWithSelector(IERC20Extended.InvalidRecipient.selector, address(0)));

vm.prank(_portal);
_mToken.mint(address(0), 1_000, 0);
}

function test_mint_toNonEarner() external {
vm.prank(_portal);
_mToken.mint(_alice, 1_000, 0);
Expand Down