编译器
0.8.22+commit.4fc1097e
文件 1 的 11:Address.sol
pragma solidity ^0.8.1;
library Address {
function isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
文件 2 的 11:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 3 的 11:ECDSA.sol
pragma solidity ^0.8.0;
import "../Strings.sol";
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return;
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
}
}
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
function recover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError) {
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
function recover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
}
}
文件 4 的 11:IERC1271.sol
pragma solidity ^0.8.0;
interface IERC1271 {
function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}
文件 5 的 11:MadicineUtil.sol
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
abstract contract ERC721 {
function ownerOf(uint256 tokenId) public view virtual returns (address);
function balanceOf(address owner) public view virtual returns (uint256);
}
abstract contract ERC20 {
function transferFrom(address from, address to, uint256 amount) public virtual returns (bool);
function balanceOf(address account) public view virtual returns (uint256);
}
abstract contract Madicine {
struct MadicineInfo {
uint16 maxSupply;
uint16 walletLimit;
bool prescribeAllowed;
address prescribeCosigner;
uint16 mintCount;
uint16 currentStageId;
uint16 pointerId;
bool isReversed;
uint80 ethCost;
uint80 ip3Cost;
uint56 prescribeEndTime;
}
struct StageInfo {
uint56 startTime;
uint56 endTime;
bool mintAllowed;
uint8 mintMethod;
uint80 ethPrice;
uint16 maxSupply;
uint16 walletLimit;
uint16 mintCount;
bytes32 merkleRoot;
address cosigner;
uint80 ip3Price;
uint16 nPerMate;
}
function getMadicineInfo(uint256 madicineId) external view virtual returns (MadicineInfo memory);
function getStageInfo(uint256 madicineId, uint256 stageId) external view virtual returns (StageInfo memory);
function totalSupply(uint256 madicineId) external view virtual returns (uint256);
function numberMintedBy(uint256 madicineId, address addr) external view virtual returns (uint256);
function stageMintedBy(uint256 madicineId, uint256 stageId, address addr) external view virtual returns (uint256);
function isPrescribed(uint256 madicineId, uint256 oozId) public view virtual returns (bool);
function canPrescribeNow(uint256 madicineId, uint256 oozId) public view virtual returns (bool);
function mint(address to, uint256 madicineId, uint256 stageId, uint256 amount) public virtual;
function burn(address to, uint256 madicineId, uint256 amount) public virtual;
function prescribe(address to, uint256 madicineId, uint256 oozId) public virtual;
}
contract MadicineUtil is Ownable, ReentrancyGuard {
using ECDSA for bytes32;
uint8 constant OWNER = 0;
uint8 constant PUBLIC = 1;
uint8 constant MATES = 2;
uint8 constant CHECKMATE = 3;
mapping(uint256 => uint16[][]) private _requiredMadicine;
mapping(uint256 => mapping(uint256 => uint16[])) private _mergeMadicineIds;
mapping(uint256 => mapping(uint256 => uint16[])) private _mergeMadicineCounts;
mapping(uint256 => mapping(uint256 => bool[10000])) private _checkMate;
Madicine public Mad_icine;
ERC721 public OOZ;
ERC20 public IP3;
address public IP3recipientAddr;
uint256 public timestampExpirySeconds;
constructor() {
Mad_icine = Madicine(0x81B636Cbc85e674b1A4Ca08e80B6eedFFa009C83);
OOZ = ERC721(0x0A69FDBaF055f92b8CC16a4ddb2DdE8aBe876927);
IP3 = ERC20(0x01C3f4a1EbccbC37cD3D4763B540e880E60302c9);
IP3recipientAddr = owner();
timestampExpirySeconds = 120;
}
function setIP3recipientAddr(address addr) external onlyOwner {
IP3recipientAddr = addr;
}
function setTimestampExpirySeconds(uint256 expirySeconds) external onlyOwner {
timestampExpirySeconds = expirySeconds;
}
function addRequiredMadicine(uint256 madicineId, uint16[][] memory requiredMadicine) external onlyOwner {
require(Mad_icine.getMadicineInfo(madicineId).mintCount == Mad_icine.totalSupply(madicineId), "Prescribe already started");
_requiredMadicine[madicineId] = requiredMadicine;
}
function addMergeMadicine(uint256 madicineId, uint256 stageId, uint16[] calldata mergeMadicineIds, uint16[] calldata mergeMadicineCounts) external onlyOwner {
require(Mad_icine.getStageInfo(madicineId, stageId).mintCount == 0, "Stage has already started");
require(mergeMadicineIds.length == mergeMadicineCounts.length, "Array length not matching");
_mergeMadicineIds[madicineId][stageId] = mergeMadicineIds;
_mergeMadicineCounts[madicineId][stageId] = mergeMadicineCounts;
}
function _prescribe(uint256 madicineId, uint256 oozId, bytes calldata signature, uint256 timestamp) internal returns (uint256) {
require(Mad_icine.canPrescribeNow(madicineId, oozId), "Cannot prescribe madicine to OOZ");
require(OOZ.ownerOf(oozId) == msg.sender, "Does not own corresponding OOZ");
if (_requiredMadicine[madicineId].length > 0) {
bool found;
for (uint256 i = 0; i < _requiredMadicine[madicineId].length; i++) {
for (uint256 j = 0; j < _requiredMadicine[madicineId][i].length; j++) {
if (Mad_icine.isPrescribed(_requiredMadicine[madicineId][i][j], oozId)) {
found = true;
}
}
require(found, "Required madicine not prescribed");
found = false;
}
delete found;
}
if (Mad_icine.getMadicineInfo(madicineId).prescribeCosigner != address(0)) {
require(SignatureChecker.isValidSignatureNow(Mad_icine.getMadicineInfo(madicineId).prescribeCosigner, keccak256(abi.encodePacked(madicineId, oozId, msg.sender, timestamp)).toEthSignedMessageHash(), signature), "Invalid signature");
require(timestamp + timestampExpirySeconds >= block.timestamp, "Timestamp expired");
}
if (Mad_icine.getMadicineInfo(madicineId).ip3Cost > 0) {
require(IP3.balanceOf(msg.sender) >= Mad_icine.getMadicineInfo(madicineId).ip3Cost, "Not enough IP3");
IP3.transferFrom(msg.sender, IP3recipientAddr, Mad_icine.getMadicineInfo(madicineId).ip3Cost);
}
Mad_icine.prescribe(msg.sender, madicineId, oozId);
return Mad_icine.getMadicineInfo(madicineId).ethCost;
}
function prescribe(uint256 madicineId, uint256 oozId, bytes calldata signature, uint256 timestamp) external payable nonReentrant {
require(msg.value >= Mad_icine.getMadicineInfo(madicineId).ethCost, "Not enough ETH");
_prescribe(madicineId, oozId, signature, timestamp);
}
function prescribeBatch(uint256[] calldata madicineIds, uint256[] calldata oozIds, bytes[] calldata signatures, uint256[] calldata timestamps) external payable nonReentrant {
require(madicineIds.length == oozIds.length && oozIds.length == signatures.length && signatures.length == timestamps.length, "Array length not matching");
uint256 ethRequired = 0;
for (uint256 i = 0; i < madicineIds.length; i++) {
ethRequired += _prescribe(madicineIds[i], oozIds[i], signatures[i], timestamps[i]);
}
require(msg.value >= ethRequired, "Not enough ETH");
delete ethRequired;
}
function _mint(uint256 madicineId, uint256 stageId, uint256 amount, uint256 proofAmount, bytes32[] calldata proof, bytes calldata signature, uint256 timestamp) internal returns (uint256) {
require(Mad_icine.getStageInfo(madicineId, stageId).mintAllowed && Mad_icine.getStageInfo(madicineId, stageId).startTime <= block.timestamp, "Mint is not allowed");
require(Mad_icine.getStageInfo(madicineId, stageId).endTime == 0 || block.timestamp <= Mad_icine.getStageInfo(madicineId, stageId).endTime, "Stage has ended");
require(amount + Mad_icine.getMadicineInfo(madicineId).mintCount <= Mad_icine.getMadicineInfo(madicineId).maxSupply, "Exceeds maximum madicine supply");
require(amount + Mad_icine.getStageInfo(madicineId, stageId).mintCount <= Mad_icine.getStageInfo(madicineId, stageId).maxSupply, "Exceeds maximum stage supply");
require(Mad_icine.getMadicineInfo(madicineId).walletLimit == 0 || amount + Mad_icine.numberMintedBy(madicineId, msg.sender) <= Mad_icine.getMadicineInfo(madicineId).walletLimit, "Exceeds madicine wallet limit");
require(Mad_icine.getStageInfo(madicineId, stageId).walletLimit == 0 || amount + Mad_icine.stageMintedBy(madicineId, stageId, msg.sender) <= Mad_icine.getStageInfo(madicineId, stageId).walletLimit, "Exceeds stage wallet limit");
require(Mad_icine.getStageInfo(madicineId, stageId).mintMethod == PUBLIC || Mad_icine.getStageInfo(madicineId, stageId).mintMethod == MATES, "Stage mint method not matching");
if (Mad_icine.getStageInfo(madicineId, stageId).merkleRoot != 0) {
require(MerkleProof.processProof(proof, keccak256(abi.encodePacked(msg.sender, proofAmount))) == Mad_icine.getStageInfo(madicineId, stageId).merkleRoot, "Invalid proof");
require(amount + Mad_icine.stageMintedBy(madicineId, stageId, msg.sender) <= proofAmount, "Exceeds whitelist limit");
}
if (Mad_icine.getStageInfo(madicineId, stageId).cosigner != address(0)) {
require(isValidCosign(madicineId, stageId, msg.sender, amount, timestamp, signature), "Invalid signature");
require(timestamp + timestampExpirySeconds >= block.timestamp, "Timestamp expired");
}
if (Mad_icine.getStageInfo(madicineId, stageId).mintMethod == MATES) {
require(OOZ.balanceOf(msg.sender) > 0, "Does not own OOZ");
}
if (_mergeMadicineIds[madicineId][stageId].length > 0) {
for (uint256 i = 0; i < _mergeMadicineIds[madicineId][stageId].length; i++) {
uint256 id = _mergeMadicineIds[madicineId][stageId][i];
uint256 total = _mergeMadicineCounts[madicineId][stageId][i] * amount;
Mad_icine.burn(msg.sender, id, total);
delete id;
delete total;
}
}
if (Mad_icine.getStageInfo(madicineId, stageId).ip3Price > 0) {
require(IP3.balanceOf(msg.sender) >= Mad_icine.getStageInfo(madicineId, stageId).ip3Price * amount, "Not enough IP3");
uint256 ip3Total = Mad_icine.getStageInfo(madicineId, stageId).ip3Price * amount;
IP3.transferFrom(msg.sender, IP3recipientAddr, ip3Total);
delete ip3Total;
}
Mad_icine.mint(msg.sender, madicineId, stageId, amount);
return Mad_icine.getStageInfo(madicineId, stageId).ethPrice * amount;
}
function mint(uint256 madicineId, uint256 stageId, uint256 amount, uint256 proofAmount, bytes32[] calldata proof, bytes calldata signature, uint256 timestamp) external payable nonReentrant {
require(msg.value >= Mad_icine.getStageInfo(madicineId, stageId).ethPrice * amount, "Not enough ETH");
_mint(madicineId, stageId, amount, proofAmount, proof, signature, timestamp);
}
function mintBatch(uint256[] calldata madicineIds, uint256[] calldata stageIds, uint256[][2] calldata amounts, bytes32[][] calldata proofs, bytes[] calldata signatures, uint256[] calldata timestamps) external payable nonReentrant {
require(madicineIds.length == stageIds.length && stageIds.length == amounts[0].length && amounts[0].length == amounts[1].length && amounts[1].length == proofs.length && proofs.length == signatures.length && signatures.length == timestamps.length, "Array length not matching");
uint256 ethRequired = 0;
for (uint256 i = 0; i < madicineIds.length; i++) {
ethRequired += _mint(madicineIds[i], stageIds[i], amounts[0][i], amounts[1][i], proofs[i], signatures[i], timestamps[i]);
}
require(msg.value >= ethRequired, "Not enough ETH");
delete ethRequired;
}
function mintCheckMate(uint256 madicineId, uint256 stageId, uint256[] calldata oozIds, bytes32[][] calldata proofs, bytes[] calldata signatures, uint256[] calldata timestamps) external payable nonReentrant {
require(Mad_icine.getStageInfo(madicineId, stageId).mintAllowed && Mad_icine.getStageInfo(madicineId, stageId).startTime <= block.timestamp, "Mint is not allowed");
require(Mad_icine.getStageInfo(madicineId, stageId).endTime == 0 || block.timestamp <= Mad_icine.getStageInfo(madicineId, stageId).endTime, "Stage has ended");
require(Mad_icine.getStageInfo(madicineId, stageId).mintMethod == CHECKMATE, "Stage mint method not matching");
require(Mad_icine.getStageInfo(madicineId, stageId).nPerMate > 0, "N per mate not initialized");
require(oozIds.length == proofs.length && proofs.length == signatures.length && signatures.length == timestamps.length, "Array length not matching");
require(msg.value >= Mad_icine.getStageInfo(madicineId, stageId).ethPrice * oozIds.length, "Not enough ETH");
uint256 mintAmount = oozIds.length * Mad_icine.getStageInfo(madicineId, stageId).nPerMate;
require(mintAmount + Mad_icine.getMadicineInfo(madicineId).mintCount <= Mad_icine.getMadicineInfo(madicineId).maxSupply, "Exceeds maximum madicine supply");
require(mintAmount + Mad_icine.getStageInfo(madicineId, stageId).mintCount <= Mad_icine.getStageInfo(madicineId, stageId).maxSupply, "Exceeds maximum stage supply");
require(Mad_icine.getMadicineInfo(madicineId).walletLimit == 0 || mintAmount + Mad_icine.numberMintedBy(madicineId, msg.sender) <= Mad_icine.getMadicineInfo(madicineId).walletLimit, "Exceeds madicine wallet limit");
require(Mad_icine.getStageInfo(madicineId, stageId).walletLimit == 0 || mintAmount + Mad_icine.stageMintedBy(madicineId, stageId, msg.sender) <= Mad_icine.getStageInfo(madicineId, stageId).walletLimit, "Exceeds stage wallet limit");
for (uint256 i = 0; i < oozIds.length; i++) {
require(oozIds[i] > 0 && oozIds[i] < 10000, "OOZ ID does not exist");
require(OOZ.ownerOf(oozIds[i]) == msg.sender, "Does not own corresponding OOZ");
require(!_checkMate[madicineId][stageId][oozIds[i]], "Already minted using this OOZ");
if (Mad_icine.getStageInfo(madicineId, stageId).merkleRoot != 0) {
require(MerkleProof.processProof(proofs[i], keccak256(abi.encodePacked(oozIds[i]))) == Mad_icine.getStageInfo(madicineId, stageId).merkleRoot, "Invalid proof");
}
if (Mad_icine.getStageInfo(madicineId, stageId).cosigner != address(0)) {
require(SignatureChecker.isValidSignatureNow(Mad_icine.getStageInfo(madicineId, stageId).cosigner, keccak256(abi.encodePacked(madicineId, stageId, msg.sender, oozIds[i], timestamps[i])).toEthSignedMessageHash(), signatures[i]), "Invalid signature");
require(timestamps[i] + timestampExpirySeconds >= block.timestamp, "Timestamp expired");
}
_checkMate[madicineId][stageId][oozIds[i]] = true;
}
if (_mergeMadicineIds[madicineId][stageId].length > 0) {
for (uint256 i = 0; i < _mergeMadicineIds[madicineId][stageId].length; i++) {
uint256 total = _mergeMadicineCounts[madicineId][stageId][i] * mintAmount;
uint256 id =_mergeMadicineIds[madicineId][stageId][i];
Mad_icine.burn(msg.sender, id, total);
delete id;
delete total;
}
}
if (Mad_icine.getStageInfo(madicineId, stageId).ip3Price > 0) {
require(IP3.balanceOf(msg.sender) >= Mad_icine.getStageInfo(madicineId, stageId).ip3Price * oozIds.length, "Not enough IP3");
uint256 ip3Total = Mad_icine.getStageInfo(madicineId, stageId).ip3Price * oozIds.length;
IP3.transferFrom(msg.sender, IP3recipientAddr, ip3Total);
delete ip3Total;
}
Mad_icine.mint(msg.sender, madicineId, stageId, mintAmount);
delete mintAmount;
}
function isValidCosign(uint256 madicineId, uint256 stageId, address addr, uint256 amount, uint256 timestamp, bytes calldata signature) internal view returns (bool) {
bytes32 hash = keccak256(abi.encodePacked(madicineId, stageId, addr, amount, timestamp, Mad_icine.stageMintedBy(madicineId, stageId, addr)));
hash = hash.toEthSignedMessageHash();
if (SignatureChecker.isValidSignatureNow(Mad_icine.getStageInfo(madicineId, stageId).cosigner, hash, signature)) {
delete hash;
return true;
} else {
delete hash;
return false;
}
}
function withdrawFunds() public onlyOwner {
payable(msg.sender).transfer(address(this).balance);
}
}
文件 6 的 11:Math.sol
pragma solidity ^0.8.0;
library Math {
enum Rounding {
Down,
Up,
Zero
}
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
function average(uint256 a, uint256 b) internal pure returns (uint256) {
return (a & b) + (a ^ b) / 2;
}
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
return a == 0 ? 0 : (a - 1) / b + 1;
}
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
uint256 prod0;
uint256 prod1;
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
if (prod1 == 0) {
return prod0 / denominator;
}
require(denominator > prod1);
uint256 remainder;
assembly {
remainder := mulmod(x, y, denominator)
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
uint256 twos = denominator & (~denominator + 1);
assembly {
denominator := div(denominator, twos)
prod0 := div(prod0, twos)
twos := add(div(sub(0, twos), twos), 1)
}
prod0 |= prod1 * twos;
uint256 inverse = (3 * denominator) ^ 2;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
result = prod0 * inverse;
return result;
}
}
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator,
Rounding rounding
) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 result = 1 << (log2(a) >> 1);
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10**64) {
value /= 10**64;
result += 64;
}
if (value >= 10**32) {
value /= 10**32;
result += 32;
}
if (value >= 10**16) {
value /= 10**16;
result += 16;
}
if (value >= 10**8) {
value /= 10**8;
result += 8;
}
if (value >= 10**4) {
value /= 10**4;
result += 4;
}
if (value >= 10**2) {
value /= 10**2;
result += 2;
}
if (value >= 10**1) {
result += 1;
}
}
return result;
}
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
}
}
}
文件 7 的 11:MerkleProof.sol
pragma solidity ^0.8.0;
library MerkleProof {
function verify(
bytes32[] memory proof,
bytes32 root,
bytes32 leaf
) internal pure returns (bool) {
return processProof(proof, leaf) == root;
}
function verifyCalldata(
bytes32[] calldata proof,
bytes32 root,
bytes32 leaf
) internal pure returns (bool) {
return processProofCalldata(proof, leaf) == root;
}
function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = _hashPair(computedHash, proof[i]);
}
return computedHash;
}
function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = _hashPair(computedHash, proof[i]);
}
return computedHash;
}
function multiProofVerify(
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32 root,
bytes32[] memory leaves
) internal pure returns (bool) {
return processMultiProof(proof, proofFlags, leaves) == root;
}
function multiProofVerifyCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32 root,
bytes32[] memory leaves
) internal pure returns (bool) {
return processMultiProofCalldata(proof, proofFlags, leaves) == root;
}
function processMultiProof(
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32[] memory leaves
) internal pure returns (bytes32 merkleRoot) {
uint256 leavesLen = leaves.length;
uint256 totalHashes = proofFlags.length;
require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof");
bytes32[] memory hashes = new bytes32[](totalHashes);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
for (uint256 i = 0; i < totalHashes; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++];
hashes[i] = _hashPair(a, b);
}
if (totalHashes > 0) {
return hashes[totalHashes - 1];
} else if (leavesLen > 0) {
return leaves[0];
} else {
return proof[0];
}
}
function processMultiProofCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32[] memory leaves
) internal pure returns (bytes32 merkleRoot) {
uint256 leavesLen = leaves.length;
uint256 totalHashes = proofFlags.length;
require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof");
bytes32[] memory hashes = new bytes32[](totalHashes);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
for (uint256 i = 0; i < totalHashes; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++];
hashes[i] = _hashPair(a, b);
}
if (totalHashes > 0) {
return hashes[totalHashes - 1];
} else if (leavesLen > 0) {
return leaves[0];
} else {
return proof[0];
}
}
function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) {
return a < b ? _efficientHash(a, b) : _efficientHash(b, a);
}
function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
assembly {
mstore(0x00, a)
mstore(0x20, b)
value := keccak256(0x00, 0x40)
}
}
}
文件 8 的 11:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 9 的 11:ReentrancyGuard.sol
pragma solidity ^0.8.0;
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
}
function _nonReentrantAfter() private {
_status = _NOT_ENTERED;
}
}
文件 10 的 11:SignatureChecker.sol
pragma solidity ^0.8.0;
import "./ECDSA.sol";
import "../Address.sol";
import "../../interfaces/IERC1271.sol";
library SignatureChecker {
function isValidSignatureNow(
address signer,
bytes32 hash,
bytes memory signature
) internal view returns (bool) {
(address recovered, ECDSA.RecoverError error) = ECDSA.tryRecover(hash, signature);
if (error == ECDSA.RecoverError.NoError && recovered == signer) {
return true;
}
(bool success, bytes memory result) = signer.staticcall(
abi.encodeWithSelector(IERC1271.isValidSignature.selector, hash, signature)
);
return (success &&
result.length == 32 &&
abi.decode(result, (bytes32)) == bytes32(IERC1271.isValidSignature.selector));
}
}
文件 11 的 11:Strings.sol
pragma solidity ^0.8.0;
import "./math/Math.sol";
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}
{
"compilationTarget": {
"Madicine/MadicineUtil.sol": "MadicineUtil"
},
"evmVersion": "shanghai",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"IP3","outputs":[{"internalType":"contract ERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"IP3recipientAddr","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"Mad_icine","outputs":[{"internalType":"contract Madicine","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"OOZ","outputs":[{"internalType":"contract ERC721","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"madicineId","type":"uint256"},{"internalType":"uint256","name":"stageId","type":"uint256"},{"internalType":"uint16[]","name":"mergeMadicineIds","type":"uint16[]"},{"internalType":"uint16[]","name":"mergeMadicineCounts","type":"uint16[]"}],"name":"addMergeMadicine","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"madicineId","type":"uint256"},{"internalType":"uint16[][]","name":"requiredMadicine","type":"uint16[][]"}],"name":"addRequiredMadicine","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"madicineId","type":"uint256"},{"internalType":"uint256","name":"stageId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"proofAmount","type":"uint256"},{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"madicineIds","type":"uint256[]"},{"internalType":"uint256[]","name":"stageIds","type":"uint256[]"},{"internalType":"uint256[][2]","name":"amounts","type":"uint256[][2]"},{"internalType":"bytes32[][]","name":"proofs","type":"bytes32[][]"},{"internalType":"bytes[]","name":"signatures","type":"bytes[]"},{"internalType":"uint256[]","name":"timestamps","type":"uint256[]"}],"name":"mintBatch","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"madicineId","type":"uint256"},{"internalType":"uint256","name":"stageId","type":"uint256"},{"internalType":"uint256[]","name":"oozIds","type":"uint256[]"},{"internalType":"bytes32[][]","name":"proofs","type":"bytes32[][]"},{"internalType":"bytes[]","name":"signatures","type":"bytes[]"},{"internalType":"uint256[]","name":"timestamps","type":"uint256[]"}],"name":"mintCheckMate","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"madicineId","type":"uint256"},{"internalType":"uint256","name":"oozId","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"prescribe","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"madicineIds","type":"uint256[]"},{"internalType":"uint256[]","name":"oozIds","type":"uint256[]"},{"internalType":"bytes[]","name":"signatures","type":"bytes[]"},{"internalType":"uint256[]","name":"timestamps","type":"uint256[]"}],"name":"prescribeBatch","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"setIP3recipientAddr","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"expirySeconds","type":"uint256"}],"name":"setTimestampExpirySeconds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"timestampExpirySeconds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawFunds","outputs":[],"stateMutability":"nonpayable","type":"function"}]