Skip to content

Commit

Permalink
fix: update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hoshiyari420 committed Mar 11, 2024
1 parent 9aa5b7c commit 45e90d7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
8 changes: 5 additions & 3 deletions contracts/contracts/paymasters/SignatureBasedPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ contract SignatureBasedPaymaster is IPaymaster, Ownable, EIP712 {
);
(uint lastTimestamp, bytes memory sig) = abi.decode(innerInputs,(uint256,bytes));

// Verify if token is the correct one
// Verify signature expiry based on timestamp.
// Timestamp is used in signature hash, hence cannot be faked.
require(block.timestamp <= lastTimestamp, "Paymaster: Signature expired");
// We verify that the user has provided enough allowance
// Get user address from transaction.from
address userAddress = address(uint160(_transaction.from));
// Generate hash
bytes32 hash = keccak256(abi.encode(SIGNATURE_TYPEHASH, userAddress,lastTimestamp, nonces[userAddress]++));

// Hashing with domain separator includes chain id. Hence prevention to signature replay atttacks.
bytes32 digest = _hashTypedDataV4(hash);
require(signer == digest.recover(sig),"Paymaster: Invalid signer");

Expand Down
2 changes: 1 addition & 1 deletion contracts/deploy/signatureBasedPaymaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default async function (hre: HardhatRuntimeEnvironment) {
const network = hre.userConfig.networks?.zkSyncTestnet;
const provider = new Provider((network as HttpNetworkUserConfig).url);

// The wallet that will deploy the token and the paymaster
// The wallet that will deploy the paymaster
// It is assumed that this wallet already has sufficient funds on zkSync
const wallet = new Wallet(PRIVATE_KEY);
const deployer = new Deployer(hre, wallet);
Expand Down
3 changes: 1 addition & 2 deletions contracts/test/signatureBased.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ describe("SignatureBasedPaymaster", function () {
greeter = await deployContract(deployer, "Greeter", ["Hi"]);
await fundAccount(wallet, paymaster.address, "3");
console.log(`Paymaster current signer: ${signerWallet.address}`);
console.log("--------------------------------");
});

async function createSignatureData(
Expand Down Expand Up @@ -78,7 +77,7 @@ describe("SignatureBasedPaymaster", function () {

const signature = await signer._signTypedData(domain, types, values);

console.log("Signature generated successfully !");
//console.log("Signature generated successfully !");
//console.log("Signer : " + signer.address);
//console.log("Paymaster : "+ paymaster.address);
//console.log(`Signature valid till: ${lastTimestamp} for user: ${user.address} and nonce: ${nonce}`);
Expand Down

0 comments on commit 45e90d7

Please sign in to comment.