### Copy Environment File (Bash) Source: https://github.com/safe-global/safe-modules/blob/main/examples/4337-passkeys/README.md Copies the example environment file `.env.example` to `.env` to configure application settings. ```bash cp .env.example .env ``` -------------------------------- ### Install Dependencies with pnpm (Bash) Source: https://github.com/safe-global/safe-modules/blob/main/examples/4337-passkeys/README.md Installs project dependencies using the pnpm package manager. ```bash pnpm install ``` -------------------------------- ### Run Development Server with pnpm (Bash) Source: https://github.com/safe-global/safe-modules/blob/main/examples/4337-passkeys/README.md Runs the development server for the specific example application package using pnpm. ```bash pnpm run --filter @safe-global/safe-modules-example-4337-passkeys dev ``` -------------------------------- ### Installing Project Dependencies (Bash) Source: https://github.com/safe-global/safe-modules/blob/main/modules/passkey/README.md This command uses pnpm to install all necessary project dependencies as specified in the package.json file. ```bash pnpm install ``` -------------------------------- ### Clone Safe Modules Repository (Bash) Source: https://github.com/safe-global/safe-modules/blob/main/examples/4337-passkeys/README.md Clones the safe-global/safe-modules repository from GitHub and navigates into the cloned directory. ```bash git clone https://github.com/safe-global/safe-modules.git cd safe-modules ``` -------------------------------- ### Installing Project Dependencies (Bash) Source: https://github.com/safe-global/safe-modules/blob/main/modules/4337/README.md This command uses PNPM to install all necessary project dependencies as defined in the project's `package.json` file. This is the first step required before running tests or deploying contracts. ```Bash pnpm install ``` -------------------------------- ### Deploying Safe Allowance Module Contracts (Bash) Source: https://github.com/safe-global/safe-modules/blob/main/modules/allowances/README.md Installs dependencies and runs the deployment script for the Safe Global allowance module contracts on a specified network. Requires environment variables to be set. ```bash pnpm i pnpm run deploy ``` -------------------------------- ### Compiling Safe Allowance Module Contracts (Bash) Source: https://github.com/safe-global/safe-modules/blob/main/modules/allowances/README.md Installs dependencies and compiles the smart contracts for the Safe Global allowance module. ```bash pnpm i pnpm build ``` -------------------------------- ### Running Tests for Safe Allowance Module (Bash) Source: https://github.com/safe-global/safe-modules/blob/main/modules/allowances/README.md Installs dependencies and runs the test suite for the Safe Global allowance module contract. ```bash pnpm i pnpm test ``` -------------------------------- ### Generating Safe InitCode with WebAuthn Shared Signer and ERC-4337 Module Source: https://github.com/safe-global/safe-modules/blob/main/modules/passkey/contracts/4337/README.md This Solidity snippet demonstrates how to construct the initCode for deploying and configuring a Safe with the SafeWebAuthnSharedSigner and the Safe4337Module. It shows how to encode the signer configuration and module enablement calls using abi.encodeCall and bundle them within a MultiSend transaction for the Safe's setup function. ```Solidity SafeProxyFactory proxyFactory = ...;\nSafe singleton = ...;\nSafeWebAuthnSharedSigner sharedSigner = ...;\nSafe4337Module safe4337Module = ...;\nSafeModuleSetup moduleSetup = ...;\nMultiSend multiSend = ...;\n\nuint256 signerX = ...;\nuint256 signerY = ...;\nuint256 signerVerifiers = ...;\n\naddress initializer = ...;\nbytes memory initializerData = ...;\naddress fallbackHandler = ...;\n\naddress[] owners memory = [..., address(sharedSigner), ...];\nuint256 threshold = ...;\n\nbytes memory configureData = abi.encodeCall(\n sharedSigner.configure,\n (\n signerX,\n signerY,\n signerVerifiers\n )\n);\n\naddress[] memory modules = new address[](1);\n{\n modules[0] = safe4337Module;\n}\nbytes memory enableModulesData = abi.encodeCall(\n moduleSetup.enableModules,\n (modules)\n);\n\nbytes memory initCode = abi.encodePacked(\n proxyFactory,\n abi.encodeCall(\n launchpad.setup,\n (\n owners,\n threshold,\n address(multiSend),\n abi.encodeCall(\n multiSend.multiSend,\n abi.encodePacked(\n // configure signer\n uint8(1), // operation\n address(sharedSigner),\n uint256(0), // value\n configureData.length,\n configureData\n // enable modules\n uint8(1), // operation\n address(moduleSetup),\n uint256(0), // value\n enableModulesData.length,\n enableModulesData\n )\n ),\n address(safe4337Module),\n address(0),\n 0,\n address(0)\n )\n )\n); ``` -------------------------------- ### Composing Safe 4337 Module InitCode (Solidity) Source: https://github.com/safe-global/safe-modules/blob/main/modules/4337/README.md This Solidity code demonstrates how to construct the `initCode` required by ERC-4337 to deploy a Safe account with the 4337 module enabled. It involves setting up the module list, encoding the initializer data for the Safe setup, encoding the call data for the proxy factory, and finally packing the proxy factory address and call data into the final `initCode`. ```Solidity /** Setup Safe **/ address[] memory modules = new address[](1); { modules[0] = SAFE_4337_MODULE_ADDRESS; } bytes memory initializer = abi.encodeWithSignature( "setup(address[],uint256,address,bytes,address,address,uint256,address)", owners, threshold, SAFE_MODULE_SETUP_ADDRESS, abi.encodeWithSignature("enableModules(address[])", modules), SAFE_4337_MODULE_ADDRESS, // We do not want to use any refund logic; therefore, this is all set to 0 address(0), 0, address(0) ); /** Deploy Proxy **/ bytes memory initCallData = abi.encodeWithSignature( "createProxyWithNonce(address,bytes,uint256)", SAFE_SINGLETON_ADDRESS, initializer, saltNonce ); /** Encode for 4337 **/ bytes memory initCode = abi.encodePacked(SAFE_PROXY_FACTORY_ADDRESS, initCallData); ``` -------------------------------- ### Verifying Safe Allowance Module Contract on Etherscan (TypeScript) Source: https://github.com/safe-global/safe-modules/blob/main/modules/allowances/README.md Example TypeScript code snippet showing how to manually specify the Etherscan API URL when verifying the deployed contract using the Hardhat 'etherscan-verify' task. ```ts await hre.run('etherscan-verify', { forceLicense: true, license: 'LGPL-3.0', apiUrl: "https://api.gnosiscan.io" }) ``` -------------------------------- ### Using Floating Pragma and Defining Contract (Solidity) Source: https://github.com/safe-global/safe-modules/blob/main/modules/passkey/docs/v0.2.1/audit-competition-report-hats.md This snippet shows the use of a floating Solidity pragma (`>=0.8.0`) and the start of the `SafeWebAuthnSharedSigner` contract definition. The issue is that using floating pragmas is discouraged for deployed contracts as it doesn't fix the compiler version, which can lead to unexpected behavior or vulnerabilities if compiled with a different version than intended. ```Solidity pragma solidity >=0.8.0; import {SignatureValidator} from "../base/SignatureValidator.sol"; import {ISafe} from "../interfaces/ISafe.sol"; import {P256, WebAuthn} from "../libraries/WebAuthn.sol"; /** * @title Safe WebAuthn Shared Signer * @dev A contract for verifying WebAuthn signatures shared by all Safe accounts. This contract uses * storage from the Safe account itself for full ERC-4337 compatibility. */ contract SafeWebAuthnSharedSigner is SignatureValidator { ``` -------------------------------- ### Detailed Deployment Steps (Bash) Source: https://github.com/safe-global/safe-modules/blob/main/modules/passkey/README.md This sequence of commands outlines the individual steps performed by the 'pnpm run deploy-all' script. It includes building, deploying via Hardhat, local verification, Etherscan verification, Sourcify verification, and specific contract verification. ```bash pnpm run build npx hardhat --network $NETWORK deploy npx hardhat --network $NETWORK local-verify npx hardhat --network $NETWORK etherscan-verify npx hardhat --network $NETWORK sourcify npx hardhat --network $NETWORK verify $SAFE_WEBAUTHN_SIGNER_SINGLETON_ADDRESS --contract SafeWebAuthnSignerSingleton ``` -------------------------------- ### Deployment Steps (Bash) Source: https://github.com/safe-global/safe-modules/blob/main/modules/4337/README.md This sequence of commands outlines the individual steps performed by the `deploy-all` script. It includes building the project, deploying using Hardhat, and verifying the deployed contracts on local networks, Etherscan, and Sourcify. ```Bash pnpm run build npx hardhat --network $NETWORK deploy npx hardhat --network $NETWORK local-verify npx hardhat --network $NETWORK etherscan-verify npx hardhat --network $NETWORK sourcify ``` -------------------------------- ### Deploying All Contracts (Bash) Source: https://github.com/safe-global/safe-modules/blob/main/modules/4337/README.md This command initiates the deterministic deployment process for all project contracts to a specified network (`$NETWORK`). It requires `MNEMONIC` and `INFURA_KEY` to be set in the `.env` file. ```Bash pnpm run deploy-all $NETWORK ``` -------------------------------- ### Running Benchmark Tests (Bash) Source: https://github.com/safe-global/safe-modules/blob/main/modules/passkey/README.md This command executes the project's benchmark tests to measure performance characteristics of the contracts or code. ```bash pnpm run bench ``` -------------------------------- ### Running All Tests (Bash) Source: https://github.com/safe-global/safe-modules/blob/main/modules/4337/README.md This command provides a shortcut to execute both the Hardhat integration tests and the end-to-end tests sequentially. It ensures comprehensive testing of the project's functionality. ```Bash pnpm run test:all ``` -------------------------------- ### Deploy Safe and Execute ERC721 Transaction with Gelato Source: https://github.com/safe-global/safe-modules/blob/main/examples/4337-gas-metering/gelato/README.md Runs the `gelato:erc721:1balance` pnpm script to deploy a new Safe wallet and then execute an ERC721 transaction via Gelato Relay. The output logs indicate the deployment step before transaction execution, providing links to the Gelato task and resulting transaction. ```shell pnpm run gelato:erc721:1balance ``` -------------------------------- ### Deploying All Contracts Deterministically (Bash) Source: https://github.com/safe-global/safe-modules/blob/main/modules/passkey/README.md This command triggers the deterministic deployment process for all contracts on a specified network. It requires MNEMONIC or PK and ETHERSCAN_API_KEY environment variables to be set for deployment and verification. ```bash pnpm run deploy-all $NETWORK ``` -------------------------------- ### Running Hardhat Tests (Bash) Source: https://github.com/safe-global/safe-modules/blob/main/modules/passkey/README.md These commands execute the project's test suite using Hardhat. The first command runs the standard tests, and the second specifically runs tests related to EIP-4337. ```bash pnpm test pnpm run test:4337 ``` -------------------------------- ### Running ERC-4337 Local Bundler Tests using pnpm Source: https://github.com/safe-global/safe-modules/blob/main/modules/passkey/test/4337/local-bundler/README.md This command executes the ERC-4337 compatibility tests against the local reference bundler using the pnpm package manager. It is the standard way to run these specific tests within the project. ```Shell pnpm run test:4337 ``` -------------------------------- ### Deploying Safe + Native Transfer with Gelato Relay (Shell) Source: https://github.com/safe-global/safe-modules/blob/main/examples/4337-gas-metering/gelato/README.md Runs a script to deploy a new Safe account and perform a native ETH transfer within the same transaction using Gelato Relay. It involves preparing calldata, init code, determining the counterfactual address, funding the address, and relaying the combined deployment and transfer transaction. ```Shell pnpm run gelato:native-transfer:1balance > @safe-global/4337-gas-metering@1.0.0 gelato:native-transfer:1balance > tsx ./gelato/gelato.ts native-transfer ``` -------------------------------- ### Deploying Safe Account with Gelato Relay (Shell) Source: https://github.com/safe-global/safe-modules/blob/main/examples/4337-gas-metering/gelato/README.md Executes a script to deploy a new Safe account using Gelato Relay. The process involves extracting a signer, creating calldata and init code, determining the counterfactual address, and relaying the deployment transaction. The output includes links to the transaction status and gas usage. ```Shell pnpm run gelato:account:1balance > @safe-global/4337-gas-metering@1.0.0 gelato:account:1balance > tsx ./gelato/gelato.ts account ``` -------------------------------- ### Running Hardhat Integration Tests (Bash) Source: https://github.com/safe-global/safe-modules/blob/main/modules/4337/README.md This command executes the Hardhat integration tests defined within the project. These tests verify the functionality of the contracts in a simulated environment using Hardhat. ```Bash pnpm test ``` -------------------------------- ### Running End-to-end Tests (Bash) Source: https://github.com/safe-global/safe-modules/blob/main/modules/4337/README.md This command runs the end-to-end tests, which interact with a reference bundler implementation. These tests require Docker and a Geth RPC endpoint to verify compliance with ERC-4337 validation rules. ```Bash pnpm run test:e2e ``` -------------------------------- ### Deploying Safe + ERC20 Transfer with Gelato Relay (Shell) Source: https://github.com/safe-global/safe-modules/blob/main/examples/4337-gas-metering/gelato/README.md Runs a script to deploy a new Safe account and execute an ERC20 token transfer within the same transaction using Gelato Relay. Steps include preparing calldata, init code, determining the counterfactual address, minting ERC20 tokens to the address, and relaying the combined deployment and transfer transaction. ```Shell pnpm run gelato:erc20:1balance > @safe-global/4337-gas-metering@1.0.0 gelato:erc20:1balance > tsx ./gelato/gelato.ts erc20 ``` -------------------------------- ### Execute ERC721 Transaction with Gelato (Existing Safe) Source: https://github.com/safe-global/safe-modules/blob/main/examples/4337-gas-metering/gelato/README.md Runs the `gelato:erc721:1balance` pnpm script to execute an ERC721 transaction via Gelato Relay using an existing Safe wallet. The output confirms the Safe is already deployed before proceeding with transaction preparation, signing, and execution via Gelato, providing relevant links and gas usage. ```shell pnpm run gelato:erc721:1balance ``` -------------------------------- ### Run Hardhat Script on Goerli Source: https://github.com/safe-global/safe-modules/blob/main/modules/4337/README.md Executes the `scripts/runOp.ts` script using Hardhat on the Goerli network. Requires setting `DEPLOYMENT_ENTRY_POINT_ADDRESS` and `SCRIPT_*` environment variables beforehand. ```Bash npx hardhat run scripts/runOp.ts --network goerli ``` -------------------------------- ### Execute ERC20 Transaction with Gelato (Existing Safe) Source: https://github.com/safe-global/safe-modules/blob/main/examples/4337-gas-metering/gelato/README.md Runs the `gelato:erc20:1balance` pnpm script to execute an ERC20 transaction via Gelato Relay using an existing Safe wallet. The process involves preparing calldata, creating init code, determining the counterfactual address, and executing the transaction through Gelato. Output includes transaction links and gas usage. ```shell pnpm run gelato:erc20:1balance ``` -------------------------------- ### ERC-4337 User Operation Execution Flow Diagram Source: https://github.com/safe-global/safe-modules/blob/main/modules/4337/README.md This Mermaid diagram illustrates the sequence of interactions between the Bundler, Entry Point, Safe Proxy, Safe Singleton, Safe 4337 Module, and Target contract during the validation and execution of an ERC-4337 user operation. ```Mermaid sequenceDiagram actor B as Bundler participant E as Entry Point participant P as Safe Proxy participant S as Safe Singleton participant M as Safe 4337 Module actor T as Target B->>+E: Submit User Operations E->>+P: Validate User Operation P-->>S: Load Safe logic Note over P, M: Gas overhead for calls and storage access P->>+M: Forward validation Note over P, M: Load fallback handler ~2100 gas
Intital module access ~2600 gas M->>P: Check signatures P-->>S: Load Safe logic Note over P, M: Call to Safe Proxy ~100 gas
Load logic ~100 gas opt Pay required fee M->>P: Trigger fee payment P-->>S: Load Safe logic Note over P, M: Module check ~2100 gas
Call to Safe Proxy ~100 gas
Load logic ~100 gas P->>E: Perform fee payment end M-->>-P: Validation response P-->>-E: Validation response Note over P, M: Total gas overhead
Without fee payment ~4.900 gas
With fee payment ~7.200 gas E->>+P: Execute User Operation P-->>S: Load Safe logic P->>+M: Forward execution Note over P, M: Call to Safe Proxy ~100 gas
Call to fallback handler ~100 gas M->>P: Execute From Module P-->>S: Load Safe logic Note over P, M: Call to Safe Proxy ~100 gas
Module check ~100 gas P->>+T: Perform transaction opt Bubble up return data T-->>-P: Call Return Data P-->>M: Call Return Data M-->>-P: Call return data P-->>-E: Call return data end ``` -------------------------------- ### Executing Native Transfer on Deployed Safe with Gelato Relay (Shell) Source: https://github.com/safe-global/safe-modules/blob/main/examples/4337-gas-metering/gelato/README.md Executes a script to perform a native ETH transfer on an already deployed Safe account using Gelato Relay. The process involves creating and signing calldata for the transfer and relaying the transaction. This demonstrates executing a transaction on an existing Safe via the relayer. ```Shell pnpm run gelato:native-transfer:1balance > @safe-global/4337-gas-metering@1.0.0 gelato:native-transfer:1balance > tsx ./gelato/gelato.ts native-transfer ``` -------------------------------- ### Local Contract Verification with Hardhat Source: https://github.com/safe-global/safe-modules/blob/main/modules/4337/README.md Performs local verification of deployed contracts using Hardhat. It compiles contracts from deployment artifacts and compares them against the on-chain code on the specified network (`$NETWORK`). ```Bash npx hardhat --network $NETWORK local-verify ``` -------------------------------- ### Encoding WebAuthn Signature Data for Verification (Solidity) Source: https://github.com/safe-global/safe-modules/blob/main/modules/passkey/README.md This snippet demonstrates how to encode the components of a WebAuthn signature (`authenticatorData`, `clientDataFields`, `r`, `s`) into a single `bytes` array using `abi.encode`. This specific encoding format is required by the `WebAuthn` library's `verifySignature` function for on-chain verification. ```Solidity bytes authenticatorData = ...; string clientDataFields = ...; uint256 r = ...; uint256 s = ...; // Encode the signature data bytes memory signature = abi.encode(authenticatorData, clientDataFields, r, s); ``` -------------------------------- ### Etherscan Contract Verification with Hardhat Source: https://github.com/safe-global/safe-modules/blob/main/modules/4337/README.md Uploads the source code of deployed contracts to Etherscan for verification. Uses Hardhat and requires specifying the target network (`$NETWORK`). ```Bash npx hardhat --network $NETWORK etherscan-verify ``` -------------------------------- ### Computing P256.Verifiers Value (Solidity) Source: https://github.com/safe-global/safe-modules/blob/main/modules/passkey/README.md This Solidity snippet demonstrates how to compute the uint176 value for the P256.Verifiers custom type. It combines a 2-byte precompile address and a 20-byte fallback verifier address into a single value, allowing the library to use either a precompile or a fallback contract. ```Solidity uint16 precompile = ...; address fallbackVerifier = ...; P256.Verifiers = P256.Verifiers.wrap( (uint176(precompile) << 160) + uint176(uint160(fallbackVerifier)) ); ``` -------------------------------- ### Configuring Signer in SafeWebAuthnSharedSigner (Solidity) Source: https://github.com/safe-global/safe-modules/blob/main/modules/passkey/docs/v0.2.1/audit-competition-report-hats.md This Solidity function `configure` in `SafeWebAuthnSharedSigner` updates the signer configuration in storage using inline assembly. The issue highlighted is that it fails to emit an event after modifying the storage, which is a best practice for transparency and external monitoring. ```Solidity function configure(Signer memory signer) external onlyDelegateCall { uint256 signerSlot = SIGNER_SLOT; Signer storage signerStorage; // solhint-disable-next-line no-inline-assembly assembly ('memory-safe') { signerStorage.slot := signerSlot } signerStorage.x = signer.x; signerStorage.y = signer.y; signerStorage.verifiers = signer.verifiers; } ``` -------------------------------- ### Specifying Certora CLI Dependency - Python Source: https://github.com/safe-global/safe-modules/blob/main/modules/passkey/certora/requirements.txt This line specifies a required dependency for the project: the 'certora-cli' package at the exact version 7.17.2. This format is commonly used in Python's requirements.txt files to ensure reproducible builds. ```Python certora-cli==7.17.2 ``` -------------------------------- ### EIP-712 Domain Type Definition - JSON Source: https://github.com/safe-global/safe-modules/blob/main/modules/allowances/README.md Defines the EIP-712 domain structure used for signing messages in the Allowance Module. It includes the chain ID and the verifying contract address. ```json { "EIP712Domain": [ { "type": "uint256", "name": "chainId" }, { "type": "address", "name": "verifyingContract" } ] } ``` -------------------------------- ### Encoding Signatures for Safe 4337 (Solidity) Source: https://github.com/safe-global/safe-modules/blob/main/modules/4337/README.md This Solidity function shows how signatures are encoded for use with the Safe 4337 module. It concatenates `validUntil` and `validAfter` timestamps (48 bits each) with the actual concatenated signatures bytes, following the specified Safe signature encoding format. ```Solidity function encodeSignatures(uint48 validUntil, uint48 validAfter, bytes signatures) { return abi.encodePacked(validUntil, validAfter, signatures); } ``` -------------------------------- ### EIP-712 AllowanceTransfer Type Definition - JSON Source: https://github.com/safe-global/safe-modules/blob/main/modules/allowances/README.md Defines the EIP-712 structure for the AllowanceTransfer message signed by delegates. It includes details about the Safe, token, recipient, amount, payment token, payment amount, and nonce. ```json { "AllowanceTransfer": [ { "type": "address", "name": "safe" }, { "type": "address", "name": "token" }, { "type": "address", "name": "to" }, { "type": "uint96", "name": "amount" }, { "type": "address", "name": "paymentToken" }, { "type": "uint96", "name": "payment" }, { "type": "uint16", "name": "nonce" } ] } ``` -------------------------------- ### Performing Staticcall in SHA-256 Function (Solidity Assembly) Source: https://github.com/safe-global/safe-modules/blob/main/modules/passkey/docs/v0.2.1/audit-competition-report-hats.md This Solidity assembly code snippet is part of a `_sha256` function, performing a `staticcall` to compute a hash. The critical issue is that the success/failure return value of the `staticcall` is not checked, meaning execution continues even if the call fails, potentially leading to unexpected behavior. ```Solidity pop(staticcall(gas(), 0x0002, add(input, 0x20), mload(input), 0, 32)) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.