The XDEFI protocol has a migration system that uses user signatures.
Migration functions can be temporarily blocked with a permission frontrun. An attacker can call permit with the user’s signature directly on the token contract and increment the nonce, reverting the migration tx:
function permit(
address owner_,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external override {
require(owner_ != address(0), "ERC20: Owner cannot be 0");
require(block.timestamp < deadline, "ERC20: Expired");
bytes32 digest =
keccak256(
abi.encodePacked(
EIP191_PREFIX_FOR_EIP712_STRUCTURED_DATA,
DOMAIN_SEPARATOR,
>> keccak256(abi.encode(PERMIT_SIGNATURE_HASH, owner_, spender, value, nonces[owner_]++, deadline))
)
);
It is recommended to wrap token.permit() calls in a try-catch block to allow tx to continue if the permission has already been consumed:
function migrate(uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
+ try IERC20Permit(address(oldToken)).permit(msg.sender, address(this), amount, deadline, v, r, s) {} catch {}
// send tokens
}
A very simple and nice fix for such problem.
Read the full report here:
#trycatch
#signature
#frontrun
Completely free courses
Learn more about the blockchain world
Free education videos
by RareSkills
by Jeiwan
by RareSkills
by RareSkills
by Andreas M. Antonopoulos, Gavin Wood
by Micah Dameron
Compare execution layer differences between chains
Dive deep into the storage of any contract