This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from getwax/anon-aadhaar
Use correct verfier for AnonAadhaar
- Loading branch information
Showing
15 changed files
with
704 additions
and
431 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,3 @@ | ||
# Paymaster | ||
|
||
These are exemplary paymaster contracts. The SponsorEverythingPaymaster contract and its test can serve as references when developing more complex paymasters for your specific use cases. |
35 changes: 35 additions & 0 deletions
35
packages/plugins/src/paymaster/SponsorEverythingPaymaster.sol
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,35 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.4 <0.9.0; | ||
|
||
import {IEntryPoint} from 'account-abstraction/interfaces/IEntryPoint.sol'; | ||
|
||
import {BasePaymaster} from 'account-abstraction/core/BasePaymaster.sol'; | ||
import {UserOperationLib} from 'account-abstraction/core/UserOperationLib.sol'; | ||
import {PackedUserOperation} from 'account-abstraction/interfaces/PackedUserOperation.sol'; | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
THIS CONTRACT IS STILL IN ACTIVE DEVELOPMENT. NOT FOR PRODUCTION USE | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
/// @title This paymaster sponsors everything. | ||
contract SponsorEverythingPaymaster is BasePaymaster { | ||
using UserOperationLib for PackedUserOperation; | ||
|
||
constructor(IEntryPoint _entryPoint) BasePaymaster(_entryPoint) {} | ||
|
||
/** | ||
* Validate a user operation. | ||
* @param userOp - The user operation. | ||
* @param userOpHash - The hash of the user operation. | ||
* @param maxCost - The maximum cost of the user operation. | ||
*/ | ||
function _validatePaymasterUserOp( | ||
PackedUserOperation calldata userOp, | ||
bytes32 userOpHash, | ||
uint256 maxCost | ||
) internal virtual override returns (bytes memory context, uint256 validationData) { | ||
// Validation logic comes here. | ||
// Approve everything. | ||
return ("", 0); | ||
} | ||
} |
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
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,5 @@ | ||
# Anon Aadhaar Contracts | ||
|
||
These contracts are copied from https://github.com/anon-aadhaar/anon-aadhaar/tree/main/packages/contracts @ `v2.2.0`. This has been done for 2 reasons: | ||
- `AnonAadhaarVerifier.sol` needed to be modified to use gas opcodes that work within the [validation cycle gas opcode limitations for ERC-4337 (OP-012)](https://eips.ethereum.org/EIPS/eip-7562#opcode-rules). | ||
- Using the `@anon-aadhaar/contracts` npm package's contract interfaces causes issues with Typechain generation in this project. |
13 changes: 13 additions & 0 deletions
13
packages/plugins/src/safe/utils/anonAadhaar/interfaces/IAnonAadhaar.sol
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,13 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.19; | ||
|
||
interface IAnonAadhaar { | ||
function verifyAnonAadhaarProof( | ||
uint nullifierSeed, | ||
uint nullifier, | ||
uint timestamp, | ||
uint signal, | ||
uint[4] memory revealArray, | ||
uint[8] memory groth16Proof | ||
) external view returns (bool); | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/plugins/src/safe/utils/anonAadhaar/interfaces/IAnonAadhaarGroth16Verifier.sol
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,11 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.19; | ||
|
||
interface IAnonAadhaarGroth16Verifier { | ||
function verifyProof( | ||
uint[2] calldata _pA, | ||
uint[2][2] calldata _pB, | ||
uint[2] calldata _pC, | ||
uint[9] calldata publicInputs | ||
) external view returns (bool); | ||
} |
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
110 changes: 110 additions & 0 deletions
110
packages/plugins/test/e2e/SafeSponsorEverythingPaymaster.test.ts
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,110 @@ | ||
import { expect } from "chai"; | ||
import { ethers } from "ethers"; | ||
import { | ||
SafeECDSAFactory__factory, | ||
SafeECDSAPlugin__factory, | ||
SponsorEverythingPaymaster__factory, | ||
EntryPoint__factory | ||
} from "../../typechain-types"; | ||
import receiptOf from "./utils/receiptOf"; | ||
import { setupTests } from "./utils/setupTests"; | ||
import { createAndSendUserOpWithEcdsaSig } from "./utils/createUserOp"; | ||
|
||
const oneEther = ethers.parseEther("1"); | ||
|
||
describe("SafeSponsorEverythingPaymasterPlugin", () => { | ||
it("should pass the ERC4337 validation", async () => { | ||
const { | ||
bundlerProvider, | ||
provider, | ||
admin, | ||
owner, | ||
entryPointAddress, | ||
deployer, | ||
safeSingleton, | ||
} = await setupTests(); | ||
|
||
// Deploy paymaster. | ||
const paymaster = await new SponsorEverythingPaymaster__factory(admin).deploy(entryPointAddress); | ||
await paymaster.waitForDeployment(); | ||
const paymasterAddress = await paymaster.getAddress(); | ||
|
||
// Paymaster deposits. | ||
await paymaster.connect(admin).deposit({ value: oneEther }) | ||
|
||
const recipient = ethers.Wallet.createRandom(); | ||
const transferAmount = oneEther; | ||
const dummySignature = await owner.signMessage("dummy sig"); | ||
|
||
// Deploy ecdsa plugin | ||
const safeECDSAFactory = await deployer.connectOrDeploy( | ||
SafeECDSAFactory__factory, | ||
[], | ||
); | ||
|
||
const createArgs = [ | ||
safeSingleton, | ||
entryPointAddress, | ||
await owner.getAddress(), | ||
0, | ||
] satisfies Parameters<typeof safeECDSAFactory.create.staticCall>; | ||
|
||
const accountAddress = await safeECDSAFactory.create.staticCall( | ||
...createArgs, | ||
); | ||
|
||
await receiptOf(safeECDSAFactory.create(...createArgs)); | ||
|
||
const safeEcdsaPlugin = SafeECDSAPlugin__factory.connect( | ||
accountAddress, | ||
owner, | ||
); | ||
|
||
// Native tokens for the pre-fund | ||
await receiptOf( | ||
admin.sendTransaction({ | ||
to: accountAddress, | ||
value: oneEther, | ||
}), | ||
); | ||
|
||
// Construct userOp | ||
const userOpCallData = safeEcdsaPlugin.interface.encodeFunctionData( | ||
"execTransaction", | ||
[recipient.address, transferAmount, "0x00"], | ||
); | ||
|
||
// Note: factoryParams is not used because we need to create both the safe | ||
// proxy and the plugin, and 4337 currently only allows one contract | ||
// creation in this step. Since we need an extra step anyway, it's simpler | ||
// to do the whole create outside of 4337. | ||
const factoryParams = { | ||
factory: "0x", | ||
factoryData: "0x", | ||
}; | ||
|
||
// Check paymaster balances before and after sending UserOp. | ||
const entrypoint = EntryPoint__factory.connect(entryPointAddress, provider) | ||
const paymasterBalanceBefore = await entrypoint.balanceOf(paymasterAddress) | ||
|
||
// Send userOp | ||
await createAndSendUserOpWithEcdsaSig( | ||
provider, | ||
bundlerProvider, | ||
owner, | ||
accountAddress, | ||
factoryParams, | ||
userOpCallData, | ||
entryPointAddress, | ||
dummySignature, | ||
paymasterAddress, | ||
3e5, | ||
"0x" | ||
); | ||
|
||
const paymasterBalanceAfter = await entrypoint.balanceOf(paymasterAddress) | ||
|
||
expect(paymasterBalanceBefore).greaterThan(paymasterBalanceAfter) | ||
expect(await provider.getBalance(recipient.address)).to.equal(oneEther); | ||
}); | ||
}); |
Oops, something went wrong.