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: various bugs/missing features #7

Merged
merged 29 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a8d25f7
feat: make storage 4337 compliant
kopy-kat Jun 27, 2024
0506673
chore: renaming initializeAccount
zeroknots Jun 27, 2024
0f89432
feat: testing launchpad for 4337 compliance
zeroknots Jun 27, 2024
e7151ea
feat: adding launchpad function to allow existing safes to use launch…
zeroknots Jun 27, 2024
4f6daa3
feat: prototype implementation to allow safe checknsignature signers
zeroknots Jun 27, 2024
349ff72
fixed bug in validation
zeroknots Jun 28, 2024
128bf6a
wip
zeroknots Jun 28, 2024
3cac556
WIPip
zeroknots Jun 28, 2024
67cd00c
feat: all tests passing
kopy-kat Jun 28, 2024
7a66b3b
feature: clean up safe owner verification in launchpad
kopy-kat Jun 29, 2024
5092f78
feature: add existing safe test
kopy-kat Jun 29, 2024
8df99dd
feat: add support viewer contract
kopy-kat Jun 29, 2024
80a6c7a
chore: add deployments
kopy-kat Jun 29, 2024
b4ced92
chore: update supportviewer
kopy-kat Jun 30, 2024
ec0ebdf
Merge pull request #8 from rhinestonewtf/feature/safe-owner-cleanup
kopy-kat Jul 1, 2024
ca2d1a1
Merge pull request #9 from rhinestonewtf/feature/safe-owner-launchpad
kopy-kat Jul 1, 2024
8a1bde5
fix: tests
kopy-kat Jul 1, 2024
4573126
fix: abstract contracts
kopy-kat Jul 1, 2024
3dc8fdb
fix: linting
kopy-kat Jul 1, 2024
ca4ce07
chore: internal review
zeroknots Jul 1, 2024
dd2b4c5
rm: broadcast
zeroknots Jul 1, 2024
3c57ecd
feat: add safe as validator module addr
zeroknots Jul 1, 2024
45ccd05
chore: update lock
kopy-kat Jul 1, 2024
d961421
fix: relative imports
kopy-kat Jul 1, 2024
9bf62e7
fix: typo
kopy-kat Jul 5, 2024
065da36
fix: remove unused using for
kopy-kat Jul 5, 2024
1d25d2d
fix: update checknsignatures to latest
kopy-kat Jul 8, 2024
1a08bda
feat: add audit report
kopy-kat Jul 8, 2024
bedaf2f
Merge pull request #11 from rhinestonewtf/fix/final-remediations
kopy-kat Jul 8, 2024
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
Prev Previous commit
Next Next commit
WIPip
  • Loading branch information
zeroknots committed Jun 28, 2024
commit 3cac556299a455a93aacb2d335d8855beebfca31
11 changes: 8 additions & 3 deletions src/Safe7579Launchpad.sol
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ contract Safe7579Launchpad is IAccount, SafeStorage, ISafeOp {
msg.sender // ERC2771 access control
)
);

console2.logBytes(userOp.signature);
// ensure that the call was successful
if (!success) revert InvalidUserOperationData();

Expand All @@ -238,6 +240,7 @@ contract Safe7579Launchpad is IAccount, SafeStorage, ISafeOp {
validAfter: validAfter
});
} else {
console2.log("hash valid");
validationData = _packValidationData({
sigFailed: false,
validUntil: validUntil,
Expand Down Expand Up @@ -280,6 +283,7 @@ contract Safe7579Launchpad is IAccount, SafeStorage, ISafeOp {
}

function _isValidSafeSigners(
ISafe7579 safe7579,
bytes32 userOpHash,
PackedUserOperation calldata userOp
)
Expand All @@ -290,9 +294,10 @@ contract Safe7579Launchpad is IAccount, SafeStorage, ISafeOp {
bytes memory operationData;
bytes calldata signatures;

(operationData, validAfter, validUntil, signatures) = _getSafeOp(userOp);
(operationData, validAfter, validUntil, signatures) = safe7579.getSafeOp(userOp);

bytes32 _hash = keccak256(operationData);
console2.logBytes32(_hash);

InitData memory safeSetupCallData = abi.decode(userOp.callData[4:], (InitData));
address[] memory signers =
Expand All @@ -304,7 +309,7 @@ contract Safe7579Launchpad is IAccount, SafeStorage, ISafeOp {
owners.uniquifySorted();

uint256 length = owners.length;
console2.log("owners", owners.length, safeSetupCallData.threshold);
console2.log("owners", owners.length, safeSetupCallData.threshold, signers[0]);

uint256 validSigs;
for (uint256 i; i < length; i++) {
Expand Down Expand Up @@ -450,7 +455,7 @@ contract Safe7579Launchpad is IAccount, SafeStorage, ISafeOp {
* @return signatures The Safe owner signatures extracted from the user operation.
*/
function _getSafeOp(PackedUserOperation calldata userOp)
internal
public
view
returns (
bytes memory operationData,
Expand Down
86 changes: 75 additions & 11 deletions test/LaunchpadSafeSigner.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
pragma solidity ^0.8.23;

import "forge-std/Test.sol";
import { ISafeOp, SAFE_OP_TYPEHASH } from "src/interfaces/ISafeOp.sol";
import { UserOperationLib } from "@ERC4337/account-abstraction/contracts/core/UserOperationLib.sol";
import { Safe7579 } from "src/Safe7579.sol";
import { ISafe7579 } from "src/ISafe7579.sol";
import { IERC7484 } from "src/interfaces/IERC7484.sol";
Expand Down Expand Up @@ -31,6 +33,7 @@ import { Simulator } from "@rhinestone/erc4337-validation/src/Simulator.sol";

contract LaunchpadSafeSignerBase is Test {
using Simulator for PackedUserOperation; // or UserOperation
using UserOperationLib for PackedUserOperation;

Safe7579 safe7579;
Safe singleton;
Expand Down Expand Up @@ -134,18 +137,28 @@ contract LaunchpadSafeSignerBase is Test {
userOp.sender = predict;
assertEq(userOp.sender, predict);

bytes32 userOpHash = entrypoint.getUserOpHash(userOp);
bytes memory signatures;
uint8 v;
bytes32 r;
bytes32 s;
(v, r, s) = vm.sign(signer1.key, userOpHash);
address signer = address(uint160(uint256(r)));
signatures = abi.encodePacked(r, s, v);
(v, r, s) = vm.sign(signer2.key, userOpHash);
signatures = abi.encodePacked(signatures, abi.encodePacked(r, s, v));
uint48 validAfter = 0;
uint48 validUntil = type(uint48).max;

userOp.signature = signatures;
userOp.signature =
abi.encodePacked(validAfter, validUntil, hex"4141414141414141414141414141414141");

(bytes memory operationData,,,) = launchpad._getSafeOp(userOp);
bytes32 opHash = keccak256(operationData);
console2.logBytes32(opHash);

bytes memory sig = signHash(signer1.key, opHash);

userOp.signature = abi.encodePacked(validAfter, validUntil, sig);

(
bytes memory _operationData,
uint48 _validAfter,
uint48 _validUntil,
bytes memory _signatures
) = launchpad._getSafeOp(userOp);

assertEq(opHash, keccak256(_operationData));

PackedUserOperation[] memory userOps = new PackedUserOperation[](1);
userOps[0] = userOp;
Expand Down Expand Up @@ -200,4 +213,55 @@ contract LaunchpadSafeSignerBase is Test {
signature: abi.encodePacked(hex"41414141")
});
}

function signHash(uint256 privKey, bytes32 digest) internal returns (bytes memory) {
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privKey, digest);

// Sanity checks
address signer = ecrecover(digest, v, r, s);
require(signer == vm.addr(privKey), "Invalid signature");

return abi.encodePacked(r, s, v);
}

function getSafeOp(
PackedUserOperation calldata userOp,
uint48 validAfter,
uint48 validUntil
)
external
returns (bytes memory operationData)
{
ISafeOp.EncodedSafeOpStruct memory encodedSafeOp = ISafeOp.EncodedSafeOpStruct({
typeHash: SAFE_OP_TYPEHASH,
safe: msg.sender,
nonce: userOp.nonce,
initCodeHash: keccak256(userOp.initCode),
callDataHash: keccak256(userOp.callData),
callGasLimit: userOp.unpackCallGasLimit(),
verificationGasLimit: userOp.unpackVerificationGasLimit(),
preVerificationGas: userOp.preVerificationGas,
maxFeePerGas: userOp.unpackMaxFeePerGas(),
maxPriorityFeePerGas: userOp.unpackMaxPriorityFeePerGas(),
paymasterAndDataHash: keccak256(userOp.paymasterAndData),
validAfter: validAfter,
validUntil: validUntil,
entryPoint: 0x0000000071727De22E5E9d8BAf0edAc6f37da032
});

bytes32 safeOpStructHash;
// solhint-disable-next-line no-inline-assembly
assembly ("memory-safe") {
// Since the `encodedSafeOp` value's memory layout is identical to the result of
// `abi.encode`-ing the
// individual `SafeOp` fields, we can pass it directly to `keccak256`. Additionally,
// there are 14
// 32-byte fields to hash, for a length of `14 * 32 = 448` bytes.
safeOpStructHash := keccak256(encodedSafeOp, 448)
}

operationData = abi.encodePacked(
bytes1(0x19), bytes1(0x01), launchpad.domainSeparator(), safeOpStructHash
);
}
}