Skip to content

Commit

Permalink
chore: viaIR, PUSH0 and 0.8.23 (#6)
Browse files Browse the repository at this point in the history
* chore: viaIR, PUSH0 and 0.8.23

* ignore out-optimized

* address comment
  • Loading branch information
r0ohafza authored Feb 14, 2024
1 parent 1d7073f commit 49eddbb
Show file tree
Hide file tree
Showing 47 changed files with 89 additions and 131 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ jobs:
run: pnpm install

- name: Build
run: pnpm build
run: pnpm build:optimized

- name: Lint
run: pnpm lint

- name: Test
run: pnpm test
run: pnpm test:optimized
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
"private": true,
"scripts": {
"build": "turbo build",
"build:optimized": "turbo build:optimized",
"dev": "turbo dev",
"lint": "turbo lint",
"lint:sol": "turbo lint:sol",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"test": "turbo test",
"test:optimized": "turbo test:optimized",
"test:coverage": "turbo test:coverage"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/splits-v2/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ coverage
lib
node_modules
out
out-optimized

# files
*.env
Expand Down
46 changes: 15 additions & 31 deletions packages/splits-v2/foundry.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[profile.default]
auto_detect_solc = false
gas_reports = ["*"]
gas_reports = ["SplitsWarehouse", "SplitFactoryV2", "SplitWalletV2"]
optimizer = true
optimizer_runs = 5_000_000
out = "out"
script = "script"
solc = "0.8.18"
solc = "0.8.23"
src = "src"
test = "test"
allow_paths = ['../../node_modules']
fs_permissions = [{ access = "read-write", path = "./" }]

evm_version = "shanghai"

[profile.default.fuzz]
max_test_rejects = 1_000_000
Expand All @@ -22,6 +22,18 @@ depth = 20
fail_on_revert = true
runs = 20

[profile.optimized]
out = "out-optimized"
via_ir = true

[profile.test-optimized]
ffi = true
src = "test"

[doc]
ignore = ["**/*.t.sol"]
out = "docs"

[profile.ci]
fuzz = { runs = 10_000 }
verbosity = 4
Expand All @@ -37,34 +49,6 @@ tab_width = 4
wrap_comments = true
sort_imports = true

[profile.smt]
out = "out-optimized"
script = "src"
test = "src"
via_ir = false

[profile.smt.model_checker]
engine = "chc" # constrained Horn clauses
invariants = ["contract", "reentrancy"]
show_proved_safe = true
show_unproved = true
show_unsupported = true
timeout = 100_000 # in milliseconds, per solving query
targets = [
"assert",
"constantCondition",
"divByZero",
"outOfBounds",
"overflow",
"underflow",
]

[profile.smt.model_checker.contracts]
"src/SplitsWarehouse.sol" = ["SplitsWarehouse"]
"src/splitters/SplitWalletV2.sol" = ["SplitWalletV2"]
"src/splitters/SplitFactoryV2.sol" = ["SplitFactoryV2"]


[etherscan]
mainnet = { key = "${ETHERSCAN_API_KEY}" }
sepolia = { key = "${ETHERSCAN_API_KEY}" }
Expand Down
17 changes: 10 additions & 7 deletions packages/splits-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
"description": "Splits v2 contracts",
"scripts": {
"build": "forge build",
"clean": "rm -rf cache out",
"lint": "pnpm lint:sol && prettier --check \"**/*.{json,md,yml}\"",
"build:optimized": "FOUNDRY_PROFILE=optimized forge build",
"clean": "rm -rf cache out out-optimized",
"lint": "pnpm lint:sol && pnpm run prettier:check",
"lint:sol": "forge fmt --check && pnpm solhint {script,src,test}/**/*.sol",
"format": "prettier --write \"**/*.{json,md,yml}\" --ignore-path=.prettierignore",
"prettier:check": "prettier --check \"**/*.{json,md,svg,yml}\"",
"prettier:write": "prettier --write \"**/*.{json,md,svg,yml}\"",
"test": "forge test -vvv",
"test:optimized": "pnpm run build:optimized && FOUNDRY_PROFILE=test-optimized forge test -vvv",
"test:coverage": "forge coverage",
"test:coverage:report": "forge coverage --report lcov && genhtml lcov.info --branch-coverage --output-dir coverage",
"deploy:SplitsWarehouse:test": "export DRY_RUN=true && source .env && forge script script/SplitsWarehouse.s.sol:SplitsWarehouseScript --account SPLITS_V2_DEPLOYER -vvvvv --rpc-url ",
"deploy:SplitsWarehouse": "export DRY_RUN=false && source .env && forge script script/SplitsWarehouse.s.sol:SplitsWarehouseScript --account SPLITS_V2_DEPLOYER --broadcast --verify --verifier sourcify -vvvvv --rpc-url ",
"deploy:SplitFactoryV2:test": "export DRY_RUN=true && source .env && forge script script/SplitFactoryV2.s.sol:SplitFactoryV2Script --account SPLITS_V2_DEPLOYER -vvvvv --rpc-url ",
"deploy:SplitFactoryV2": "export DRY_RUN=false && source .env && forge script script/SplitFactoryV2.s.sol:SplitFactoryV2Script --account SPLITS_V2_DEPLOYER --broadcast --verify --verifier sourcify -vvvvv --rpc-url "
"deploy:SplitsWarehouse:test": "export DRY_RUN=true && source .env && FOUNDRY_PROFILE=optimized forge script script/SplitsWarehouse.s.sol:SplitsWarehouseScript --account SPLITS_V2_DEPLOYER -vvvvv --rpc-url ",
"deploy:SplitsWarehouse": "export DRY_RUN=false && source .env && FOUNDRY_PROFILE=optimized forge script script/SplitsWarehouse.s.sol:SplitsWarehouseScript --account SPLITS_V2_DEPLOYER --broadcast --verify --verifier sourcify -vvvvv --rpc-url ",
"deploy:SplitFactoryV2:test": "export DRY_RUN=true && source .env && FOUNDRY_PROFILE=optimized forge script script/SplitFactoryV2.s.sol:SplitFactoryV2Script --account SPLITS_V2_DEPLOYER -vvvvv --rpc-url ",
"deploy:SplitFactoryV2": "export DRY_RUN=false && source .env && FOUNDRY_PROFILE=optimized forge script script/SplitFactoryV2.s.sol:SplitFactoryV2Script --account SPLITS_V2_DEPLOYER --broadcast --verify --verifier sourcify -vvvvv --rpc-url "
},
"keywords": [],
"author": "@splits",
Expand Down
2 changes: 1 addition & 1 deletion packages/splits-v2/script/Base.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.18;
pragma solidity ^0.8.23;

import { ICreateX } from "./ICreateX.sol";
import { Script } from "forge-std/Script.sol";
Expand Down
2 changes: 1 addition & 1 deletion packages/splits-v2/script/SplitFactoryV2.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.18;
pragma solidity ^0.8.23;

import { SplitFactoryV2 } from "../src/splitters/SplitFactoryV2.sol";

Expand Down
2 changes: 1 addition & 1 deletion packages/splits-v2/script/SplitsWarehouse.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.18;
pragma solidity ^0.8.23;

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

Expand Down
20 changes: 4 additions & 16 deletions packages/splits-v2/src/SplitsWarehouse.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// license?
pragma solidity ^0.8.18;
pragma solidity ^0.8.23;

import { Cast } from "./libraries/Cast.sol";
import { Math } from "./libraries/Math.sol";
Expand Down Expand Up @@ -182,14 +182,10 @@ contract SplitsWarehouse is ERC6909X {
uint256 amount;
uint256 tokenId = _token.toUint256();
uint256 length = _receivers.length;
for (uint256 i; i < length;) {
for (uint256 i; i < length; ++i) {
amount = _amounts[i];
sum += amount;
_mint(_receivers[i], tokenId, amount);

unchecked {
++i;
}
}

if (_token == NATIVE_TOKEN) {
Expand Down Expand Up @@ -239,13 +235,9 @@ contract SplitsWarehouse is ERC6909X {

uint256 reward;
uint256 length = _tokens.length;
for (uint256 i; i < length;) {
for (uint256 i; i < length; ++i) {
reward = _amounts[i] * config.incentive / PERCENTAGE_SCALE;
_withdraw(_owner, _tokens[i], _amounts[i], _withdrawer, reward);

unchecked {
++i;
}
}
}

Expand All @@ -263,17 +255,13 @@ contract SplitsWarehouse is ERC6909X {
uint256 amount;
address receiver;
uint256 length = _receivers.length;
for (uint256 i; i < length;) {
for (uint256 i; i < length; ++i) {
receiver = _receivers[i];
amount = _amounts[i];

balanceOf[receiver][tokenId] += amount;
emit Transfer(msg.sender, msg.sender, receiver, tokenId, amount);
sum += amount;

unchecked {
++i;
}
}
balanceOf[msg.sender][tokenId] -= sum;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/splits-v2/src/interfaces/IERC165.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.18;
pragma solidity ^0.8.23;

interface IERC165 {
/// @notice Checks if a contract implements an interface.
Expand Down
2 changes: 1 addition & 1 deletion packages/splits-v2/src/interfaces/IERC6909.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.18;
pragma solidity ^0.8.23;

import { IERC165 } from "./IERC165.sol";

Expand Down
2 changes: 1 addition & 1 deletion packages/splits-v2/src/interfaces/IERC6909X.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.18;
pragma solidity ^0.8.23;

import { IERC5267 } from "@openzeppelin/contracts/interfaces/IERC5267.sol";

Expand Down
2 changes: 1 addition & 1 deletion packages/splits-v2/src/interfaces/IERC6909XCallback.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.18;
pragma solidity ^0.8.23;

interface IERC6909XCallback {
function onTemporaryApprove(
Expand Down
2 changes: 1 addition & 1 deletion packages/splits-v2/src/interfaces/ISplitsWarehouse.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.18;
pragma solidity ^0.8.23;

import { IERC6909 } from "./IERC6909.sol";

Expand Down
2 changes: 1 addition & 1 deletion packages/splits-v2/src/interfaces/IWETH9.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.18;
pragma solidity ^0.8.23;

interface IWETH9 {
function deposit() external payable;
Expand Down
2 changes: 1 addition & 1 deletion packages/splits-v2/src/libraries/Cast.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.18;
pragma solidity ^0.8.23;

library Cast {
error Overflow();
Expand Down
2 changes: 1 addition & 1 deletion packages/splits-v2/src/libraries/Clone.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.18;
pragma solidity ^0.8.23;

/**
* @title Modified minimal proxy
Expand Down
12 changes: 3 additions & 9 deletions packages/splits-v2/src/libraries/Math.sol
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.18;
pragma solidity ^0.8.23;

library Math {
function sum(uint256[] calldata values) internal pure returns (uint256 total) {
for (uint256 i = 0; i < values.length;) {
for (uint256 i; i < values.length; ++i) {
total += values[i];
unchecked {
++i;
}
}
}

function sumMem(uint256[] memory values) internal pure returns (uint256 total) {
for (uint256 i = 0; i < values.length;) {
for (uint256 i; i < values.length; ++i) {
total += values[i];
unchecked {
++i;
}
}
}

Expand Down
17 changes: 4 additions & 13 deletions packages/splits-v2/src/libraries/SplitV2.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.18;
pragma solidity ^0.8.23;

library SplitV2Lib {
/* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -56,11 +56,8 @@ library SplitV2Lib {
}

uint256 totalAllocation;
for (uint256 i; i < numOfRecipients;) {
for (uint256 i; i < numOfRecipients; ++i) {
totalAllocation += _split.allocations[i];
unchecked {
++i;
}
}
if (totalAllocation != _split.totalAllocation) revert InvalidSplit_TotalAllocationMismatch();
}
Expand All @@ -79,11 +76,8 @@ library SplitV2Lib {
distributorReward = _amount * _split.distributionIncentive / PERCENTAGE_SCALE;
_amount -= distributorReward;

for (uint256 i; i < numOfRecipients;) {
for (uint256 i; i < numOfRecipients; ++i) {
amounts[i] = _amount * _split.allocations[i] / _split.totalAllocation;
unchecked {
++i;
}
}
}

Expand All @@ -101,11 +95,8 @@ library SplitV2Lib {
distributorReward = _amount * _split.distributionIncentive / PERCENTAGE_SCALE;
_amount -= distributorReward;

for (uint256 i; i < numOfRecipients;) {
for (uint256 i; i < numOfRecipients; ++i) {
amounts[i] = _amount * _split.allocations[i] / _split.totalAllocation;
unchecked {
++i;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/splits-v2/src/splitters/SplitFactoryV2.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.18;
pragma solidity ^0.8.23;

// TODO: do we want to use our clone or the minimal standard?
import { Clone } from "../libraries/Clone.sol";
Expand Down
14 changes: 3 additions & 11 deletions packages/splits-v2/src/splitters/SplitWalletV2.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.18;
pragma solidity ^0.8.23;

import { ISplitsWarehouse } from "../interfaces/ISplitsWarehouse.sol";

Expand Down Expand Up @@ -222,28 +222,20 @@ contract SplitWalletV2 is Wallet {
uint256 allocatedAmount;

if (_token == NATIVE_TOKEN) {
for (uint256 i; i < numOfRecipients;) {
for (uint256 i; i < numOfRecipients; ++i) {
allocatedAmount = _split.calculateAllocatedAmount(amountToDistribute, i);

if (!_split.recipients[i].trySafeTransferETH(allocatedAmount, SafeTransferLib.GAS_STIPEND_NO_GRIEF)) {
SPLITS_WAREHOUSE.deposit{ value: allocatedAmount }(_split.recipients[i], _token, allocatedAmount);
}

unchecked {
++i;
}
}

if (distributorReward > 0) _distributor.safeTransferETH(distributorReward);
} else {
for (uint256 i; i < numOfRecipients;) {
for (uint256 i; i < numOfRecipients; ++i) {
allocatedAmount = _split.calculateAllocatedAmount(amountToDistribute, i);

IERC20(_token).safeTransfer(_split.recipients[i], allocatedAmount);

unchecked {
++i;
}
}

if (distributorReward > 0) IERC20(_token).safeTransfer(_distributor, distributorReward);
Expand Down
2 changes: 1 addition & 1 deletion packages/splits-v2/src/tokens/ERC6909.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.18;
pragma solidity ^0.8.23;

import { IERC165 } from "../interfaces/IERC165.sol";
import { IERC6909 } from "../interfaces/IERC6909.sol";
Expand Down
Loading

0 comments on commit 49eddbb

Please sign in to comment.