無法在啟用優化的情況下驗證 Etherscan 上的特定智能合約程式碼
我已經在 Ropsten 測試網部署了許多智能合約,並在 Etherscan 中成功驗證了它們,但今天我遇到了一份合約,我的所有嘗試都沒有得到驗證。這是我試圖驗證其程式碼的更大契約的簡化版本。
- 已成功驗證啟用了類似程式碼和優化的智能合約。
- 由於某種原因,具有以下程式碼和相同編譯器設置的智能合約未在 Etherscan 上得到驗證。
- Etherscan 的驗證合約程式碼(2.0 版)也無濟於事。
- 我嘗試使用 Truffle 和 Remix IDE 部署合約,並使用 compiler version 啟用優化(runs = 200)
v0.4.23+commit.124ca40d
。- 我在這個GitHub gist中提供了關於這個問題的擴展描述。
我感謝有關此問題的任何幫助或提示。非常感謝。
未在 Etherscan 中驗證的程式碼:
pragma solidity 0.4.23; contract TEST { string public someVal; string public someVal2; bytes32 public signature1 = keccak256( "address TEST TEST TEST TEST", "address TEST TEST TEST TEST TEST TEST", "address TEST TEST TEST TEST TEST TEST", "uint256 TEST TEST TEST TEST TEST TEST TEST TEST", "bytes TEST TEST TEST TEST", "uint256 TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST", "uint256 TEST TEST TEST TEST TEST TEST TEST TEST" ); bytes32 public signature2 = keccak256( "address TEST TEST TEST TEST", "address TEST TEST TEST TEST TEST TEST", "address TEST TEST TEST TEST TEST TEST", "uint256 TEST TEST TEST TEST TEST TEST TEST TEST", "bytes TEST TEST TEST TEST", "uint256 TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST", "uint256 TEST TEST TEST TEST TEST TEST TEST TEST" ); bytes32 public signature3 = keccak256( "address TEST TEST TEST TEST", "address TEST TEST TEST TEST TEST TEST", "address TEST TEST TEST TEST TEST TEST", "uint256 TEST TEST TEST TEST TEST TEST TEST TEST", "bytes TEST TEST TEST TEST", "uint256 TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST", "uint256 TEST TEST TEST TEST TEST TEST TEST TEST", "uint256 TEST TEST TEST TEST" ); constructor (string val, string val2) public { someVal = val; someVal2 = val2; } }
我能夠
0x746612a6d4dcadbff55619bedeba403c0c252361
使用來自 gist 的原始碼和以下 ABI 編碼的建構子參數來驗證契約(來自您連結到的 gist):000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000044475636b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044455434b00000000000000000000000000000000000000000000000000
我將驗證工具的 v2 與您提到的編譯器和優化器的 200 次執行一起使用。
我認為該工具錯誤地猜測了建構子參數。我不確定它如何嘗試確定建構子參數,但它建議了這些參數。開頭是合約實際字節碼的一部分。
75696e743235362054455354205445535420544553542054455354205445535461646472657373205445535420544553542054455354205445535400000000006279746573205445535420544553542054455354205445535400000000000000205445535420544553542054455354205445535420544553542054455354205461646472657373205445535420544553542054455354205445535420544553540000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000044475636b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044455434b00000000000000000000000000000000000000000000000000000000
我使用的正確的ABI編碼參數可以這樣理解:
0x...40
(32 字節) - 指定第一個字元串的數據從偏移量 64 開始。0x...80
(32 字節) - 指定第二個字元串的數據從偏移量 128 開始。0x...04
(32 字節) - 指定第一個字元串的長度 (“Duck”)0x4475636b...
(32 字節)-“鴨子”的 UTF-8 表示0x...04
(32 字節) - 指定第二個字元串的長度 (“DUCK”)0x4455434b...
(32 字節)-“DUCK”的 UTF-8 表示