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 review #11

Merged
merged 16 commits into from
Sep 7, 2024
Merged
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
4 changes: 2 additions & 2 deletions script/RumpelWalletFactory.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity =0.8.24;

import {Script, console} from "forge-std/Script.sol";
import {PointTokenVault} from "point-tokenization-vault/PointTokenVault.sol";
Expand Down
4 changes: 2 additions & 2 deletions src/InitializationScript.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity =0.8.24;

import {ISafe} from "./interfaces/external/ISafe.sol";
import {Enum} from "./interfaces/external/ISafe.sol";
Expand Down
4 changes: 2 additions & 2 deletions src/RumpelGuard.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity =0.8.24;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

Expand Down
9 changes: 4 additions & 5 deletions src/RumpelModule.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity =0.8.24;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

Expand All @@ -14,7 +14,6 @@ contract RumpelModule is Ownable {
struct Call {
ISafe safe;
address to;
uint256 value;
bytes data;
Enum.Operation operation;
}
Expand Down Expand Up @@ -49,13 +48,13 @@ contract RumpelModule is Ownable {
}
}

bool success = call.safe.execTransactionFromModule(call.to, call.value, call.data, call.operation);
bool success = call.safe.execTransactionFromModule(call.to, 0, call.data, call.operation);

if (!success) {
revert ExecFailed(call.safe, call.to, call.data);
}

emit ExecutionFromModule(call.safe, call.to, call.value, call.data);
emit ExecutionFromModule(call.safe, call.to, 0, call.data);

unchecked {
++i;
Expand Down
20 changes: 15 additions & 5 deletions src/RumpelWalletFactory.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity =0.8.24;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
Expand Down Expand Up @@ -45,6 +45,9 @@ contract RumpelWalletFactory is Ownable, Pausable {
uint256 threshold,
InitializationScript.InitCall[] calldata initCalls
) external whenNotPaused returns (address) {
// Calculate a unique salt based on the sender's address and nonce.
uint256 salt = uint256(keccak256(abi.encodePacked(msg.sender, saltNonce[msg.sender]++)));

address safe = proxyFactory.createProxyWithNonce(
safeSingleton,
abi.encodeWithSelector(
Expand All @@ -58,16 +61,22 @@ contract RumpelWalletFactory is Ownable, Pausable {
0, // payment
address(0) // paymentReceiver
),
saltNonce[msg.sender]++ // For deterministic address generation
salt // For deterministic address generation
);

emit SafeCreated(safe, owners, threshold);

return safe;
}

function precomputeAddress(bytes memory _initializer, uint256 _saltNonce) external view returns (address) {
bytes32 salt = keccak256(abi.encodePacked(keccak256(_initializer), _saltNonce));
function precomputeAddress(bytes memory _initializer, address _sender, uint256 _saltNonce)
external
view
returns (address)
{
bytes32 salt = keccak256(
abi.encodePacked(keccak256(_initializer), uint256(keccak256(abi.encodePacked(_sender, _saltNonce))))
);

bytes memory deploymentData =
abi.encodePacked(proxyFactory.proxyCreationCode(), uint256(uint160(safeSingleton)));
Expand All @@ -88,6 +97,7 @@ contract RumpelWalletFactory is Ownable, Pausable {
else if (what == "RUMPEL_MODULE") rumpelModule = data;
else if (what == "RUMPEL_GUARD") rumpelGuard = data;
else if (what == "INITIALIZATION_SCRIPT") initializationScript = data;
else if (what == "COMPATIBILITY_FALLBACK") compatibilityFallback = data;
else revert UnrecognizedParam(what);
emit ParamChanged(what, data);
}
Expand Down
2 changes: 1 addition & 1 deletion src/external/CompatibilityFallbackHandler.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;
pragma solidity =0.8.24;

import "safe-smart-account/contracts/handler/TokenCallbackHandler.sol";
import "safe-smart-account/contracts/Safe.sol";
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/external/IGuard.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity =0.8.24;

import {Enum} from "./ISafe.sol";

Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/external/ISafe.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity =0.8.24;

library Enum {
enum Operation {
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/external/ISafeProxyFactory.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity =0.8.24;

interface ISafeProxyFactory {
function createProxyWithNonce(address _singleton, bytes memory _initializer, uint256 _saltNonce)
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/external/ISignMessageLib.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity =0.8.24;

interface ISignMessageLib {
function signMessage(bytes calldata digest) external;
Expand Down
16 changes: 8 additions & 8 deletions test/RumpelWallet.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity =0.8.24;

import {Test, console} from "forge-std/Test.sol";
import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol";
Expand Down Expand Up @@ -90,20 +90,23 @@ contract RumpelWalletTest is Test {
address newScript = makeAddr("newScript");
address newSingleton = makeAddr("newSingleton");
address newProxyFactory = makeAddr("newProxyFactory");
address newCompatibilityFallback = makeAddr("newCompatibilityFallback");

vm.startPrank(admin);
rumpelWalletFactory.setParam("RUMPEL_GUARD", newGuard);
rumpelWalletFactory.setParam("RUMPEL_MODULE", newModule);
rumpelWalletFactory.setParam("INITIALIZATION_SCRIPT", newScript);
rumpelWalletFactory.setParam("SAFE_SINGLETON", newSingleton);
rumpelWalletFactory.setParam("PROXY_FACTORY", newProxyFactory);
rumpelWalletFactory.setParam("COMPATIBILITY_FALLBACK", newCompatibilityFallback);
vm.stopPrank();

assertEq(rumpelWalletFactory.rumpelGuard(), newGuard);
assertEq(rumpelWalletFactory.rumpelModule(), newModule);
assertEq(rumpelWalletFactory.initializationScript(), newScript);
assertEq(rumpelWalletFactory.safeSingleton(), newSingleton);
assertEq(address(rumpelWalletFactory.proxyFactory()), newProxyFactory);
assertEq(rumpelWalletFactory.compatibilityFallback(), newCompatibilityFallback);
}

function testFuzz_createWalletOwners(uint256 ownersLength, uint256 threshold) public {
Expand Down Expand Up @@ -157,11 +160,13 @@ contract RumpelWalletTest is Test {
address(0)
);

vm.startPrank(alice);
uint256 saltNonce = 0; // First wallet for this sender
address expectedAddress = rumpelWalletFactory.precomputeAddress(initializer, saltNonce);
address expectedAddress = rumpelWalletFactory.precomputeAddress(initializer, alice, saltNonce);

// Create the wallet
address actualAddress = rumpelWalletFactory.createWallet(owners, 1, initCalls);
vm.stopPrank();

// Check if the actual address matches the expected address
assertEq(actualAddress, expectedAddress, "Actual address does not match expected address");
Expand Down Expand Up @@ -522,7 +527,6 @@ contract RumpelWalletTest is Test {
safe: safe,
to: address(mockToken),
data: abi.encodeCall(ERC20.transfer, (RUMPEL_VAULT, 1.1e18)),
value: 0,
operation: Enum.Operation.Call
});

Expand All @@ -548,7 +552,6 @@ contract RumpelWalletTest is Test {
safe: safe,
to: address(mockToken),
data: abi.encodeCall(ERC20.transfer, (RUMPEL_VAULT, 1.1e18)),
value: 0,
operation: Enum.Operation.Call
});
rumpelModule.exec(calls);
Expand All @@ -574,7 +577,6 @@ contract RumpelWalletTest is Test {
safe: safe,
to: address(rumpelModule.signMessageLib()),
data: abi.encodeCall(ISignMessageLib.signMessage, (abi.encode(keccak256(message)))),
value: 0,
operation: Enum.Operation.DelegateCall
});
rumpelModule.exec(calls);
Expand Down Expand Up @@ -618,7 +620,6 @@ contract RumpelWalletTest is Test {
safe: safe,
to: address(mockToken),
data: abi.encodeCall(ERC20.transfer, (RUMPEL_VAULT, 1e18)),
value: 0,
operation: Enum.Operation.Call
});
rumpelModule.exec(calls);
Expand Down Expand Up @@ -646,7 +647,6 @@ contract RumpelWalletTest is Test {
safe: safe,
to: address(safe),
data: abi.encodeCall(ISafe.enableModule, (address(newRumpelModule))),
value: 0,
operation: Enum.Operation.Call
});
rumpelModule.exec(calls);
Expand Down