Guard::checkTransaction restricts native ETH transfer from user’s safes
The Guard::checkTransaction function required transaction data to be at least 4 bytes long, which prevented native ETH transfers from a rental safe because such transfers have empty data. As a result, users could not transfer ETH out of their safes, leaving funds stuck.
AkshaySrivastav Follow with KupiaSec
Originally disclosed on Code4rena
Submitted by AkshaySrivastav, also found by KupiaSec
The Guard::checkTransaction function’s current design unintentionally restricts native ETH transfers from the safe. This limitation originates from a data length check that requires transaction data to be at least 4 bytes long, aiming to validate the presence of a function selector.
However, since native ETH transfers have empty data fields, they fail this, leading to an inability to execute such transfers.
This results in a significant functional restriction, as users are unable to execute standard ETH transfers from their safes.
The Safe contracts contains receive function which by default enables them to receive native ETH. These native tokens can be transferred to safe by protocol users or current/future protocol hooks.
receive() external payable {
emit SafeReceived(msg.sender, msg.value);
}
Proof of Concept
The Guard::checkTransaction is designed to validate transactions initiated by a rental safe. Its role is to ascertain whether a transaction meets the set criteria based on its destination, value, data and operation type. This function is a critical component in ensuring that transactions are executed in accordance with the protocol’s rule.
A notable issue within the Guard::checkTransaction function is its requirement for transaction data to be at least 4 bytes long, as indicated by this code:
In src/policies/Guard.sol
328 // Require that a function selector exists.
329 if (data.length < 4) {
330 revert Errors.GuardPolicy_FunctionSelectorRequired();
331 }
This condition is ideal for transactions involving function calls where a function selector is necessary.
However, this becomes problematic for native ETH transfers, which are characteristically simple transactions without any data payload. As these transactions have a data length of zero bytes, failing the imposed condition.
Such transactions are automatically rejected by the Guard::checkTransaction function due to not meeting the 4-byte data length requirement.
The inability to transfer native ETH not only reduces the safe’s practicality but also poses a severe limitation on user operations, affecting trust and reliability in the system.
The following foundry test shows the process described above. Copy and paste it into test folder to run.
Click to expand Foundry Test
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.20;
import {BaseTest} from "@test/BaseTest.sol";
import {SafeProxyFactory} from "@safe-contracts/proxies/SafeProxyFactory.sol";
import {SafeL2} from "@safe-contracts/SafeL2.sol";
import {ISafe} from "@src/interfaces/ISafe.sol";
import {Enum} from "@safe-contracts/common/Enum.sol";
import {Errors} from "@src/libraries/Errors.sol";
contract SafeStuckEth is BaseTest {
// In this test case we'll see how ETH transfers works fine for normal Gnosis Safes
// But doesn't work for ReNFT Safes
function test_poc() public {
vm.startPrank(alice.addr);
// Create a new safe by directly interacting with Gnosis safe factory
SafeProxyFactory safeFactory = factory.safeProxyFactory();
SafeL2 safeSingleton = factory.safeSingleton();
address[] memory owners = new address[](1);
owners[0] = alice.addr;
bytes memory initializerPayload = abi.encodeCall(
ISafe.setup,
(
owners,
1,
address(0),
new bytes(0),
address(0),
address(0),
0,
payable(address(0))
)
);
// new safe is created
address newSafe = address(
safeFactory.createProxyWithNonce(
address(safeSingleton),
initializerPayload,
uint256(keccak256(""))
)
);
address receiver = address(0x1010101);
// Transfer some ETH to the freshly deployed safe
vm.deal(newSafe, 1 ether);
assertEq(newSafe.balance, 1 ether);
assertEq(receiver.balance, 0);
// Pull out the sent ETH from the safe
bytes memory transactionSignature = _signTransaction(
address(newSafe),
Enum.Operation.Call,
alice.privateKey,
address(receiver),
1 ether,
new bytes(0)
);
_executeTransaction(
address(newSafe),
Enum.Operation.Call,
address(receiver),
1 ether,
new bytes(0),
transactionSignature,
new bytes(0)
);
// ETH succesfully pulled out from the safe
assertEq(newSafe.balance, 0);
assertEq(receiver.balance, 1 ether);
/// Now replicate same scenario for a ReNFT safe
// Send some ETH to an existing ReNFT safe of Alice
vm.deal(address(alice.safe), 1 ether);
assertEq(address(alice.safe).balance, 1 ether);
assertEq(receiver.balance, 1 ether);
transactionSignature = _signTransaction(
address(alice.safe),
Enum.Operation.Call,
alice.privateKey,
address(receiver),
1 ether,
new bytes(0)
);
// Try to pull out ETH
// Txn reverts with error `GuardPolicy_FunctionSelectorRequired`
vm.expectRevert(abi.encodeWithSelector(Errors.GuardPolicy_FunctionSelectorRequired.selector));
_executeTransaction(
address(alice.safe),
Enum.Operation.Call,
address(receiver),
1 ether,
new bytes(0),
transactionSignature,
new bytes(0)
);
// ETH remains stuck in Alice's ReNFT safe
assertEq(address(alice.safe).balance, 1 ether);
assertEq(receiver.balance, 1 ether);
}
function _signTransaction(
address safe,
Enum.Operation operation,
uint256 ownerPrivateKey,
address to,
uint256 value,
bytes memory transaction
) private view returns (bytes memory transactionSignature) {
// get the safe nonce
uint256 nonce = ISafe(safe).nonce();
// get the eip712 compatible transaction hash that the safe owner will sign
bytes32 transactionHash = ISafe(safe).getTransactionHash(
to,
value,
transaction,
operation,
0 ether,
0 ether,
0 ether,
address(0),
payable(address(0)),
nonce
);
// sign the transaction
(uint8 v, bytes32 r, bytes32 s) = vm.sign(ownerPrivateKey, transactionHash);
transactionSignature = abi.encodePacked(r, s, v);
}
function _executeTransaction(
address safe,
Enum.Operation operation,
address to,
uint256 value,
bytes memory transaction,
bytes memory signature,
bytes memory expectedError
) private {
// expect an error if error data was provided
if (expectedError.length != 0) {
vm.expectRevert(expectedError);
}
// execute the transaction
ISafe(safe).execTransaction(
to,
value,
transaction,
operation,
0 ether,
0 ether,
0 ether,
address(0),
payable(address(0)),
signature
);
}
}
Tools Used
Foundry
Recommended Mitigation Steps
Consider allowing data.length to be 0 as that will be used for performing native ETH transfers.
See comment on issue 261.
Alec1017 (reNFT) confirmed and commented:
Agree that this is a valid M vulnerability.
The PR here - Allows native ETH to be transferred out of a rental safe.
Status: Mitigation confirmed. Full details in reports from EV_om and sin1st3r__.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
Users could not transfer native ETH out of their rental safes, leaving funds stuck and reducing the safe's practicality.
What the attacker needed
A rental safe holding ETH; safe owner initiates a transfer
The fix
The guard was fixed to allow zero-length data so that native ETH transfers can be executed.
How it was found
- Deploy a normal Gnosis Safe and fund it with ETH.
- Sign and execute a transaction sending 1 ETH to a receiver with empty data; it succeeds.
- Fund an existing ReNFT safe with ETH.
- Sign and attempt the same ETH transfer from the ReNFT safe; it reverts with GuardPolicy_FunctionSelectorRequired.
- Observe that the ETH remains stuck in the ReNFT safe.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract safe holds funds and only allows transfers if a guard contract approves them. The guard mistakenly required every transfer to include extra data (at least 4 bytes), but simple ETH transfers have no such data, so the guard rejected them and the ETH could not be moved out.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.