Skip to content

Commit

Permalink
Enable via-ir
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeSandwich committed Feb 28, 2024
1 parent 99796cc commit 62d9ef5
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
if: ${{ github.event_name == 'push' }}
run: echo FOUNDRY_FUZZ_RUNS=50000 >> $GITHUB_ENV
- name: run tests
run: forge test --deny-warnings
run: FOUNDRY_PROFILE=optimized forge test --deny-warnings
- name: run Slither
uses: crytic/slither-action@v0.3.0
with:
Expand Down
6 changes: 5 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
[profile.default]
solc_version = '0.8.24'
evm_version = 'shanghai'
optimizer_runs = 7_700
optimizer = false
verbosity = 1
fuzz_runs = 5
[profile.optimized]
via_ir = true
optimizer = true
optimizer_runs = 1_000_000_000
[fmt]
line_length = 100
[fuzz]
Expand Down
8 changes: 5 additions & 3 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ ffffffffffffffffffffffffffe0908116603f0116810190838211818310171561059b5761059b61
}

drips_deployer() {
local GET_DEPLOYED="getDeployed(address deployer, bytes32 salt)(address deployed))"
local GET_DEPLOYED="getDeployed(address deployer, bytes32 salt)(address deployed)"
local SALT="$(cast format-bytes32-string "$DRIPS_DEPLOYER_SALT")"
cast call "$CREATE3_FACTORY" "$GET_DEPLOYED" "$WALLET" "$SALT"
}
Expand Down Expand Up @@ -197,6 +197,8 @@ query() {
}

main() {
export FOUNDRY_PROFILE=optimized

verify_parameter ETH_RPC_URL
verify_parameter WALLET_ARGS
verify_parameter DRIPS_DEPLOYER_SALT
Expand Down Expand Up @@ -278,8 +280,8 @@ main() {
esac
done

print_title "Installing dependencies"
forge install
print_title "Building the contracts"
forge build --skip test

if [ -n "$DEPLOY_DETERMINISTIC_DEPLOYER" ]; then
deploy_deterministic_deployer
Expand Down
2 changes: 2 additions & 0 deletions scripts/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ verify_single() {
}

main() {
export FOUNDRY_PROFILE=optimized

if [ -z "$1" ]; then
echo "Error: expected 1 argument, the DripsDeployer address, see README.md"
exit 1
Expand Down
12 changes: 6 additions & 6 deletions src/DripsDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ abstract contract ProxyDeployerModule is BaseModule {
}

abstract contract DripsDependentModule is BaseModule {
bytes32 internal immutable _dripsModuleSalt = "Drips";
bytes32 internal constant _DRIPS_MODULE_SALT = "Drips";

function _dripsModule() internal view returns (DripsModule) {
address module = _moduleAddress(_dripsModuleSalt);
address module = _moduleAddress(_DRIPS_MODULE_SALT);
require(Address.isContract(module), "Drips module not deployed");
return DripsModule(module);
}
Expand All @@ -150,7 +150,7 @@ contract DripsModule is DripsDependentModule, ProxyDeployerModule {
}

constructor(DripsDeployer dripsDeployer_, uint32 dripsCycleSecs_, address proxyAdmin_)
BaseModule(dripsDeployer_, _dripsModuleSalt)
BaseModule(dripsDeployer_, _DRIPS_MODULE_SALT)
{
dripsCycleSecs = dripsCycleSecs_;
// slither-disable-next-line too-many-digits
Expand Down Expand Up @@ -179,10 +179,10 @@ contract DripsModule is DripsDependentModule, ProxyDeployerModule {
}

abstract contract CallerDependentModule is BaseModule {
bytes32 internal immutable _callerModuleSalt = "Caller";
bytes32 internal constant _CALLER_MODULE_SALT = "Caller";

function _callerModule() internal view returns (CallerModule) {
address module = _moduleAddress(_callerModuleSalt);
address module = _moduleAddress(_CALLER_MODULE_SALT);
require(Address.isContract(module), "Caller module not deployed");
return CallerModule(module);
}
Expand All @@ -193,7 +193,7 @@ contract CallerModule is ContractDeployerModule, CallerDependentModule {
return abi.encode(dripsDeployer);
}

constructor(DripsDeployer dripsDeployer_) BaseModule(dripsDeployer_, _callerModuleSalt) {
constructor(DripsDeployer dripsDeployer_) BaseModule(dripsDeployer_, _CALLER_MODULE_SALT) {
// slither-disable-next-line too-many-digits
_deployContract(type(Caller).creationCode);
}
Expand Down
10 changes: 5 additions & 5 deletions test/Caller.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ contract CallerTest is Test {
uint256 input = 1234567890;
bytes memory data = abi.encodeCall(target.run, (input));
uint256 value = 4321;
uint256 deadline = block.timestamp;
uint256 deadline = vm.getBlockTimestamp();
(bytes32 r, bytes32 sv) = signCall(senderKey, target, data, value, 0, deadline);

bytes memory returned =
Expand All @@ -56,7 +56,7 @@ contract CallerTest is Test {

function testCallSignedRejectsExpiredDeadline() public {
bytes memory data = abi.encodeCall(target.run, (1));
uint256 deadline = block.timestamp;
uint256 deadline = vm.getBlockTimestamp();
skip(1);
(bytes32 r, bytes32 sv) = signCall(senderKey, target, data, 0, 0, deadline);

Expand All @@ -66,7 +66,7 @@ contract CallerTest is Test {

function testCallSignedRejectsInvalidNonce() public {
bytes memory data = abi.encodeCall(target.run, (1));
uint256 deadline = block.timestamp;
uint256 deadline = vm.getBlockTimestamp();
(bytes32 r, bytes32 sv) = signCall(senderKey, target, data, 0, 0, deadline);
caller.callSigned(sender, address(target), data, deadline, r, sv);
assertNonce(sender, 1);
Expand All @@ -77,7 +77,7 @@ contract CallerTest is Test {

function testCallSignedRejectsInvalidSigner() public {
bytes memory data = abi.encodeCall(target.run, (1));
uint256 deadline = block.timestamp;
uint256 deadline = vm.getBlockTimestamp();
(bytes32 r, bytes32 sv) = signCall(senderKey + 1, target, data, 0, 0, deadline);

vm.expectRevert(ERROR_SIGNATURE);
Expand All @@ -87,7 +87,7 @@ contract CallerTest is Test {
function testCallSignedBubblesErrors() public {
// Zero input triggers a revert in Target
bytes memory data = abi.encodeCall(target.run, (0));
uint256 deadline = block.timestamp;
uint256 deadline = vm.getBlockTimestamp();
(bytes32 r, bytes32 sv) = signCall(senderKey, target, data, 0, 0, deadline);

vm.expectRevert(ERROR_ZERO_INPUT);
Expand Down
8 changes: 4 additions & 4 deletions test/Drips.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ contract DripsTest is Test {
}

function skipToCycleEnd() internal {
skip(drips.cycleSecs() - (block.timestamp % drips.cycleSecs()));
skip(drips.cycleSecs() - (vm.getBlockTimestamp() % drips.cycleSecs()));
}

function loadStreams(uint256 forAccount)
Expand Down Expand Up @@ -149,7 +149,7 @@ contract DripsTest is Test {
storeStreams(forAccount, newReceivers);
assertEq(realBalanceDelta, balanceDelta, "Invalid real balance delta");
(,, uint32 updateTime, uint128 actualBalance,) = drips.streamsState(forAccount, erc20);
assertEq(updateTime, block.timestamp, "Invalid new last update time");
assertEq(updateTime, vm.getBlockTimestamp(), "Invalid new last update time");
assertEq(balanceTo, actualBalance, "Invalid streams balance");
assertOwnBalance(uint256(int256(ownBalanceBefore) - balanceDelta));
assertDripsBalance(uint256(int256(dripsBalanceBefore) + balanceDelta));
Expand Down Expand Up @@ -473,7 +473,7 @@ contract DripsTest is Test {
setStreams(accountId, 0, 2, receivers);

// Create history
uint32 lastUpdate = uint32(block.timestamp);
uint32 lastUpdate = uint32(vm.getBlockTimestamp());
uint32 maxEnd = lastUpdate + 2;
StreamsHistory[] memory history = new StreamsHistory[](1);
history[0] = StreamsHistory(0, receivers, lastUpdate, maxEnd);
Expand Down Expand Up @@ -541,7 +541,7 @@ contract DripsTest is Test {
StreamReceiver[] memory receivers = streamsReceivers(receiver, 1);
setStreams(accountId, 0, 2, receivers);
uint256 balanceAt =
drips.balanceAt(accountId, erc20, receivers, uint32(block.timestamp + 1));
drips.balanceAt(accountId, erc20, receivers, uint32(vm.getBlockTimestamp() + 1));
assertEq(balanceAt, 1, "Invalid balance");
}

Expand Down
Loading

0 comments on commit 62d9ef5

Please sign in to comment.