From 574f3b89e1b94bdf932957a65d40fa252508e9af Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Tue, 1 Feb 2022 23:10:11 +0100 Subject: [PATCH] Add proper revert message on overflow of totalSupply during burn (#3144) --- contracts/token/ERC1155/extensions/ERC1155Supply.sol | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/contracts/token/ERC1155/extensions/ERC1155Supply.sol b/contracts/token/ERC1155/extensions/ERC1155Supply.sol index 822c3bb0e..5caa52726 100644 --- a/contracts/token/ERC1155/extensions/ERC1155Supply.sol +++ b/contracts/token/ERC1155/extensions/ERC1155Supply.sol @@ -51,7 +51,13 @@ abstract contract ERC1155Supply is ERC1155 { if (to == address(0)) { 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; + } } } }