-
Notifications
You must be signed in to change notification settings - Fork 621
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
fix(contracts): Frontrun Permit in GasSwap #1184
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1184 +/- ##
===========================================
+ Coverage 56.16% 57.08% +0.91%
===========================================
Files 157 153 -4
Lines 12176 11322 -854
===========================================
- Hits 6839 6463 -376
+ Misses 4814 4387 -427
+ Partials 523 472 -51
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Hi, How does it do it? Overall, the PR addresses a critical security concern and ensures the integrity and safety of the codebase by removing potentially exploitable functionality. |
According to https://github.com/Amxx/openzeppelin-contracts/blob/487b3f9cdd0561e151d4965ca18590bba907209a/contracts/token/ERC20/extensions/IERC20Permit.sol#L16-L33, doesn't use details: function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
if (block.timestamp > deadline) {
revert ERC2612ExpiredSignature(deadline);
}
bytes32 structHash = keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));
bytes32 hash = _hashTypedDataV4(structHash);
address signer = ECDSA.recover(hash, v, r, s);
if (signer != owner) {
revert ERC2612InvalidSigner(signer, owner);
}
_approve(owner, spender, value);
} when user sign function _useNonce(address owner) internal virtual returns (uint256) {
// For each account, the nonce has an initial value of 0, can only be incremented by one, and cannot be
// decremented or reset. This guarantees that the nonce never overflows.
unchecked {
// It is important to do x++ and not ++x here.
return _nonces[owner]++;
}
} so every time
add contract with normal permit(no try catch) + testing here: |
Also, I just pushed a fix to the test. Could you give it another look? I'm new to Hardhat. Thanks! |
b8d96d4
to
69dd4cc
Compare
69dd4cc
to
2a96c8f
Compare
@Thegaram hi! any update? |
hi @tapakornl we're reviewing this week, thank you very much for your patience. Update ASAP. |
please move to https://github.com/scroll-tech/scroll-contracts. |
Purpose or design rationale of this PR
Describe your change. Make sure to answer these three questions: What does this PR do? Why does it do it? How does it do it?
This PR fix the following issue
In brief, users may face front-running vulnerabilities when invoking
swap(...)
inGasSwap.sol
, as an attacker could executepermit
inERC20Permit.sol
before userswap
tx is mined, leading to the user's transaction reverting due to the signature being already used.PR title
Your PR title must follow conventional commits (as we are doing squash merge for each PR), so it must start with one of the following types:
Deployment tag versioning
Has
tag
incommon/version.go
been updated or have you addedbump-version
label to this PR?Breaking change label
Does this PR have the
breaking-change
label?