diff --git a/.env.example b/.env.example index 89c92d0..9c2aad6 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,5 @@ SAFE=0x0000000000000000000000000000000000000000 SENDER=0x0000000000000000000000000000000000000000 +SAFE_NONCE= FOUNDRY_ETH_RPC_URL=https://eth.llamarpc.com diff --git a/README.md b/README.md index 1251e25..c3685be 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ - Install [Foundry](https://github.com/foundry-rs/foundry). - Run `make` to initialize the repository. - Create a `.env` file from the template [`.env.example`](./.env.example) file. + - Use the environment variable `SAFE_NONCE` to override a transaction's nonce. Leave it blank to use the default, latest Safe nonce. You can customize the RPC url used in [`foundry.tml`](./foundry.toml) under the `rpc_endpoint` section. This is useful if your Safe is not deployed on mainnet (which is the default chain used). diff --git a/script/SafeTxDataBuilder.sol b/script/SafeTxDataBuilder.sol index d1a300f..c1ba5fb 100644 --- a/script/SafeTxDataBuilder.sol +++ b/script/SafeTxDataBuilder.sol @@ -45,7 +45,7 @@ contract SafeTxDataBuilder is Script, SignatureDecoder { constructor(address payable safe) { SAFE = GnosisSafe(safe); - NONCE = SAFE.nonce(); + NONCE = vm.envOr("SAFE_NONCE", SAFE.nonce()); THRESHOLD = SAFE.getThreshold(); DOMAIN_SEPARATOR = SAFE.domainSeparator(); } @@ -65,25 +65,18 @@ contract SafeTxDataBuilder is Script, SignatureDecoder { } function hashData(SafeTxData memory txData) internal view returns (bytes32) { - bytes32 safeTxHash = keccak256( - abi.encode( - SAFE_TX_TYPEHASH, - txData.to, - txData.value, - keccak256(txData.data), - txData.operation, - txData.safeTxGas, - txData.baseGas, - txData.gasPrice, - txData.gasToken, - txData.refundReceiver, - NONCE - ) + return SAFE.getTransactionHash( + txData.to, + txData.value, + txData.data, + txData.operation, + txData.safeTxGas, + txData.baseGas, + txData.gasPrice, + txData.gasToken, + txData.refundReceiver, + NONCE ); - - bytes memory txHashData = abi.encodePacked(bytes1(0x19), bytes1(0x01), DOMAIN_SEPARATOR, safeTxHash); - - return keccak256(txHashData); } function decode(bytes32 dataHash, bytes memory signature)