-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed8bdb7
commit b0bbeb4
Showing
5 changed files
with
162 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.9; | ||
|
||
import {MessageData} from "../../FrameVerifier.sol"; | ||
// import Strings | ||
|
||
import {UserOperation} from "./UserOperation.sol"; | ||
import {SharedVerifier} from "../SharedVerifier.sol"; | ||
|
||
contract Account { | ||
bytes32 public publicKey; | ||
string public baseUrl; | ||
SharedVerifier public sharedVerifier; | ||
uint256 public lastFrameTimstamp; | ||
|
||
struct FrameUserOpSignature { | ||
bytes32 signature_r; | ||
bytes32 signature_s; | ||
MessageData messageData; | ||
} | ||
|
||
function validateUserOp(UserOperation calldata userOp, bytes32 userOpHash, uint256 missingAccountFunds) | ||
external | ||
returns (uint256 validationData) | ||
{ | ||
FrameUserOpSignature memory frameStruct = abi.decode(userOp.signature, (FrameUserOpSignature)); | ||
string memory expectedUrl = string.concat(baseUrl, Strings.toString(block.chainId), ":", userOp.callData); | ||
frameStruct.messageData.frame_action_body.url = expectedUrl; | ||
|
||
if ( | ||
SharedVerifier.verifyMessageData( | ||
SharedVerifier.VerifyRequest( | ||
publicKey, frameStruct.signature_r, frameStruct.signature_s, frameStruct.messageData | ||
) | ||
) | ||
) { | ||
if (frameStruct.messageData.frame_action_body.timestamp < lastFrameTimstamp) { | ||
return 1; | ||
} | ||
lastFrameTimstamp = frameStruct.messageData.frame_action_body.timestamp; | ||
return 0; | ||
} | ||
|
||
return 1; | ||
|
||
// pay missing account funds | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.9; | ||
|
||
import {UserOperation} from "./UserOperation.sol"; | ||
import {SharedVerifier} from "../SharedVerifier.sol"; | ||
|
||
contract Paymaster { | ||
mapping(bytes32 => uint256) public castBalance; | ||
mapping(uint256 => uint256) public fidBalance; | ||
|
||
function validatePaymasterUserOp(UserOperation calldata userOp, bytes32 userOpHash, uint256 maxCost) | ||
external | ||
returns (bytes memory context, uint256 validationData) | ||
{} | ||
|
||
function postOp(PostOpMode mode, bytes calldata context, uint256 actualGasCost) external {} | ||
|
||
enum PostOpMode { | ||
opSucceeded, // user op succeeded | ||
opReverted, // user op reverted. still has to pay for gas. | ||
postOpReverted // user op succeeded, but caused postOp to revert | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
struct UserOperation { | ||
address sender; | ||
uint256 nonce; | ||
bytes initCode; | ||
bytes callData; | ||
uint256 callGasLimit; | ||
uint256 verificationGasLimit; | ||
uint256 preVerificationGas; | ||
uint256 maxFeePerGas; | ||
uint256 maxPriorityFeePerGas; | ||
bytes paymasterAndData; | ||
bytes signature; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.9; | ||
|
||
import {MessageData, FrameVerifier} from "../FrameVerifier.sol"; | ||
|
||
// To attempt to save gas verifying Frames in multiple contracts | ||
// we can use a shared verifier that saves the result | ||
contract SharedVerifier { | ||
mapping(bytes32 => bool) public isValid; | ||
|
||
struct VerifyRequest { | ||
bytes32 public_key; | ||
bytes32 signature_r; | ||
bytes32 signature_s; | ||
MessageData messageData; | ||
} | ||
|
||
function verifyMessageData(VerifyRequest memory request) external returns (bool) { | ||
bytes32 hash = keccak256(abi.encode(request.messageData)); | ||
if (isValid[hash]) { | ||
return true; | ||
} | ||
|
||
bool valid = FrameVerifier.verifyMessageData( | ||
request.public_key, request.signature_r, request.signature_s, request.messageData | ||
); | ||
|
||
if (valid) { | ||
isValid[hash] = true; | ||
} | ||
|
||
return valid; | ||
} | ||
} |