From 139363f8e476da7ce604b0e06a87bb06c4bd1ddb Mon Sep 17 00:00:00 2001 From: Pascal Marco Caversaccio Date: Fri, 13 Jan 2023 21:23:05 +0100 Subject: [PATCH 01/17] Fix wrong PR `CHANGELOG` link (#3957) --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b21c1d6189..cf30caf0de9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,7 +53,7 @@ function supportsInterface(bytes4 interfaceId) public view virtual override retu * `Math`: optimize `log256` rounding check. ([#3745](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3745)) * `Strings`: add `equal` method. ([#3774](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3774)) * `Strings`: add `toString` method for signed integers. ([#3773](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3773)) - * `MerkleProof`: optimize by using unchecked arithmetic. ([#3745](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3745)) + * `MerkleProof`: optimize by using unchecked arithmetic. ([#3869](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3869)) * `EnumerableMap`: add a `keys()` function that returns an array containing all the keys. ([#3920](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3920)) ### Deprecations From 39025145931e762c17f443509bd391c488168d1d Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Mon, 16 Jan 2023 15:34:19 -0400 Subject: [PATCH 02/17] update contract --- .../token/ERC1155/extensions/ERC1155Supply.sol | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/contracts/token/ERC1155/extensions/ERC1155Supply.sol b/contracts/token/ERC1155/extensions/ERC1155Supply.sol index 77690b59d0a..765814813d3 100644 --- a/contracts/token/ERC1155/extensions/ERC1155Supply.sol +++ b/contracts/token/ERC1155/extensions/ERC1155Supply.sol @@ -15,6 +15,7 @@ import "../ERC1155.sol"; */ abstract contract ERC1155Supply is ERC1155 { mapping(uint256 => uint256) private _totalSupply; + uint256 private _totalSupplyAll; /** * @dev Total amount of tokens in with a given id. @@ -23,6 +24,13 @@ abstract contract ERC1155Supply is ERC1155 { return _totalSupply[id]; } + /** + * @dev Total amount of tokens. + */ + function totalSupply() public view virtual returns (uint256) { + return _totalSupplyAll; + } + /** * @dev Indicates whether any token exist with a given id, or not. */ @@ -40,10 +48,13 @@ abstract contract ERC1155Supply is ERC1155 { uint256[] memory amounts, bytes memory data ) internal virtual override { + uint256 totalAmount; if (from == address(0)) { for (uint256 i = 0; i < ids.length; ++i) { _totalSupply[ids[i]] += amounts[i]; + totalAmount += amounts[i]; } + _totalSupplyAll += totalAmount; } if (to == address(0)) { @@ -54,8 +65,10 @@ abstract contract ERC1155Supply is ERC1155 { require(supply >= amount, "ERC1155: burn amount exceeds totalSupply"); unchecked { _totalSupply[id] = supply - amount; + totalAmount += amount; } } + _totalSupplyAll -= totalAmount; } super._update(from, to, ids, amounts, data); } From 7a267c7f6b9d8f1e779aedc9cb16dc1071522b5e Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Mon, 16 Jan 2023 16:01:09 -0400 Subject: [PATCH 03/17] add tests for the new function --- .../ERC1155/extensions/ERC1155Supply.test.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/test/token/ERC1155/extensions/ERC1155Supply.test.js b/test/token/ERC1155/extensions/ERC1155Supply.test.js index 721d5a782ee..37fc719c843 100644 --- a/test/token/ERC1155/extensions/ERC1155Supply.test.js +++ b/test/token/ERC1155/extensions/ERC1155Supply.test.js @@ -25,7 +25,8 @@ contract('ERC1155Supply', function (accounts) { }); it('totalSupply', async function () { - expect(await this.token.totalSupply(firstTokenId)).to.be.bignumber.equal('0'); + expect(await this.token.methods['totalSupply(uint256)'](firstTokenId)).to.be.bignumber.equal('0'); + expect(await this.token.methods['totalSupply()']()).to.be.bignumber.equal('0'); }); }); @@ -40,7 +41,8 @@ contract('ERC1155Supply', function (accounts) { }); it('totalSupply', async function () { - expect(await this.token.totalSupply(firstTokenId)).to.be.bignumber.equal(firstTokenAmount); + expect(await this.token.methods['totalSupply(uint256)'](firstTokenId)).to.be.bignumber.equal(firstTokenAmount); + expect(await this.token.methods['totalSupply()']()).to.be.bignumber.equal(firstTokenAmount); }); }); @@ -60,8 +62,9 @@ contract('ERC1155Supply', function (accounts) { }); it('totalSupply', async function () { - expect(await this.token.totalSupply(firstTokenId)).to.be.bignumber.equal(firstTokenAmount); - expect(await this.token.totalSupply(secondTokenId)).to.be.bignumber.equal(secondTokenAmount); + expect(await this.token.methods['totalSupply(uint256)'](firstTokenId)).to.be.bignumber.equal(firstTokenAmount); + expect(await this.token.methods['totalSupply(uint256)'](secondTokenId)).to.be.bignumber.equal(secondTokenAmount); + expect(await this.token.methods['totalSupply()']()).to.be.bignumber.equal(firstTokenAmount.add(secondTokenAmount)); }); }); }); @@ -78,7 +81,8 @@ contract('ERC1155Supply', function (accounts) { }); it('totalSupply', async function () { - expect(await this.token.totalSupply(firstTokenId)).to.be.bignumber.equal('0'); + expect(await this.token.methods['totalSupply(uint256)'](firstTokenId)).to.be.bignumber.equal('0'); + expect(await this.token.methods['totalSupply()']()).to.be.bignumber.equal('0'); }); }); @@ -99,8 +103,9 @@ contract('ERC1155Supply', function (accounts) { }); it('totalSupply', async function () { - expect(await this.token.totalSupply(firstTokenId)).to.be.bignumber.equal('0'); - expect(await this.token.totalSupply(secondTokenId)).to.be.bignumber.equal('0'); + expect(await this.token.methods['totalSupply(uint256)'](firstTokenId)).to.be.bignumber.equal('0'); + expect(await this.token.methods['totalSupply(uint256)'](secondTokenId)).to.be.bignumber.equal('0'); + expect(await this.token.methods['totalSupply()']()).to.be.bignumber.equal('0'); }); }); }); From 17de1d95730444cd86df387d75b9d0942819279f Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Mon, 16 Jan 2023 16:09:37 -0400 Subject: [PATCH 04/17] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf30caf0de9..20fb9333adc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ function supportsInterface(bytes4 interfaceId) public view virtual override retu * `Strings`: add `toString` method for signed integers. ([#3773](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3773)) * `MerkleProof`: optimize by using unchecked arithmetic. ([#3869](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3869)) * `EnumerableMap`: add a `keys()` function that returns an array containing all the keys. ([#3920](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3920)) + * `ERC1155Supply`: add a `totalSupply()` function that returns the total amount of token circulating. ([#3962](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3962)) ### Deprecations From 3776289bb737bb7c6b991e5ab064ccf55d9d6823 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Mon, 16 Jan 2023 16:09:57 -0400 Subject: [PATCH 05/17] update tests format --- test/token/ERC1155/extensions/ERC1155Supply.test.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/token/ERC1155/extensions/ERC1155Supply.test.js b/test/token/ERC1155/extensions/ERC1155Supply.test.js index 37fc719c843..243a2724ed7 100644 --- a/test/token/ERC1155/extensions/ERC1155Supply.test.js +++ b/test/token/ERC1155/extensions/ERC1155Supply.test.js @@ -63,8 +63,12 @@ contract('ERC1155Supply', function (accounts) { it('totalSupply', async function () { expect(await this.token.methods['totalSupply(uint256)'](firstTokenId)).to.be.bignumber.equal(firstTokenAmount); - expect(await this.token.methods['totalSupply(uint256)'](secondTokenId)).to.be.bignumber.equal(secondTokenAmount); - expect(await this.token.methods['totalSupply()']()).to.be.bignumber.equal(firstTokenAmount.add(secondTokenAmount)); + expect(await this.token.methods['totalSupply(uint256)'](secondTokenId)).to.be.bignumber.equal( + secondTokenAmount, + ); + expect(await this.token.methods['totalSupply()']()).to.be.bignumber.equal( + firstTokenAmount.add(secondTokenAmount), + ); }); }); }); From 154605d324bdbbcde040a8c6813c6800ef55e0d3 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Tue, 17 Jan 2023 10:29:36 -0400 Subject: [PATCH 06/17] Add test case --- .../token/ERC1155/extensions/ERC1155Supply.sol | 18 +++++++++++------- .../ERC1155/extensions/ERC1155Supply.test.js | 13 ++++++++++++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/contracts/token/ERC1155/extensions/ERC1155Supply.sol b/contracts/token/ERC1155/extensions/ERC1155Supply.sol index 765814813d3..eef4ff1c0a8 100644 --- a/contracts/token/ERC1155/extensions/ERC1155Supply.sol +++ b/contracts/token/ERC1155/extensions/ERC1155Supply.sol @@ -15,7 +15,7 @@ import "../ERC1155.sol"; */ abstract contract ERC1155Supply is ERC1155 { mapping(uint256 => uint256) private _totalSupply; - uint256 private _totalSupplyAll; + uint private _totalSupplyAll; /** * @dev Total amount of tokens in with a given id. @@ -48,16 +48,18 @@ abstract contract ERC1155Supply is ERC1155 { uint256[] memory amounts, bytes memory data ) internal virtual override { - uint256 totalAmount; if (from == address(0)) { + uint256 totalMintAmount = 0; for (uint256 i = 0; i < ids.length; ++i) { - _totalSupply[ids[i]] += amounts[i]; - totalAmount += amounts[i]; + uint256 amount = amounts[i]; + _totalSupply[ids[i]] += amount; + totalMintAmount += amount; } - _totalSupplyAll += totalAmount; + _totalSupplyAll += totalMintAmount; } if (to == address(0)) { + uint256 totalBurnAmount = 0; for (uint256 i = 0; i < ids.length; ++i) { uint256 id = ids[i]; uint256 amount = amounts[i]; @@ -65,10 +67,12 @@ abstract contract ERC1155Supply is ERC1155 { require(supply >= amount, "ERC1155: burn amount exceeds totalSupply"); unchecked { _totalSupply[id] = supply - amount; - totalAmount += amount; + totalBurnAmount += amount; } } - _totalSupplyAll -= totalAmount; + unchecked { + _totalSupplyAll -= totalBurnAmount; + } } super._update(from, to, ids, amounts, data); } diff --git a/test/token/ERC1155/extensions/ERC1155Supply.test.js b/test/token/ERC1155/extensions/ERC1155Supply.test.js index 243a2724ed7..f05751dde38 100644 --- a/test/token/ERC1155/extensions/ERC1155Supply.test.js +++ b/test/token/ERC1155/extensions/ERC1155Supply.test.js @@ -1,7 +1,9 @@ -const { BN } = require('@openzeppelin/test-helpers'); +const { BN, constants } = require('@openzeppelin/test-helpers'); const { expect } = require('chai'); +const { ZERO_ADDRESS } = constants; + const ERC1155Supply = artifacts.require('$ERC1155Supply'); contract('ERC1155Supply', function (accounts) { @@ -113,4 +115,13 @@ contract('ERC1155Supply', function (accounts) { }); }); }); + + context('total supply of token', function () { + it('totalSupply unaffected by no-op', async function () { + this.token.safeTransferFrom(ZERO_ADDRESS, ZERO_ADDRESS, firstTokenId, firstTokenAmount, '0x', { + from: ZERO_ADDRESS, + }); + expect(await this.token.methods['totalSupply()']()).to.be.bignumber.equal('0'); + }); + }); }); From 4dae02cff495b7e0a03dd7ccfb7701c4c632b126 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Tue, 17 Jan 2023 14:11:38 -0400 Subject: [PATCH 07/17] update changelog --- CHANGELOG.md | 2 +- contracts/token/ERC1155/extensions/ERC1155Supply.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20fb9333adc..9e65af19d4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,7 +55,7 @@ function supportsInterface(bytes4 interfaceId) public view virtual override retu * `Strings`: add `toString` method for signed integers. ([#3773](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3773)) * `MerkleProof`: optimize by using unchecked arithmetic. ([#3869](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3869)) * `EnumerableMap`: add a `keys()` function that returns an array containing all the keys. ([#3920](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3920)) - * `ERC1155Supply`: add a `totalSupply()` function that returns the total amount of token circulating. ([#3962](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3962)) + * `ERC1155Supply`: add a `totalSupply()` function that returns the total amount of token circulating, this change will restrict the total tokens minted accross all ids to 2**256-1 . ([#3962](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3962)) ### Deprecations diff --git a/contracts/token/ERC1155/extensions/ERC1155Supply.sol b/contracts/token/ERC1155/extensions/ERC1155Supply.sol index eef4ff1c0a8..21cf82181b5 100644 --- a/contracts/token/ERC1155/extensions/ERC1155Supply.sol +++ b/contracts/token/ERC1155/extensions/ERC1155Supply.sol @@ -15,7 +15,7 @@ import "../ERC1155.sol"; */ abstract contract ERC1155Supply is ERC1155 { mapping(uint256 => uint256) private _totalSupply; - uint private _totalSupplyAll; + uint256 private _totalSupplyAll; /** * @dev Total amount of tokens in with a given id. From a27ba26bd9a5437c6fdfb11bdbe2185ea5f8b618 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Tue, 17 Jan 2023 14:15:10 -0400 Subject: [PATCH 08/17] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e65af19d4f..ab67ba8407c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,7 +55,7 @@ function supportsInterface(bytes4 interfaceId) public view virtual override retu * `Strings`: add `toString` method for signed integers. ([#3773](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3773)) * `MerkleProof`: optimize by using unchecked arithmetic. ([#3869](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3869)) * `EnumerableMap`: add a `keys()` function that returns an array containing all the keys. ([#3920](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3920)) - * `ERC1155Supply`: add a `totalSupply()` function that returns the total amount of token circulating, this change will restrict the total tokens minted accross all ids to 2**256-1 . ([#3962](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3962)) + * `ERC1155Supply`: add a `totalSupply()` function that returns the total amount of token circulating, this change will restrict the total tokens minted across all ids to 2**256-1 . ([#3962](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3962)) ### Deprecations From 58b21c2b46ce909dbc105f1300776600b0ba8ffa Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Wed, 18 Jan 2023 08:42:26 -0400 Subject: [PATCH 09/17] move to breaking changes in the changelog --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab67ba8407c..3b8ab6181ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * `ProxyAdmin`: Removed `getProxyAdmin` and `getProxyImplementation` getters. ([#3820](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3820)) * `ERC20`, `ERC1155`: Deleted `_beforeTokenTransfer` and `_afterTokenTransfer` hooks, added a new internal `_update` function for customizations, and refactored all extensions using those hooks to use `_update` instead. ([#3838](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3838), [#3876](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3876)) * `ERC165Storage`: Removed this contract in favor of inheritance based approach. ([#3880](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3880)) + * `ERC1155Supply`: add a `totalSupply()` function that returns the total amount of token circulating, this change will restrict the total tokens minted across all ids to 2**256-1 . ([#3962](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3962)) ### How to upgrade from 4.x @@ -53,9 +54,9 @@ function supportsInterface(bytes4 interfaceId) public view virtual override retu * `Math`: optimize `log256` rounding check. ([#3745](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3745)) * `Strings`: add `equal` method. ([#3774](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3774)) * `Strings`: add `toString` method for signed integers. ([#3773](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3773)) - * `MerkleProof`: optimize by using unchecked arithmetic. ([#3869](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3869)) + * `MerkleProof`: optimize by using unchecked arithmetic. ([#3745](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3745)) * `EnumerableMap`: add a `keys()` function that returns an array containing all the keys. ([#3920](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3920)) - * `ERC1155Supply`: add a `totalSupply()` function that returns the total amount of token circulating, this change will restrict the total tokens minted across all ids to 2**256-1 . ([#3962](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3962)) + ### Deprecations From a634d589ce380598703758c4e09703e96b4e1ace Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Wed, 18 Jan 2023 10:04:45 -0400 Subject: [PATCH 10/17] add reason to unchecked code --- contracts/token/ERC1155/extensions/ERC1155Supply.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/token/ERC1155/extensions/ERC1155Supply.sol b/contracts/token/ERC1155/extensions/ERC1155Supply.sol index 21cf82181b5..eedf96e0607 100644 --- a/contracts/token/ERC1155/extensions/ERC1155Supply.sol +++ b/contracts/token/ERC1155/extensions/ERC1155Supply.sol @@ -65,6 +65,7 @@ abstract contract ERC1155Supply is ERC1155 { uint256 amount = amounts[i]; uint256 supply = _totalSupply[id]; require(supply >= amount, "ERC1155: burn amount exceeds totalSupply"); + // Overflow not possible: sum(amounts[i]) <= sum(totalSupply(i)) <= totalSupplyAll <= 2*256-1 unchecked { _totalSupply[id] = supply - amount; totalBurnAmount += amount; From d511fa68b00edd0da0a84a275b3c54cb28d8ffc2 Mon Sep 17 00:00:00 2001 From: Francisco Date: Thu, 19 Jan 2023 21:39:36 -0300 Subject: [PATCH 11/17] clean up whitespace --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b8ab6181ac..9f9f71da000 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ * `ProxyAdmin`: Removed `getProxyAdmin` and `getProxyImplementation` getters. ([#3820](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3820)) * `ERC20`, `ERC1155`: Deleted `_beforeTokenTransfer` and `_afterTokenTransfer` hooks, added a new internal `_update` function for customizations, and refactored all extensions using those hooks to use `_update` instead. ([#3838](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3838), [#3876](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3876)) * `ERC165Storage`: Removed this contract in favor of inheritance based approach. ([#3880](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3880)) - * `ERC1155Supply`: add a `totalSupply()` function that returns the total amount of token circulating, this change will restrict the total tokens minted across all ids to 2**256-1 . ([#3962](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3962)) + * `ERC1155Supply`: add a `totalSupply()` function that returns the total amount of token circulating, this change will restrict the total tokens minted across all ids to 2**256-1 . ([#3962](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3962)) ### How to upgrade from 4.x @@ -57,7 +57,6 @@ function supportsInterface(bytes4 interfaceId) public view virtual override retu * `MerkleProof`: optimize by using unchecked arithmetic. ([#3745](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3745)) * `EnumerableMap`: add a `keys()` function that returns an array containing all the keys. ([#3920](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3920)) - ### Deprecations * `ERC20Permit`: Added the file `IERC20Permit.sol` and `ERC20Permit.sol` and deprecated `draft-IERC20Permit.sol` and `draft-ERC20Permit.sol` since [EIP-2612](https://eips.ethereum.org/EIPS/eip-2612) is no longer a Draft. Developers are encouraged to update their imports. ([#3793](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3793)) From 7be1534e17e539599f5d1cf151f7e0f4b3a8ea24 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Mon, 23 Jan 2023 09:33:42 -0400 Subject: [PATCH 12/17] Update test/token/ERC1155/extensions/ERC1155Supply.test.js Co-authored-by: Francisco --- test/token/ERC1155/extensions/ERC1155Supply.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/token/ERC1155/extensions/ERC1155Supply.test.js b/test/token/ERC1155/extensions/ERC1155Supply.test.js index f05751dde38..d5a1ceabbbf 100644 --- a/test/token/ERC1155/extensions/ERC1155Supply.test.js +++ b/test/token/ERC1155/extensions/ERC1155Supply.test.js @@ -116,8 +116,8 @@ contract('ERC1155Supply', function (accounts) { }); }); - context('total supply of token', function () { - it('totalSupply unaffected by no-op', async function () { + context('other', function () { + it('supply unaffected by no-op', async function () { this.token.safeTransferFrom(ZERO_ADDRESS, ZERO_ADDRESS, firstTokenId, firstTokenAmount, '0x', { from: ZERO_ADDRESS, }); From e143fae038b660f836578598e29b383439b00f54 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Tue, 24 Jan 2023 18:27:14 -0300 Subject: [PATCH 13/17] add expect of totalSupply(uint256) --- test/token/ERC1155/extensions/ERC1155Supply.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/token/ERC1155/extensions/ERC1155Supply.test.js b/test/token/ERC1155/extensions/ERC1155Supply.test.js index d5a1ceabbbf..7c4c54dff58 100644 --- a/test/token/ERC1155/extensions/ERC1155Supply.test.js +++ b/test/token/ERC1155/extensions/ERC1155Supply.test.js @@ -116,11 +116,12 @@ contract('ERC1155Supply', function (accounts) { }); }); - context('other', function () { + context.only('other', function () { it('supply unaffected by no-op', async function () { this.token.safeTransferFrom(ZERO_ADDRESS, ZERO_ADDRESS, firstTokenId, firstTokenAmount, '0x', { from: ZERO_ADDRESS, }); + expect(await this.token.methods['totalSupply(uint256)'](firstTokenId)).to.be.bignumber.equal('0'); expect(await this.token.methods['totalSupply()']()).to.be.bignumber.equal('0'); }); }); From 737d0146c2ef070a32c2ecd63253af6f85e89395 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Tue, 24 Jan 2023 18:45:12 -0300 Subject: [PATCH 14/17] improve unchecked overflow comments --- contracts/token/ERC1155/extensions/ERC1155Supply.sol | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contracts/token/ERC1155/extensions/ERC1155Supply.sol b/contracts/token/ERC1155/extensions/ERC1155Supply.sol index eedf96e0607..6596c4aedba 100644 --- a/contracts/token/ERC1155/extensions/ERC1155Supply.sol +++ b/contracts/token/ERC1155/extensions/ERC1155Supply.sol @@ -65,13 +65,15 @@ abstract contract ERC1155Supply is ERC1155 { uint256 amount = amounts[i]; uint256 supply = _totalSupply[id]; require(supply >= amount, "ERC1155: burn amount exceeds totalSupply"); - // Overflow not possible: sum(amounts[i]) <= sum(totalSupply(i)) <= totalSupplyAll <= 2*256-1 unchecked { + // Overflow not possible: amounts[i] <= totalSupply(i) _totalSupply[id] = supply - amount; + // Overflow not possible: sum(amounts[i]) <= sum(totalSupply(i)) <= totalSupplyAll totalBurnAmount += amount; } } unchecked { + // Overflow not possible: totalBurnAmount = sum(amounts[i]) <= sum(totalSupply(i)) <= totalSupplyAll _totalSupplyAll -= totalBurnAmount; } } From 73382dfe9646c3477e562bb9013bbff4810e3467 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Tue, 24 Jan 2023 19:01:10 -0300 Subject: [PATCH 15/17] remove .only --- test/token/ERC1155/extensions/ERC1155Supply.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/token/ERC1155/extensions/ERC1155Supply.test.js b/test/token/ERC1155/extensions/ERC1155Supply.test.js index 7c4c54dff58..22a75c84f9a 100644 --- a/test/token/ERC1155/extensions/ERC1155Supply.test.js +++ b/test/token/ERC1155/extensions/ERC1155Supply.test.js @@ -116,7 +116,7 @@ contract('ERC1155Supply', function (accounts) { }); }); - context.only('other', function () { + context('other', function () { it('supply unaffected by no-op', async function () { this.token.safeTransferFrom(ZERO_ADDRESS, ZERO_ADDRESS, firstTokenId, firstTokenAmount, '0x', { from: ZERO_ADDRESS, From 493c12d55954ad0cd6d02dab7ba3aaa97ecf4cdd Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Wed, 25 Jan 2023 14:51:26 -0400 Subject: [PATCH 16/17] Update changelog --- CHANGELOG.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fe0cb52961..98ba5f9386c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,5 @@ # Changelog - * `TimelockController`: Changed the role architecture to use `DEFAULT_ADMIN_ROLE` as the admin for all roles, instead of the bespoke `TIMELOCK_ADMIN_ROLE` that was used previously. This aligns with the general recommendation for `AccessControl` and makes the addition of new roles easier. Accordingly, the `admin` parameter and timelock will now be granted `DEFAULT_ADMIN_ROLE` instead of `TIMELOCK_ADMIN_ROLE`. ([#3799](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3799)) - * `ERC20Votes`: Changed internal vote accounting to reusable `Votes` module previously used by `ERC721Votes`. Removed implicit `ERC20Permit` inheritance. [#3816](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3816) - * `Nonces`: Added a new contract to keep track of user nonces. Used for signatures in `ERC20Permit`, `ERC20Votes`, and `ERC721Votes`. ([#3816](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3816)) - * Removed presets in favor of [OpenZeppelin Contracts Wizard](https://wizard.openzeppelin.com/). - * `TransparentUpgradeableProxy`: Removed `admin` and `implementation` getters, which were only callable by the proxy owner and thus not very useful. ([#3820](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3820)) - * `ProxyAdmin`: Removed `getProxyAdmin` and `getProxyImplementation` getters. ([#3820](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3820)) - * `ERC20`, `ERC1155`: Deleted `_beforeTokenTransfer` and `_afterTokenTransfer` hooks, added a new internal `_update` function for customizations, and refactored all extensions using those hooks to use `_update` instead. ([#3838](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3838), [#3876](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3876)) - * `ERC165Storage`: Removed this contract in favor of inheritance based approach. ([#3880](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3880)) - * `ERC1155Supply`: add a `totalSupply()` function that returns the total amount of token circulating, this change will restrict the total tokens minted across all ids to 2**256-1 . ([#3962](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3962)) - ### How to upgrade from 4.x #### ERC20, ERC721, and ERC1155 From 2ddadedd206cbaa0b3116be4e5527f4da9fae311 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Wed, 25 Jan 2023 14:52:58 -0400 Subject: [PATCH 17/17] Add changeset --- .changeset/chilled-spiders-attack.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/chilled-spiders-attack.md diff --git a/.changeset/chilled-spiders-attack.md b/.changeset/chilled-spiders-attack.md new file mode 100644 index 00000000000..ef3fc4f55a1 --- /dev/null +++ b/.changeset/chilled-spiders-attack.md @@ -0,0 +1,5 @@ +--- +'openzeppelin-solidity': major +--- + +`ERC1155Supply`: add a `totalSupply()` function that returns the total amount of token circulating, this change will restrict the total tokens minted across all ids to 2\*\*256-1 .