Skip to content

Commit

Permalink
Safe4337Mock: Remove signature check function inlining and call the…
Browse files Browse the repository at this point in the history
… function via call instead (#450)

In #446, I inlined the
signature check function because we didn't want it to revert in
unsuccessful cases. I inlined it because the `try/catch` statement
didn't work for internal function calls. Little did I know that I could
do `this.f()` and that would use the `CALL` opcode instead of `JUMP`,
making the `try/catch` statement possible

More info:
https://www.perplexity.ai/search/if-i-call-1VYIfl5eQEWvJ302U7wVOA#0
  • Loading branch information
mmv08 authored Jun 28, 2024
1 parent b4a0b60 commit 8b85c79
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions modules/4337/contracts/test/SafeMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,12 @@ contract Safe4337Mock is SafeMock, IAccount {
function _validateSignatures(PackedUserOperation calldata userOp) internal view returns (uint256 validationData) {
(bytes memory operationData, uint48 validAfter, uint48 validUntil, bytes calldata signatures) = _getSafeOp(userOp);

bytes32 dataHash = keccak256(operationData);
uint8 v;
bytes32 r;
bytes32 s;
(v, r, s) = _signatureSplit(signatures);
bool validSignature = owner == ecrecover(keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", dataHash)), v - 4, r, s);

validationData = _packValidationData(!validSignature, validUntil, validAfter);
try this.checkSignatures(keccak256(operationData), operationData, signatures) {
// The timestamps are validated by the entry point, therefore we will not check them again
validationData = _packValidationData(false, validUntil, validAfter);
} catch {
validationData = _packValidationData(true, validUntil, validAfter);
}
}

/**
Expand Down

0 comments on commit 8b85c79

Please sign in to comment.