Skip to content

Commit

Permalink
refactor!: Optional LSP1 Notification on revokeOperator(..) (#763)
Browse files Browse the repository at this point in the history
* refactor!: make notification optional in revokeOperator

* test: adjust the tests accordingly

* docs: generate docs

* chore: add override keyword

* chore: fix lsp7compatibleERC20

* refactor: include authorization status bool in lsp1 data in LSP8

* refactor!: allow increase allowance only when allowance > 0

* test: adjust the tests accoridngly

* docs: generate docs

* docs: generate docs
  • Loading branch information
YamenMerhi authored Oct 27, 2023
1 parent d0543fb commit 63c1a0f
Show file tree
Hide file tree
Showing 31 changed files with 753 additions and 853 deletions.
4 changes: 2 additions & 2 deletions constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export const INTERFACE_IDS = {
LSP1UniversalReceiver: '0x6bb56a14',
LSP1UniversalReceiverDelegate: '0xa245bbda',
LSP6KeyManager: '0x23f34c62',
LSP7DigitalAsset: '0x05519512',
LSP8IdentifiableDigitalAsset: '0x1ae9ba1f',
LSP7DigitalAsset: '0xdaa746b7',
LSP8IdentifiableDigitalAsset: '0x30dc5278',
LSP9Vault: '0x28af17e6',
LSP11BasicSocialRecovery: '0x049a28f1',
LSP14Ownable2Step: '0x94be5999',
Expand Down
60 changes: 60 additions & 0 deletions contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
* @dev Emitted when `tokenOwner` disables `operator` for `amount` tokens and set its {`authorizedAmountFor(...)`} to `0`.
* @param operator The address revoked from operating
* @param tokenOwner The token owner
* @param notified Bool indicating whether the operator has been notified or not
* @param operatorNotificationData The data to notify the operator about via LSP1.
*/
event RevokedOperator(
address indexed operator,
address indexed tokenOwner,
bool notified,
bytes operatorNotificationData
);

Expand Down Expand Up @@ -101,6 +103,7 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {

/**
* @dev Sets an `amount` of tokens that an `operator` has access from the caller's balance (allowance). See {authorizedAmountFor}.
* Notify the operator based on the LSP1-UniversalReceiver standard
*
* @param operator The address to authorize as an operator.
* @param amount The allowance amount of tokens operator has access to.
Expand All @@ -123,6 +126,7 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
* on behalf of the token owner (the caller of the function `msg.sender`). See also {authorizedAmountFor}.
*
* @param operator The address to revoke as an operator.
* @param notify Boolean indicating whether to notify the operator or not
* @param operatorNotificationData The data to notify the operator about via LSP1.
*
* @custom:requirements
Expand All @@ -133,6 +137,62 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
*/
function revokeOperator(
address operator,
bool notify,
bytes memory operatorNotificationData
) external;

/**
* @custom:info This function in the LSP7 contract can be used as a prevention mechanism
* against double spending allowance vulnerability.
*
* @notice Increase the allowance of `operator` by +`addedAmount`
*
* @dev Atomically increases the allowance granted to `operator` by the caller.
* This is an alternative approach to {authorizeOperator} that can be used as a mitigation
* for the double spending allowance problem.
* Notify the operator based on the LSP1-UniversalReceiver standard
*
* @param operator The operator to increase the allowance for `msg.sender`
* @param addedAmount The additional amount to add on top of the current operator's allowance
*
* @custom:requirements
* - `operator` cannot be the same address as `msg.sender`
* - `operator` cannot be the zero address.
*
* @custom:events {AuthorizedOperator} indicating the updated allowance
*/
function increaseAllowance(
address operator,
uint256 addedAmount,
bytes memory operatorNotificationData
) external;

/**
* @custom:info This function in the LSP7 contract can be used as a prevention mechanism
* against the double spending allowance vulnerability.
*
* @notice Decrease the allowance of `operator` by -`subtractedAmount`
*
* @dev Atomically decreases the allowance granted to `operator` by the caller.
* This is an alternative approach to {authorizeOperator} that can be used as a mitigation
* for the double spending allowance problem.
* Notify the operator based on the LSP1-UniversalReceiver standard
*
* @custom:events
* - {AuthorizedOperator} event indicating the updated allowance after decreasing it.
* - {RevokeOperator} event if `subtractedAmount` is the full allowance,
* indicating `operator` does not have any alauthorizedAmountForlowance left for `msg.sender`.
*
* @param operator The operator to decrease allowance for `msg.sender`
* @param subtractedAmount The amount to decrease by in the operator's allowance.
*
* @custom:requirements
* - `operator` cannot be the zero address.
* - `operator` must have allowance for the caller of at least `subtractedAmount`.
*/
function decreaseAllowance(
address operator,
uint256 subtractedAmount,
bytes memory operatorNotificationData
) external;

Expand Down
2 changes: 1 addition & 1 deletion contracts/LSP7DigitalAsset/LSP7Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.4;

// --- ERC165 interface ids
bytes4 constant _INTERFACEID_LSP7 = 0x05519512;
bytes4 constant _INTERFACEID_LSP7 = 0xdaa746b7;

// --- Token Hooks

Expand Down
Loading

0 comments on commit 63c1a0f

Please sign in to comment.