-
Notifications
You must be signed in to change notification settings - Fork 504
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
OZ-L10, SB-L53, SB-L54, SB-M78; Check code length on Notifications, Unsubscribe Minimum Gas Limit #318
OZ-L10, SB-L53, SB-L54, SB-M78; Check code length on Notifications, Unsubscribe Minimum Gas Limit #318
Changes from 7 commits
eca398f
c93fc95
dd948d2
845a1d4
7710b38
732bee4
234596f
a05c0c9
12989e5
e7fe727
de32571
e96d8d3
df2be3b
f23b137
0faaa59
21fa51f
f151630
dc3a623
6caa7cc
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 |
---|---|---|
|
@@ -46,7 +46,7 @@ abstract contract Notifier is INotifier { | |
_positionConfigs(tokenId).setSubscribe(); | ||
ISubscriber _subscriber = subscriber[tokenId]; | ||
|
||
if (_subscriber != NO_SUBSCRIBER) revert AlreadySubscribed(address(_subscriber)); | ||
if (_subscriber != NO_SUBSCRIBER) AlreadySubscribed.selector.revertWith(address(_subscriber)); | ||
subscriber[tokenId] = ISubscriber(newSubscriber); | ||
|
||
bool success = _call(newSubscriber, abi.encodeCall(ISubscriber.notifySubscribe, (tokenId, config, data))); | ||
|
@@ -67,11 +67,20 @@ abstract contract Notifier is INotifier { | |
{ | ||
_positionConfigs(tokenId).setUnsubscribe(); | ||
ISubscriber _subscriber = subscriber[tokenId]; | ||
if (_subscriber == NO_SUBSCRIBER) NotSubscribed.selector.revertWith(); | ||
|
||
delete subscriber[tokenId]; | ||
|
||
uint256 subscriberGasLimit = block.gaslimit.calculatePortion(BLOCK_LIMIT_BPS); | ||
try _subscriber.notifyUnsubscribe{gas: subscriberGasLimit}(tokenId, config, data) {} catch {} | ||
if (address(_subscriber).code.length > 0) { | ||
uint256 subscriberGasLimit = block.gaslimit.calculatePortion(BLOCK_LIMIT_BPS); | ||
|
||
// require that the remaining gas is sufficient to notify the subscriber | ||
// otherwise, users can select a gas limit where .notifyUnsubscribe hits OutOfGas yet the transaction/unsubscription | ||
// can still succeed | ||
saucepoint marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// to account for EIP-150, condition could be 64 * gasleft() / 63 <= subscriberGasLimit | ||
if ((64 * gasleft() / 63) < subscriberGasLimit) GasLimitTooLow.selector.revertWith(); | ||
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. in core we dont bother with the *64/63. Theres just a comment about it thoughts? 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. agree |
||
try _subscriber.notifyUnsubscribe{gas: subscriberGasLimit}(tokenId, config, data) {} catch {} | ||
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. need extra eyes on this (and the natspec) feels weirdly unintuitive that users may need to specify a very high gas limit on 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. yeah it means that all users will have to send in |
||
} | ||
|
||
emit Unsubscribed(tokenId, address(_subscriber)); | ||
} | ||
|
@@ -106,6 +115,7 @@ abstract contract Notifier is INotifier { | |
} | ||
|
||
function _call(address target, bytes memory encodedCall) internal returns (bool success) { | ||
if (target.code.length == 0) NoCodeSubscriber.selector.revertWith(); | ||
assembly ("memory-safe") { | ||
success := call(gas(), target, 0, add(encodedCall, 0x20), mload(encodedCall), 0, 0) | ||
} | ||
|
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.
i see that this check makes sense, surprised it wasnt here before
doesnt one of these issues say to add it? i cant find it
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.
I think it may make more sense to check _postionConfigs().hasSubscriber? i guess see if its cheaper in the case where they do have a subscriber?
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.
yep looked like .hasSubscriber() was slightly cheaper! refactored it