it.only("should validate user operation correctly with signing", async function () {
[owner, addr1] = await ethers.getSigners();
const entryPoint = await hre.ethers.getContractAt(
"MockEntryPoint",
EP_ADDRESS
);
await mondrianWallet.connect(owner).addDeposit({
value: hre.ethers.parseEther("100"),
});
const sender = await hre.ethers.getCreateAddress({
from: FACTORY_ADDRESS,
nonce: FACTORY_NONCE,
});
const address0 = await owner.getAddress();
let initCode = "0x";
const Account = await hre.ethers.getContractFactory("MondrianWallet");
const callGasLimit = ethers.zeroPadValue(ethers.toBeHex(200000), 16);
const verificationGasLimit = ethers.zeroPadValue(
ethers.toBeHex(200000),
16
);
const accountGasLimits =
"0x" +
Buffer.concat([
Buffer.from(callGasLimit.slice(2), "hex"),
Buffer.from(verificationGasLimit.slice(2), "hex"),
]).toString("hex");
const maxPriorityFeePerGas = ethers.zeroPadValue(ethers.toBeHex(25000), 16);
const maxFeePerGas = ethers.zeroPadValue(ethers.toBeHex(25000), 16);
const gasFees =
"0x" +
Buffer.concat([
Buffer.from(maxPriorityFeePerGas.slice(2), "hex"),
Buffer.from(maxFeePerGas.slice(2), "hex"),
]).toString("hex");
console.log(gasFees);
const userOp = {
sender,
nonce: await entryPoint.getNonce(sender, 0),
initCode,
callData: Account.interface.encodeFunctionData("mint", [sender, 0]),
accountGasLimits,
preVerificationGas: 500000,
gasFees,
paymasterAndData: "0x",
signature: "0x",
};
const userOpHash = await entryPoint.getUserOpHash(userOp);
userOp.signature = await addr1.signMessage(hre.ethers.getBytes(userOpHash));
const tx = await entryPoint.handleOps([userOp], address0);
const receipt = await tx.wait();
console.log(receipt);
});
This makes the signature validation incomplete and always returns SIG_VALIDATION_SUCCESS.
function _validateSignature(PackedUserOperation calldata userOp, bytes32 userOpHash)
internal
view
returns (uint256 validationData)
{
bytes32 hash = MessageHashUtils.toEthSignedMessageHash(userOpHash);
address recoveredAddress = ECDSA.recover(hash, userOp.signature);
if (recoveredAddress != owner()) {
return SIG_VALIDATION_FAILED;
}
return SIG_VALIDATION_SUCCESS;
}