-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Summary
In simulate-with-tenderly/simulate-with-tenderly.ts, PUBLIC_ADDRESS and PRIVATE_KEY environment variables are currently resolved independently. This can result in a mismatch where an env-specified address is paired with a generated private key, or vice versa — causing the simulated UserOperation to be signed by a different owner than the one used to initialize the account, making it invalid.
Steps to Reproduce
- Set only
PUBLIC_ADDRESSin the environment (withoutPRIVATE_KEY). - Run the simulate-with-tenderly example.
- The account is initialized with the env address, but the UserOperation is signed with a freshly generated private key — the simulation will fail or produce an invalid result.
Expected Behavior
ownerPublicAddress and ownerPrivateKey must always come from the same source (either both from environment variables, or both from a freshly generated key pair). If only one of the two env vars is provided, an error should be thrown.
Suggested Fix
const ownerPrivateKeyGenerated = generatePrivateKey();
const owner = privateKeyToAccount(ownerPrivateKeyGenerated);
const envPublicAddress = process.env.PUBLIC_ADDRESS;
const envPrivateKey = process.env.PRIVATE_KEY;
if ((envPublicAddress && !envPrivateKey) || (!envPublicAddress && envPrivateKey)) {
throw new Error("PUBLIC_ADDRESS and PRIVATE_KEY must be provided together");
}
const ownerPublicAddress = envPublicAddress ?? owner.address;
const ownerPrivateKey = envPrivateKey ?? ownerPrivateKeyGenerated;References
- PR: Refactor/replace ethers with viem #15
- Review comment: Refactor/replace ethers with viem #15 (comment)
Requested by @Sednaoui
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels