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 6 commits
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
85 changes: 85 additions & 0 deletions broadcast/Deploy.s.sol/11155111/run-1719675459.json

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

226 changes: 226 additions & 0 deletions broadcast/Deploy.s.sol/84532/run-1719683556.json

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions broadcast/Deploy.s.sol/84532/run-1719683922.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"transactions": [
{
"hash": "0xa8ebe0410fe6361288b61c3a6c42538defdc9a995179dc67fbfb3a9a14216a6b",
"transactionType": "CREATE2",
"contractName": null,
"contractAddress": "0xbdf6ae24b783a7ba2a0d874ef49cb0d2d7f619c6",
"function": null,
"arguments": null,
"transaction": {
"from": "0x8749313f626b100b822d573c71dfffdaca383032",
"to": "0x4e59b44847b379578588920ca78fbf26c0b4956c",
"gas": "0x56505",
"value": "0x0",
"input": "0x00000000000000000000000000000000000000000000000000000000000000006080604052348015600f57600080fd5b506103a98061001f6000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c80636d61fe70146100675780638a91b0e314610067578063970032031461007b578063d60b347f146100a1578063ecd05961146100c5578063f551e2ee146100d9575b600080fd5b61007961007536600461018c565b5050565b005b61008e6100893660046101ce565b610110565b6040519081526020015b60405180910390f35b6100b56100af366004610235565b50600090565b6040519015158152602001610098565b6100b56100d3366004610257565b60011490565b6100f76100e7366004610270565b630b135d3f60e11b949350505050565b6040516001600160e01b03199091168152602001610098565b60008061012060608501856102ca565b61012f91600491600091610311565b6101389161033b565b506000949350505050565b60008083601f84011261015557600080fd5b50813567ffffffffffffffff81111561016d57600080fd5b60208301915083602082850101111561018557600080fd5b9250929050565b6000806020838503121561019f57600080fd5b823567ffffffffffffffff8111156101b657600080fd5b6101c285828601610143565b90969095509350505050565b600080604083850312156101e157600080fd5b823567ffffffffffffffff8111156101f857600080fd5b8301610120818603121561020b57600080fd5b946020939093013593505050565b80356001600160a01b038116811461023057600080fd5b919050565b60006020828403121561024757600080fd5b61025082610219565b9392505050565b60006020828403121561026957600080fd5b5035919050565b6000806000806060858703121561028657600080fd5b61028f85610219565b935060208501359250604085013567ffffffffffffffff8111156102b257600080fd5b6102be87828801610143565b95989497509550505050565b6000808335601e198436030181126102e157600080fd5b83018035915067ffffffffffffffff8211156102fc57600080fd5b60200191503681900382131561018557600080fd5b6000808585111561032157600080fd5b8386111561032e57600080fd5b5050820193919092039150565b80356001600160e01b0319811690600484101561036c576001600160e01b0319600485900360031b81901b82161691505b509291505056fea26469706673582212203922fd7f4e81546b2a84c58acdf6f1138f1a63c796cfbbc5424678f60d7c809264736f6c634300081a0033",
"nonce": "0x1c",
"chainId": "0x14a34"
},
"additionalContracts": [],
"isFixedGasLimit": false
}
],
"receipts": [
{
"status": "0x1",
"cumulativeGasUsed": "0x115410",
"logs": [],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"type": "0x2",
"transactionHash": "0xa8ebe0410fe6361288b61c3a6c42538defdc9a995179dc67fbfb3a9a14216a6b",
"transactionIndex": "0x6",
"blockHash": "0x0911abf7308fe87da8863db466c295bb39fe4128101fdf6749583a6e4aa98a20",
"blockNumber": "0xb6762d",
"gasUsed": "0x3e814",
"effectiveGasPrice": "0xf43fa",
"from": "0x8749313f626b100b822d573c71dfffdaca383032",
"to": "0x4e59b44847b379578588920ca78fbf26c0b4956c",
"contractAddress": "0xbdf6ae24b783a7ba2a0d874ef49cb0d2d7f619c6",
"l1BaseFeeScalar": "0x44d",
"l1BlobBaseFee": "0x4",
"l1BlobBaseFeeScalar": "0xa118b",
"l1Fee": "0x3ec33a1588",
"l1GasPrice": "0x5168d5de5",
"l1GasUsed": "0x2bc3"
}
],
"libraries": [],
"pending": [],
"returns": {},
"timestamp": 1719683922,
"chain": 84532,
"commit": "5092f78"
}
59 changes: 59 additions & 0 deletions broadcast/Deploy.s.sol/84532/run-1719685138.json

Large diffs are not rendered by default.

56 changes: 56 additions & 0 deletions broadcast/Deploy.s.sol/84532/run-1719690025.json

Large diffs are not rendered by default.

56 changes: 56 additions & 0 deletions broadcast/Deploy.s.sol/84532/run-latest.json

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
import { Safe7579 } from "src/Safe7579.sol";
import { Safe7579Launchpad } from "src/Safe7579Launchpad.sol";
import { IERC7484 } from "src/interfaces/IERC7484.sol";
import { MockRegistry } from "test/mocks/MockRegistry.sol";

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

View workflow job for this annotation

GitHub Actions / lint / forge-lint

imported name MockRegistry is not used
import { Safe } from "@safe-global/safe-contracts/contracts/Safe.sol";

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

View workflow job for this annotation

GitHub Actions / lint / forge-lint

imported name Safe is not used
import { SafeProxyFactory } from

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

View workflow job for this annotation

GitHub Actions / lint / forge-lint

imported name SafeProxyFactory is not used
"@safe-global/safe-contracts/contracts/proxies/SafeProxyFactory.sol";
import { MockValidator } from "test/mocks/MockValidator.sol";

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

View workflow job for this annotation

GitHub Actions / lint / forge-lint

imported name MockValidator is not used

/**
* @title Deploy
Expand All @@ -15,11 +20,17 @@
bytes32 salt = bytes32(uint256(0));

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

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

// new Safe7579{ salt: salt }();
// new MockValidator{ salt: salt }();

// new Safe{ salt: salt }();
// new SafeProxyFactory{ salt: salt }();

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

vm.stopBroadcast();
Expand Down
12 changes: 8 additions & 4 deletions src/ISafe7579.sol
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,18 @@ interface ISafe7579 is IERC7579Account {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* Query Misc */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
function supportsExecutionMode(ModeCode encodedMode) external pure returns (bool supported);
function supportsModule(uint256 moduleTypeId) external pure returns (bool);
function accountId() external view returns (string memory accountImplementationId);

// todo: add back in
// function supportsExecutionMode(ModeCode encodedMode) external pure returns (bool supported);
// function supportsModule(uint256 moduleTypeId) external pure returns (bool);
// function accountId() external view returns (string memory accountImplementationId);

/**
* Domain Separator for EIP-712.
*/
function domainSeparator() external view returns (bytes32);
// TODO: is this required?
// function domainSeparator() external view returns (bytes32);

/**
* Safe7579 is using validator selection encoding in the userop nonce.
* to make it easier for SDKs / devs to integrate, this function can be
Expand Down
137 changes: 4 additions & 133 deletions src/Safe7579.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import { ModuleInstallUtil } from "./utils/DCUtil.sol";
import { AccessControl } from "./core/AccessControl.sol";
import { Initializer } from "./core/Initializer.sol";
import { ISafeOp, SAFE_OP_TYPEHASH } from "./interfaces/ISafeOp.sol";
import { SafeOp } from "./core/SafeOp.sol";
import { ISafe } from "./interfaces/ISafe.sol";
import { ISafe7579 } from "./ISafe7579.sol";
import {
Expand All @@ -34,6 +34,7 @@ import {
import { _packValidationData } from "@ERC4337/account-abstraction/contracts/core/Helpers.sol";
import { IEntryPoint } from "@ERC4337/account-abstraction/contracts/interfaces/IEntryPoint.sol";
import { IERC1271 } from "./interfaces/IERC1271.sol";
import { SupportViewer } from "./core/SupportViewer.sol";

uint256 constant MULTITYPE_MODULE = 0;

Expand All @@ -50,7 +51,7 @@ uint256 constant MULTITYPE_MODULE = 0;
* event emissions to be done via the SafeProxy as msg.sender using Safe's
* "executeTransactionFromModule" features.
*/
contract Safe7579 is ISafe7579, ISafeOp, AccessControl, Initializer {
contract Safe7579 is ISafe7579, SafeOp, SupportViewer, AccessControl, Initializer {
using UserOperationLib for PackedUserOperation;
using ExecutionLib for bytes;

Expand Down Expand Up @@ -306,7 +307,7 @@ contract Safe7579 is ISafe7579, ISafeOp, AccessControl, Initializer {
uint48 validAfter,
uint48 validUntil,
bytes calldata signatures
) = _getSafeOp(userOp);
) = _getSafeOp(userOp, entryPoint());
try ISafe((msg.sender)).checkSignatures(keccak256(operationData), operationData, signatures)
{
// The timestamps are validated by the entry point,
Expand Down Expand Up @@ -460,43 +461,6 @@ contract Safe7579 is ISafe7579, ISafeOp, AccessControl, Initializer {
});
}

/**
* @inheritdoc ISafe7579
*/
function supportsExecutionMode(ModeCode encodedMode)
external
pure
override
returns (bool supported)
{
CallType callType;
ExecType execType;
// solhint-disable-next-line no-inline-assembly
assembly {
callType := encodedMode
execType := shl(8, encodedMode)
}
if (callType == CALLTYPE_BATCH) supported = true;
else if (callType == CALLTYPE_SINGLE) supported = true;
else if (callType == CALLTYPE_DELEGATECALL) supported = true;
else return false;

if (supported && execType == EXECTYPE_DEFAULT) return supported;
else if (supported && execType == EXECTYPE_TRY) return supported;
else return false;
}

/**
* @inheritdoc ISafe7579
*/
function supportsModule(uint256 moduleTypeId) external pure override returns (bool) {
if (moduleTypeId == MODULE_TYPE_VALIDATOR) return true;
else if (moduleTypeId == MODULE_TYPE_EXECUTOR) return true;
else if (moduleTypeId == MODULE_TYPE_FALLBACK) return true;
else if (moduleTypeId == MODULE_TYPE_HOOK) return true;
else return false;
}

/**
* @inheritdoc ISafe7579
*/
Expand All @@ -522,99 +486,6 @@ contract Safe7579 is ISafe7579, ISafeOp, AccessControl, Initializer {
}
}

/**
* @inheritdoc ISafe7579
*/
function accountId() external view returns (string memory accountImplementationId) {
string memory safeVersion = ISafe(msg.sender).VERSION();
return string(abi.encodePacked("safe-", safeVersion, ".erc7579.v0.0.1"));
}

/**
* @dev Decodes an ERC-4337 user operation into a Safe operation.
* @param userOp The ERC-4337 user operation.
* @return operationData Encoded EIP-712 Safe operation data bytes used for signature
* verification.
* @return validAfter The timestamp the user operation is valid from.
* @return validUntil The timestamp the user operation is valid until.
* @return signatures The Safe owner signatures extracted from the user operation.
*/
function _getSafeOp(PackedUserOperation calldata userOp)
internal
view
returns (
bytes memory operationData,
uint48 validAfter,
uint48 validUntil,
bytes calldata signatures
)
{
// Extract additional Safe operation fields from the user operation signature which is
// encoded as:
// `abi.encodePacked(validAfter, validUntil, signatures)`
{
bytes calldata sig = userOp.signature;
validAfter = uint48(bytes6(sig[0:6]));
validUntil = uint48(bytes6(sig[6:12]));
signatures = sig[12:];
}

// It is important that **all** user operation fields are represented in the `SafeOp` data
// somehow, to prevent
// user operations from being submitted that do not fully respect the user preferences. The
// only exception is
// the `signature` bytes. Note that even `initCode` needs to be represented in the operation
// data, otherwise
// it can be replaced with a more expensive initialization that would charge the user
// additional fees.
{
// In order to work around Solidity "stack too deep" errors related to too many stack
// variables, manually
// encode the `SafeOp` fields into a memory `struct` for computing the EIP-712
// struct-hash. This works
// because the `EncodedSafeOpStruct` struct has no "dynamic" fields so its memory layout
// is identical to the
// result of `abi.encode`-ing the individual fields.
EncodedSafeOpStruct memory encodedSafeOp = EncodedSafeOpStruct({
typeHash: SAFE_OP_TYPEHASH,
safe: userOp.sender,
nonce: userOp.nonce,
initCodeHash: keccak256(userOp.initCode),
callDataHash: keccak256(userOp.callData),
verificationGasLimit: uint128(userOp.unpackVerificationGasLimit()),
callGasLimit: uint128(userOp.unpackCallGasLimit()),
preVerificationGas: userOp.preVerificationGas,
maxPriorityFeePerGas: uint128(userOp.unpackMaxPriorityFeePerGas()),
maxFeePerGas: uint128(userOp.unpackMaxFeePerGas()),
paymasterAndDataHash: keccak256(userOp.paymasterAndData),
validAfter: validAfter,
validUntil: validUntil,
entryPoint: entryPoint()
});

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), domainSeparator(), safeOpStructHash);
}
}

/**
* @inheritdoc ISafe7579
*/
function domainSeparator() public view returns (bytes32) {
return keccak256(abi.encode(DOMAIN_SEPARATOR_TYPEHASH, block.chainid, this));
}

/**
* @inheritdoc ISafe7579
*/
Expand Down
Loading
Loading