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
feat: all tests passing
  • Loading branch information
kopy-kat committed Jun 28, 2024
commit 67cd00c5b2ff4a25de5a7653d71efc55e58ecdb6
125 changes: 125 additions & 0 deletions broadcast/Deploy.s.sol/11155111/run-1719525755.json

Large diffs are not rendered by default.

91 changes: 91 additions & 0 deletions broadcast/Deploy.s.sol/11155111/run-1719529914.json

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions broadcast/Deploy.s.sol/11155111/run-1719530935.json

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions broadcast/Deploy.s.sol/11155111/run-1719596986.json

Large diffs are not rendered by default.

73 changes: 16 additions & 57 deletions broadcast/Deploy.s.sol/11155111/run-latest.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.19;

import { Script } from "forge-std/Script.sol";
import { Safe7579 } from "src/Safe7579.sol";

Check warning on line 5 in script/Deploy.s.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

imported name Safe7579 is not used
import { Safe7579Launchpad } from "src/Safe7579Launchpad.sol";
import { IERC7484 } from "src/interfaces/IERC7484.sol";

Expand All @@ -15,11 +15,11 @@
bytes32 salt = bytes32(uint256(0));

address entryPoint = address(0x0000000071727De22E5E9d8BAf0edAc6f37da032);
IERC7484 registry = IERC7484(0xe0cde9239d16bEf05e62Bbf7aA93e420f464c826);
IERC7484 registry = IERC7484(0xc449A54310506688E1239D1aB2A5E5644679a1D6);

vm.startBroadcast(vm.envUint("PK"));

new Safe7579{ salt: salt }();
// new Safe7579{ salt: salt }();
new Safe7579Launchpad{ salt: salt }(entryPoint, registry);

vm.stopBroadcast();
Expand Down
10 changes: 5 additions & 5 deletions src/Safe7579.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
CallType,
ExecType,
ModeCode,
ModeLib,

Check warning on line 9 in src/Safe7579.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

imported name ModeLib is not used
EXECTYPE_DEFAULT,
EXECTYPE_TRY,
CALLTYPE_SINGLE,
Expand Down Expand Up @@ -348,7 +348,7 @@
)
);

require(safe.signedMessages(messageHash) != 0, "Hash not approved");

Check warning on line 351 in src/Safe7579.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

GC: Use Custom Errors instead of require statements
// return magic value
return IERC1271.isValidSignature.selector;
}
Expand Down Expand Up @@ -577,15 +577,15 @@
// result of `abi.encode`-ing the individual fields.
EncodedSafeOpStruct memory encodedSafeOp = EncodedSafeOpStruct({
typeHash: SAFE_OP_TYPEHASH,
safe: msg.sender,
safe: userOp.sender,
nonce: userOp.nonce,
initCodeHash: keccak256(userOp.initCode),
callDataHash: keccak256(userOp.callData),
callGasLimit: userOp.unpackCallGasLimit(),
verificationGasLimit: userOp.unpackVerificationGasLimit(),
verificationGasLimit: uint128(userOp.unpackVerificationGasLimit()),
callGasLimit: uint128(userOp.unpackCallGasLimit()),
preVerificationGas: userOp.preVerificationGas,
maxFeePerGas: userOp.unpackMaxFeePerGas(),
maxPriorityFeePerGas: userOp.unpackMaxPriorityFeePerGas(),
maxPriorityFeePerGas: uint128(userOp.unpackMaxPriorityFeePerGas()),
maxFeePerGas: uint128(userOp.unpackMaxFeePerGas()),
paymasterAndDataHash: keccak256(userOp.paymasterAndData),
validAfter: validAfter,
validUntil: validUntil,
Expand Down
44 changes: 19 additions & 25 deletions src/Safe7579Launchpad.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.20;

import { _packValidationData } from "@ERC4337/account-abstraction/contracts/core/Helpers.sol";
import "./interfaces/ISafeOp.sol";

Check warning on line 5 in src/Safe7579Launchpad.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

global import of path ./interfaces/ISafeOp.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)

import {
IAccount,
Expand All @@ -22,7 +22,7 @@
import { MODULE_TYPE_VALIDATOR } from "erc7579/interfaces/IERC7579Module.sol";
import { CheckSignatures } from "@rhinestone/checknsignatures/src/CheckNSignatures.sol";
import { LibSort } from "solady/utils/LibSort.sol";
import "forge-std/console2.sol";

Check failure on line 25 in src/Safe7579Launchpad.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

Unexpected import of console file

/**
* Launchpad to deploy a Safe account and connect the Safe7579 adapter.
Expand Down Expand Up @@ -219,34 +219,31 @@
// the launchpadValidator function
(bool success,) = address(initData.safe7579).call(
abi.encodePacked(
abi.encodeCall(ISafe7579.initializeAccountWithValidators, (initData.validators)), // ISafe7579.launchpadValidators

Check failure on line 222 in src/Safe7579Launchpad.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

Line length must be no more than 123 but current length is 130
msg.sender // ERC2771 access control
)
);

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

// to support validation with the safe native signers, we allow to set the validator module
// to address(0)
if (validator == address(0)) {
(bool validSig, uint48 validAfter, uint48 validUntil) =
_isValidSafeSigners(userOpHash, userOp);
if (!validSig) {
return _packValidationData({
sigFailed: !validSig,
validUntil: validUntil,
validAfter: validAfter
});
} else {
console2.log("hash valid");
validationData = _packValidationData({
sigFailed: false,
validUntil: validUntil,
validAfter: validAfter
});
_isValidSafeSigners(initData.safe7579, userOpHash, userOp);

if (missingAccountFunds > 0) {
// solhint-disable-next-line no-inline-assembly
assembly ("memory-safe") {
pop(call(gas(), caller(), missingAccountFunds, 0, 0, 0, 0))
}
}
return _packValidationData({
sigFailed: !validSig,
validUntil: validUntil,
validAfter: validAfter
});
}
// if the validator module is non address(0), we validate the userOp with the validator
// module
Expand Down Expand Up @@ -294,22 +291,19 @@
bytes memory operationData;
bytes calldata signatures;

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

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

InitData memory safeSetupCallData = abi.decode(userOp.callData[4:], (InitData));
address[] memory signers =
_hash.recoverNSignatures(userOp.signature, safeSetupCallData.threshold);
address[] memory signers = _hash.recoverNSignatures(signatures, safeSetupCallData.threshold);
signers.insertionSort();

address[] memory owners = safeSetupCallData.owners;
owners.insertionSort();
owners.uniquifySorted();

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

uint256 validSigs;
for (uint256 i; i < length; i++) {
Expand Down Expand Up @@ -492,15 +486,15 @@
// result of `abi.encode`-ing the individual fields.
EncodedSafeOpStruct memory encodedSafeOp = EncodedSafeOpStruct({
typeHash: SAFE_OP_TYPEHASH,
safe: msg.sender,
safe: userOp.sender,
nonce: userOp.nonce,
initCodeHash: keccak256(userOp.initCode),
callDataHash: keccak256(userOp.callData),
callGasLimit: userOp.unpackCallGasLimit(),
verificationGasLimit: userOp.unpackVerificationGasLimit(),
verificationGasLimit: uint128(userOp.unpackVerificationGasLimit()),
callGasLimit: uint128(userOp.unpackCallGasLimit()),
preVerificationGas: userOp.preVerificationGas,
maxFeePerGas: userOp.unpackMaxFeePerGas(),
maxPriorityFeePerGas: userOp.unpackMaxPriorityFeePerGas(),
maxPriorityFeePerGas: uint128(userOp.unpackMaxPriorityFeePerGas()),
maxFeePerGas: uint128(userOp.unpackMaxFeePerGas()),
paymasterAndDataHash: keccak256(userOp.paymasterAndData),
validAfter: validAfter,
validUntil: validUntil,
Expand Down
50 changes: 45 additions & 5 deletions src/interfaces/ISafeOp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,60 @@
pragma solidity ^0.8.23;

bytes32 constant SAFE_OP_TYPEHASH =
0x84aa190356f56b8c87825f54884392a9907c23ee0f8e1ea86336b763faf021bd;
0xc03dfc11d8b10bf9cf703d558958c8c42777f785d998c62060d85a4f0ef6ea7f;

interface ISafeOp {
/**
* @notice The EIP-712 type-hash for a SafeOp, representing the structure of a User Operation
* for
* the Safe.
* {address} safe - The address of the safe on which the operation is performed.
* {uint256} nonce - A unique number associated with the user operation, preventing replay
* attacks
* by ensuring each operation is unique.
* {bytes} initCode - The packed encoding of a factory address and its factory-specific data
* for
* creating a new Safe account.
* {bytes} callData - The bytes representing the data of the function call to be executed.
* {uint128} verificationGasLimit - The maximum amount of gas allowed for the verification
* process.
* {uint128} callGasLimit - The maximum amount of gas allowed for executing the function call.
* {uint256} preVerificationGas - The amount of gas allocated for pre-verification steps before
* executing the main operation.
* {uint128} maxPriorityFeePerGas - The maximum priority fee per gas that the user is willing
* to
* pay for the transaction.
* {uint128} maxFeePerGas - The maximum fee per gas that the user is willing to pay for the
* transaction.
* {bytes} paymasterAndData - The packed encoding of a paymaster address and its
* paymaster-specific
* data for sponsoring the user operation.
* {uint48} validAfter - A timestamp representing from when the user operation is valid.
* {uint48} validUntil - A timestamp representing until when the user operation is valid, or 0
* to
* indicated "forever".
* {address} entryPoint - The address of the entry point that will execute the user operation.
* @dev When validating the user operation, the signature timestamps are pre-pended to the
* signature
* bytes. Equal to:
* keccak256(
* "SafeOp(address safe,uint256 nonce,bytes initCode,bytes callData,uint128
* verificationGasLimit,uint128 callGasLimit,uint256 preVerificationGas,uint128
* maxPriorityFeePerGas,uint128 maxFeePerGas,bytes paymasterAndData,uint48 validAfter,uint48
* validUntil,address entryPoint)"
* ) = 0xc03dfc11d8b10bf9cf703d558958c8c42777f785d998c62060d85a4f0ef6ea7f
*/
struct EncodedSafeOpStruct {
bytes32 typeHash;
address safe;
uint256 nonce;
bytes32 initCodeHash;
bytes32 callDataHash;
uint256 callGasLimit;
uint256 verificationGasLimit;
uint128 verificationGasLimit;
uint128 callGasLimit;
uint256 preVerificationGas;
uint256 maxFeePerGas;
uint256 maxPriorityFeePerGas;
uint128 maxPriorityFeePerGas;
uint128 maxFeePerGas;
bytes32 paymasterAndDataHash;
uint48 validAfter;
uint48 validUntil;
Expand Down
74 changes: 65 additions & 9 deletions test/LaunchpadSafeSigner.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ contract LaunchpadSafeSignerBase is Test {
userOp.signature =
abi.encodePacked(validAfter, validUntil, hex"4141414141414141414141414141414141");

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

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

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

Expand All @@ -158,7 +158,7 @@ contract LaunchpadSafeSignerBase is Test {
bytes memory _signatures
) = launchpad._getSafeOp(userOp);

assertEq(opHash, keccak256(_operationData));
// assertEq(opHash, keccak256(_operationData));

PackedUserOperation[] memory userOps = new PackedUserOperation[](1);
userOps[0] = userOp;
Expand Down Expand Up @@ -234,15 +234,15 @@ contract LaunchpadSafeSignerBase is Test {
{
ISafeOp.EncodedSafeOpStruct memory encodedSafeOp = ISafeOp.EncodedSafeOpStruct({
typeHash: SAFE_OP_TYPEHASH,
safe: msg.sender,
safe: userOp.sender,
nonce: userOp.nonce,
initCodeHash: keccak256(userOp.initCode),
callDataHash: keccak256(userOp.callData),
callGasLimit: userOp.unpackCallGasLimit(),
verificationGasLimit: userOp.unpackVerificationGasLimit(),
verificationGasLimit: uint128(userOp.unpackVerificationGasLimit()),
callGasLimit: uint128(userOp.unpackCallGasLimit()),
preVerificationGas: userOp.preVerificationGas,
maxFeePerGas: userOp.unpackMaxFeePerGas(),
maxPriorityFeePerGas: userOp.unpackMaxPriorityFeePerGas(),
maxPriorityFeePerGas: uint128(userOp.unpackMaxPriorityFeePerGas()),
maxFeePerGas: uint128(userOp.unpackMaxFeePerGas()),
paymasterAndDataHash: keccak256(userOp.paymasterAndData),
validAfter: validAfter,
validUntil: validUntil,
Expand All @@ -260,8 +260,64 @@ contract LaunchpadSafeSignerBase is Test {
safeOpStructHash := keccak256(encodedSafeOp, 448)
}

uint256 id;
// solhint-disable-next-line no-inline-assembly
assembly {
id := chainid()
}

operationData = abi.encodePacked(
bytes1(0x19), bytes1(0x01), launchpad.domainSeparator(), safeOpStructHash
bytes1(0x19),
bytes1(0x01),
keccak256(
abi.encode(
0x47e79534a245952e8b16893a336b85a3d9ea9fa8c573f3d803afb92a79469218,
id,
userOp.sender
)
),
safeOpStructHash
);
}

// 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
// );
// }
}
Loading
Loading