我正在分析 Chainrunners 智能合约,所以我继续使用 Etherscan 并复制了经过验证的合约源代码。
当我尝试在没有solidity 优化器的情况下进行编译时,我收到了以下警告:
thatguyintech@albert chainrunners % npx hardhat compile
Compiling 5 files with 0.8.4
Warning: Unused local variable.
--> contracts/ChainRunnersBaseRenderer.sol:232:124:
|
232 | ... kenPalettes, uint8 numTokenLayers, string[NUM_LAYERS] memory traitTypes) = getTokenData(_dna);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Warning: Contract code size exceeds 24576 bytes (a limit introduced in Spurious Dragon). This contract may not be deployable on mainnet. Consider enabling the optimizer (with a low "runs" value!), turning off revert strings, or using libraries.
--> contracts/ChainRunnersBaseRenderer.sol:48:1:
|
48 | contract ChainRunnersBaseRenderer is Ownable, ReentrancyGuard {
| ^ (Relevant source part starts here and spans across multiple lines).
于是我尝试按照Hardhat官方文档开启优化器:https ://hardhat.org/config/
所以这是我的安全帽配置的hardhat.config.js
样子:
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: {
version: "0.8.4",
settings: {
optimizer: {
enabled: true,
runs: 2000,
}
}
}
};
所以现在CompilerError
当我尝试跑步时,我得到了这个安全帽npx hardhat compile
:
thatguyintech@albert chainrunners % npx hardhat compile
Compiling 5 files with 0.8.4
CompilerError: Stack too deep when compiling inline assembly: Variable value0 is 3 slot(s) too deep inside the stack.
有谁知道我该如何解决这个问题?从关于安全帽相关线程的几个谷歌搜索来看,似乎打开优化器应该是解决这个问题的方法,所以我很困惑。
这是我在 OpenZeppelin 论坛上找到的一个不适合我的示例:https ://forum.openzeppelin.com/t/stack-to-deep-when-compiling-inline-assembly/11391/11