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_ADDRESS in the environment (without PRIVATE_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
Requested by @Sednaoui
Summary
In
simulate-with-tenderly/simulate-with-tenderly.ts,PUBLIC_ADDRESSandPRIVATE_KEYenvironment 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
PUBLIC_ADDRESSin the environment (withoutPRIVATE_KEY).Expected Behavior
ownerPublicAddressandownerPrivateKeymust 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
References
Requested by @Sednaoui