diff --git a/src/TwabController.sol b/src/TwabController.sol index d53d41d..9ebf77c 100644 --- a/src/TwabController.sol +++ b/src/TwabController.sol @@ -18,9 +18,13 @@ error PeriodLengthTooShort(); /// @param periodOffset The period offset that was passed in error PeriodOffsetInFuture(uint48 periodOffset); +/// @notice Emitted when a user tries to mint or transfer to the zero address +error TransferToZeroAddress(); + // The minimum period length uint48 constant MINIMUM_PERIOD_LENGTH = 1 hours; +// Allows users to revoke their chances to win by delegating to the sponsorship address. address constant SPONSORSHIP_ADDRESS = address(1); /** @@ -37,8 +41,6 @@ address constant SPONSORSHIP_ADDRESS = address(1); */ contract TwabController { using SafeCast for uint256; - - /// @notice Allows users to revoke their chances to win by delegating to the sponsorship address. /// @notice Sets the minimum period length for Observations. When a period elapses, a new Observation is recorded, otherwise the most recent Observation is updated. uint48 public immutable PERIOD_LENGTH; @@ -447,6 +449,9 @@ contract TwabController { * @param _amount The amount to mint */ function mint(address _to, uint112 _amount) external { + if (_to == address(0)) { + revert TransferToZeroAddress(); + } _transferBalance(msg.sender, address(0), _to, _amount); } @@ -471,6 +476,9 @@ contract TwabController { * @param _amount The amount to transfer */ function transfer(address _from, address _to, uint112 _amount) external { + if (_to == address(0)) { + revert TransferToZeroAddress(); + } _transferBalance(msg.sender, _from, _to, _amount); } diff --git a/test/TwabController.t.sol b/test/TwabController.t.sol index f0eeb6a..8acee6d 100644 --- a/test/TwabController.t.sol +++ b/test/TwabController.t.sol @@ -11,6 +11,7 @@ import { MINIMUM_PERIOD_LENGTH, PeriodLengthTooShort, SPONSORSHIP_ADDRESS, + TransferToZeroAddress, PeriodOffsetInFuture } from "../src/TwabController.sol"; import { @@ -735,6 +736,23 @@ contract TwabControllerTest is BaseTest { assertEq(twabController.delegateOf(mockVault, alice), bob); } + function testMint_toZero() public { + vm.startPrank(mockVault); + + uint96 _amount = 1000e18; + vm.expectRevert(abi.encodeWithSelector(TransferToZeroAddress.selector)); + twabController.mint(address(0), _amount); + } + + function testTransfer_toZero() public { + vm.startPrank(mockVault); + + uint96 _amount = 1000e18; + twabController.mint(alice, _amount); + vm.expectRevert(abi.encodeWithSelector(TransferToZeroAddress.selector)); + twabController.transfer(alice, address(0), _amount); + } + function testDelegate_toSelf() public { vm.startPrank(mockVault);