@@ -251,10 +251,10 @@ abstract contract DN404 {
251
251
DN404Storage storage $ = _getDN404Storage ();
252
252
253
253
unchecked {
254
- if (_unit () - 1 >= 2 ** 96 - 1 ) revert InvalidUnit ( );
254
+ if (_unit () - 1 >= 2 ** 96 - 1 ) _rv ( uint32 (InvalidUnit. selector ) );
255
255
}
256
- if ($.mirrorERC721 != address (0 )) revert DNAlreadyInitialized ( );
257
- if (mirror == address (0 )) revert MirrorAddressIsZero ( );
256
+ if ($.mirrorERC721 != address (0 )) _rv ( uint32 (DNAlreadyInitialized. selector ) );
257
+ if (mirror == address (0 )) _rv ( uint32 (MirrorAddressIsZero. selector ) );
258
258
259
259
/// @solidity memory-safe-assembly
260
260
assembly {
@@ -278,8 +278,10 @@ abstract contract DN404 {
278
278
$.mirrorERC721 = mirror;
279
279
280
280
if (initialTokenSupply != 0 ) {
281
- if (initialSupplyOwner == address (0 )) revert TransferToZeroAddress ();
282
- if (_totalSupplyOverflows (initialTokenSupply)) revert TotalSupplyOverflow ();
281
+ if (initialSupplyOwner == address (0 )) _rv (uint32 (TransferToZeroAddress.selector ));
282
+ if (_totalSupplyOverflows (initialTokenSupply)) {
283
+ _rv (uint32 (TotalSupplyOverflow.selector ));
284
+ }
283
285
284
286
$.totalSupply = uint96 (initialTokenSupply);
285
287
AddressData storage initialOwnerAddressData = $.addressData[initialSupplyOwner];
@@ -456,7 +458,7 @@ abstract contract DN404 {
456
458
== uint256 (0 ) ? type (uint256 ).max : a.value;
457
459
458
460
if (allowed != type (uint256 ).max) {
459
- if (amount > allowed) revert InsufficientAllowance ( );
461
+ if (amount > allowed) _rv ( uint32 (InsufficientAllowance. selector ) );
460
462
unchecked {
461
463
a.value = allowed - amount;
462
464
}
@@ -502,10 +504,10 @@ abstract contract DN404 {
502
504
///
503
505
/// Emits a {Transfer} event.
504
506
function _mint (address to , uint256 amount ) internal virtual {
505
- if (to == address (0 )) revert TransferToZeroAddress ( );
507
+ if (to == address (0 )) _rv ( uint32 (TransferToZeroAddress. selector ) );
506
508
507
509
DN404Storage storage $ = _getDN404Storage ();
508
- if ($.mirrorERC721 == address (0 )) revert DNNotInitialized ( );
510
+ if ($.mirrorERC721 == address (0 )) _rv ( uint32 (DNNotInitialized. selector ) );
509
511
AddressData storage toAddressData = $.addressData[to];
510
512
511
513
_DNMintTemps memory t;
@@ -520,7 +522,9 @@ abstract contract DN404 {
520
522
uint256 newTotalSupply = uint256 ($.totalSupply) + amount;
521
523
$.totalSupply = uint96 (newTotalSupply);
522
524
uint256 overflows = _toUint (_totalSupplyOverflows (newTotalSupply));
523
- if (overflows | _toUint (newTotalSupply < amount) != 0 ) revert TotalSupplyOverflow ();
525
+ if (overflows | _toUint (newTotalSupply < amount) != 0 ) {
526
+ _rv (uint32 (TotalSupplyOverflow.selector ));
527
+ }
524
528
idLimit = newTotalSupply / _unit ();
525
529
}
526
530
while (! getSkipNFT (to)) {
@@ -594,10 +598,10 @@ abstract contract DN404 {
594
598
///
595
599
/// Emits a {Transfer} event.
596
600
function _mintNext (address to , uint256 amount ) internal virtual {
597
- if (to == address (0 )) revert TransferToZeroAddress ( );
601
+ if (to == address (0 )) _rv ( uint32 (TransferToZeroAddress. selector ) );
598
602
599
603
DN404Storage storage $ = _getDN404Storage ();
600
- if ($.mirrorERC721 == address (0 )) revert DNNotInitialized ( );
604
+ if ($.mirrorERC721 == address (0 )) _rv ( uint32 (DNNotInitialized. selector ) );
601
605
AddressData storage toAddressData = $.addressData[to];
602
606
603
607
_DNMintTemps memory t;
@@ -614,7 +618,9 @@ abstract contract DN404 {
614
618
uint256 newTotalSupply = uint256 (preTotalSupply) + amount;
615
619
$.totalSupply = uint96 (newTotalSupply);
616
620
uint256 overflows = _toUint (_totalSupplyOverflows (newTotalSupply));
617
- if (overflows | _toUint (newTotalSupply < amount) != 0 ) revert TotalSupplyOverflow ();
621
+ if (overflows | _toUint (newTotalSupply < amount) != 0 ) {
622
+ _rv (uint32 (TotalSupplyOverflow.selector ));
623
+ }
618
624
idLimit = newTotalSupply / _unit ();
619
625
id = _wrapNFTId (preTotalSupply / _unit () + _toUint (_useOneIndexed ()), idLimit);
620
626
}
@@ -677,14 +683,14 @@ abstract contract DN404 {
677
683
/// Emits a {Transfer} event.
678
684
function _burn (address from , uint256 amount ) internal virtual {
679
685
DN404Storage storage $ = _getDN404Storage ();
680
- if ($.mirrorERC721 == address (0 )) revert DNNotInitialized ( );
686
+ if ($.mirrorERC721 == address (0 )) _rv ( uint32 (DNNotInitialized. selector ) );
681
687
682
688
AddressData storage fromAddressData = $.addressData[from];
683
689
_DNBurnTemps memory t;
684
690
685
691
unchecked {
686
692
t.fromBalance = fromAddressData.balance;
687
- if (amount > t.fromBalance) revert InsufficientBalance ( );
693
+ if (amount > t.fromBalance) _rv ( uint32 (InsufficientBalance. selector ) );
688
694
689
695
fromAddressData.balance = uint96 (t.fromBalance -= amount);
690
696
t.totalSupply = uint256 ($.totalSupply) - amount;
@@ -755,12 +761,12 @@ abstract contract DN404 {
755
761
///
756
762
/// Emits a {Transfer} event.
757
763
function _transfer (address from , address to , uint256 amount ) internal virtual {
758
- if (to == address (0 )) revert TransferToZeroAddress ( );
764
+ if (to == address (0 )) _rv ( uint32 (TransferToZeroAddress. selector ) );
759
765
760
766
DN404Storage storage $ = _getDN404Storage ();
761
767
AddressData storage fromAddressData = $.addressData[from];
762
768
AddressData storage toAddressData = $.addressData[to];
763
- if ($.mirrorERC721 == address (0 )) revert DNNotInitialized ( );
769
+ if ($.mirrorERC721 == address (0 )) _rv ( uint32 (DNNotInitialized. selector ) );
764
770
765
771
_DNTransferTemps memory t;
766
772
t.fromOwnedLength = fromAddressData.ownedLength;
@@ -769,7 +775,7 @@ abstract contract DN404 {
769
775
unchecked {
770
776
{
771
777
uint256 fromBalance = fromAddressData.balance;
772
- if (amount > fromBalance) revert InsufficientBalance ( );
778
+ if (amount > fromBalance) _rv ( uint32 (InsufficientBalance. selector ) );
773
779
fromAddressData.balance = uint96 (fromBalance -= amount);
774
780
775
781
uint256 toBalance = uint256 (toAddressData.balance) + amount;
@@ -947,21 +953,21 @@ abstract contract DN404 {
947
953
internal
948
954
virtual
949
955
{
950
- if (to == address (0 )) revert TransferToZeroAddress ( );
956
+ if (to == address (0 )) _rv ( uint32 (TransferToZeroAddress. selector ) );
951
957
952
958
DN404Storage storage $ = _getDN404Storage ();
953
- if ($.mirrorERC721 == address (0 )) revert DNNotInitialized ( );
959
+ if ($.mirrorERC721 == address (0 )) _rv ( uint32 (DNNotInitialized. selector ) );
954
960
955
961
Uint32Map storage oo = $.oo;
956
962
957
963
if (from != $.aliasToAddress[_get (oo, _ownershipIndex (_restrictNFTId (id)))]) {
958
- revert TransferFromIncorrectOwner ( );
964
+ _rv ( uint32 (TransferFromIncorrectOwner. selector ) );
959
965
}
960
966
961
967
if (msgSender != from) {
962
968
if (! _isApprovedForAll (from, msgSender)) {
963
969
if (_getApproved (id) != msgSender) {
964
- revert TransferCallerNotOwnerNorApproved ( );
970
+ _rv ( uint32 (TransferCallerNotOwnerNorApproved. selector ) );
965
971
}
966
972
}
967
973
}
@@ -974,7 +980,7 @@ abstract contract DN404 {
974
980
975
981
unchecked {
976
982
uint256 fromBalance = fromAddressData.balance;
977
- if (unit > fromBalance) revert InsufficientBalance ( );
983
+ if (unit > fromBalance) _rv ( uint32 (InsufficientBalance. selector ) );
978
984
fromAddressData.balance = uint96 (fromBalance - unit);
979
985
toAddressData.balance += uint96 (unit);
980
986
}
@@ -1144,7 +1150,7 @@ abstract contract DN404 {
1144
1150
/// Requirements:
1145
1151
/// - Token `id` must exist.
1146
1152
function _ownerOf (uint256 id ) internal view virtual returns (address ) {
1147
- if (! _exists (id)) revert TokenDoesNotExist ( );
1153
+ if (! _exists (id)) _rv ( uint32 (TokenDoesNotExist. selector ) );
1148
1154
return _ownerAt (id);
1149
1155
}
1150
1156
@@ -1168,7 +1174,7 @@ abstract contract DN404 {
1168
1174
/// Requirements:
1169
1175
/// - Token `id` must exist.
1170
1176
function _getApproved (uint256 id ) internal view virtual returns (address ) {
1171
- if (! _exists (id)) revert TokenDoesNotExist ( );
1177
+ if (! _exists (id)) _rv ( uint32 (TokenDoesNotExist. selector ) );
1172
1178
return _getDN404Storage ().nftApprovals[id];
1173
1179
}
1174
1180
@@ -1187,7 +1193,7 @@ abstract contract DN404 {
1187
1193
1188
1194
if (msgSender != owner) {
1189
1195
if (! _isApprovedForAll (owner, msgSender)) {
1190
- revert ApprovalCallerNotOwnerNorApproved ( );
1196
+ _rv ( uint32 (ApprovalCallerNotOwnerNorApproved. selector ) );
1191
1197
}
1192
1198
}
1193
1199
@@ -1240,7 +1246,7 @@ abstract contract DN404 {
1240
1246
1241
1247
// `transferFromNFT(address,address,uint256,address)`.
1242
1248
if (fnSelector == 0xe5eb36c8 ) {
1243
- if (msg .sender != $.mirrorERC721) revert SenderNotMirror ( );
1249
+ if (msg .sender != $.mirrorERC721) _rv ( uint32 (SenderNotMirror. selector ) );
1244
1250
_transferFromNFT (
1245
1251
address (uint160 (_calldataload (0x04 ))), // `from`.
1246
1252
address (uint160 (_calldataload (0x24 ))), // `to`.
@@ -1251,7 +1257,7 @@ abstract contract DN404 {
1251
1257
}
1252
1258
// `setApprovalForAllNFT(address,bool,address)`.
1253
1259
if (fnSelector == 0xf6916ddd ) {
1254
- if (msg .sender != $.mirrorERC721) revert SenderNotMirror ( );
1260
+ if (msg .sender != $.mirrorERC721) _rv ( uint32 (SenderNotMirror. selector ) );
1255
1261
_setApprovalForAll (
1256
1262
address (uint160 (_calldataload (0x04 ))), // `spender`.
1257
1263
_calldataload (0x24 ) != 0 , // `status`.
@@ -1277,7 +1283,7 @@ abstract contract DN404 {
1277
1283
}
1278
1284
// `approveNFT(address,uint256,address)`.
1279
1285
if (fnSelector == 0xd10b6e0c ) {
1280
- if (msg .sender != $.mirrorERC721) revert SenderNotMirror ( );
1286
+ if (msg .sender != $.mirrorERC721) _rv ( uint32 (SenderNotMirror. selector ) );
1281
1287
address owner = _approveNFT (
1282
1288
address (uint160 (_calldataload (0x04 ))), // `spender`.
1283
1289
_calldataload (0x24 ), // `id`.
@@ -1326,7 +1332,7 @@ abstract contract DN404 {
1326
1332
/// fallback with utilities like Solady's `LibZip.cdFallback()`.
1327
1333
/// And always remember to always wrap the fallback with `dn404Fallback`.
1328
1334
fallback () external payable virtual dn404Fallback {
1329
- revert FnSelectorNotRecognized ( ); // Not mandatory. Just for quality of life.
1335
+ _rv ( uint32 (FnSelectorNotRecognized. selector ) ); // Not mandatory. Just for quality of life.
1330
1336
}
1331
1337
1332
1338
/// @dev This is to silence the compiler warning.
@@ -1787,4 +1793,13 @@ abstract contract DN404 {
1787
1793
return (0x00 , 0x20 )
1788
1794
}
1789
1795
}
1796
+
1797
+ /// @dev More bytecode-efficient way to revert.
1798
+ function _rv (uint32 s ) private pure {
1799
+ /// @solidity memory-safe-assembly
1800
+ assembly {
1801
+ mstore (0x00 , s)
1802
+ revert (0x1c , 0x04 )
1803
+ }
1804
+ }
1790
1805
}
0 commit comments