-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseNftCode
More file actions
30 lines (26 loc) · 922 Bytes
/
BaseNftCode
File metadata and controls
30 lines (26 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract BasicMath {
function adder(uint _a, uint _b) public pure returns (uint sum, bool error) {
// Use `unchecked` to allow overflow
unchecked {
uint c = _a + _b;
// If the result of the addition is smaller than _a, it means an overflow has occurred
if (c < _a) {
return (0, true);
}
return (c, false);
}
}
function subtractor(uint _a, uint _b) public pure returns (uint difference, bool error) {
// Manually check whether underflow will occur (when _a is smaller than _b)
if (_a < _b) {
return (0, true);
}
// Use `unchecked` to avoid Solidity's underflow check which will stop the transaction
unchecked {
uint c = _a - _b;
return (c, false);
}
}
}