Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary tx hash complexity and make it version agnostic #14

Merged
merged 2 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SAFE=0x0000000000000000000000000000000000000000
SENDER=0x0000000000000000000000000000000000000000

SAFE_NONCE=
FOUNDRY_ETH_RPC_URL=https://eth.llamarpc.com
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
31 changes: 12 additions & 19 deletions script/SafeTxDataBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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)
Expand Down