-
Notifications
You must be signed in to change notification settings - Fork 64
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
feat: prevent on revert spoofing backport #362
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ on: | |
- "v2/**" | ||
pull_request: | ||
branches: | ||
- "*" | ||
- "**" | ||
paths: | ||
- "v2/**" | ||
types: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ on: | |
- 'v2/**' | ||
pull_request: | ||
branches: | ||
- "*" | ||
- "**" | ||
paths: | ||
- 'v2/**' | ||
types: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ on: | |
- 'v2/**' | ||
pull_request: | ||
branches: | ||
- "*" | ||
- "**" | ||
paths: | ||
- 'v2/**' | ||
types: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ on: | |
- 'v2/**' | ||
pull_request: | ||
branches: | ||
- "*" | ||
- "**" | ||
paths: | ||
- 'v2/**' | ||
types: | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -76,6 +76,7 @@ contract GatewayEVM is | |||||||||
/// @param data Calldata to pass to the call. | ||||||||||
/// @return The result of the call. | ||||||||||
function _execute(address destination, bytes calldata data) internal returns (bytes memory) { | ||||||||||
revertIfCallingOnRevert(data); | ||||||||||
(bool success, bytes memory result) = destination.call{ value: msg.value }(data); | ||||||||||
if (!success) revert ExecutionFailed(); | ||||||||||
|
||||||||||
|
@@ -385,4 +386,18 @@ contract GatewayEVM is | |||||||||
IERC20(token).safeTransfer(custody, amount); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
// @dev prevent spoofing onRevert functions | ||||||||||
function revertIfCallingOnRevert(bytes calldata data) private pure { | ||||||||||
if (data.length >= 4) { | ||||||||||
bytes4 functionSelector; | ||||||||||
assembly { | ||||||||||
functionSelector := calldataload(data.offset) | ||||||||||
} | ||||||||||
|
||||||||||
if (functionSelector == Revertable.onRevert.selector) { | ||||||||||
revert NotAllowedToCallOnRevert(); | ||||||||||
} | ||||||||||
Comment on lines
+398
to
+400
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: is it possible to update this to Solidity 0.8.27? In that version require can now exit with a custom error, rendering this expression to:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we probably can, but in separate effort, this PR is for backporting a fix, please open issue for that update |
||||||||||
} | ||||||||||
} | ||||||||||
} |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,6 +182,14 @@ contract GatewayEVMTest is Test, IGatewayEVMErrors, IGatewayEVMEvents, IReceiver | |
gateway.execute(address(receiver), data); | ||
} | ||
|
||
function testForwardCallToReceiveOnRevertFails() public { | ||
bytes memory data = abi.encodeWithSignature("onRevert((address,uint64,bytes))"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this data build when we don't provide value for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think its using default values for the type |
||
|
||
vm.prank(tssAddress); | ||
vm.expectRevert(NotAllowedToCallOnRevert.selector); | ||
gateway.execute(address(receiver), data); | ||
} | ||
|
||
function testExecuteFailsIfDestinationIsZeroAddress() public { | ||
bytes memory data = abi.encodeWithSignature("receiveNoParams()"); | ||
|
||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
workflows were not triggering, maybe because of branch naming, but with
**
seems to work, will include this on main branch as well