4
4
pragma solidity ^ 0.8.20 ;
5
5
6
6
import {ERC1155 } from "../ERC1155.sol " ;
7
+ import {Arrays} from "../../../utils/Arrays.sol " ;
7
8
8
9
/**
9
10
* @dev Extension of ERC-1155 that adds tracking of total supply per id.
@@ -19,6 +20,8 @@ import {ERC1155} from "../ERC1155.sol";
19
20
* CAUTION: This extension should not be added in an upgrade to an already deployed contract.
20
21
*/
21
22
abstract contract ERC1155Supply is ERC1155 {
23
+ using Arrays for uint256 [];
24
+
22
25
mapping (uint256 id = > uint256 ) private _totalSupply;
23
26
uint256 private _totalSupplyAll;
24
27
@@ -57,9 +60,9 @@ abstract contract ERC1155Supply is ERC1155 {
57
60
if (from == address (0 )) {
58
61
uint256 totalMintValue = 0 ;
59
62
for (uint256 i = 0 ; i < ids.length ; ++ i) {
60
- uint256 value = values[i] ;
63
+ uint256 value = values. unsafeMemoryAccess (i) ;
61
64
// Overflow check required: The rest of the code assumes that totalSupply never overflows
62
- _totalSupply[ids[i] ] += value;
65
+ _totalSupply[ids. unsafeMemoryAccess (i) ] += value;
63
66
totalMintValue += value;
64
67
}
65
68
// Overflow check required: The rest of the code assumes that totalSupplyAll never overflows
@@ -69,11 +72,11 @@ abstract contract ERC1155Supply is ERC1155 {
69
72
if (to == address (0 )) {
70
73
uint256 totalBurnValue = 0 ;
71
74
for (uint256 i = 0 ; i < ids.length ; ++ i) {
72
- uint256 value = values[i] ;
75
+ uint256 value = values. unsafeMemoryAccess (i) ;
73
76
74
77
unchecked {
75
78
// Overflow not possible: values[i] <= balanceOf(from, ids[i]) <= totalSupply(ids[i])
76
- _totalSupply[ids[i] ] -= value;
79
+ _totalSupply[ids. unsafeMemoryAccess (i) ] -= value;
77
80
// Overflow not possible: sum_i(values[i]) <= sum_i(totalSupply(ids[i])) <= totalSupplyAll
78
81
totalBurnValue += value;
79
82
}
0 commit comments