Browse Source

Add proper revert message on overflow of totalSupply during burn (#3144)

Hadrien Croubois 3 years ago
parent
commit
574f3b89e1
1 changed files with 7 additions and 1 deletions
  1. 7 1
      contracts/token/ERC1155/extensions/ERC1155Supply.sol

+ 7 - 1
contracts/token/ERC1155/extensions/ERC1155Supply.sol

@@ -51,7 +51,13 @@ abstract contract ERC1155Supply is ERC1155 {
 
 
         if (to == address(0)) {
         if (to == address(0)) {
             for (uint256 i = 0; i < ids.length; ++i) {
             for (uint256 i = 0; i < ids.length; ++i) {
-                _totalSupply[ids[i]] -= amounts[i];
+                uint256 id = ids[i];
+                uint256 amount = amounts[i];
+                uint256 supply = _totalSupply[id];
+                require(supply >= amount, "ERC1155: burn amount exceeds totalSupply");
+                unchecked {
+                    _totalSupply[id] = supply - amount;
+                }
             }
             }
         }
         }
     }
     }