Solidity

如何在不同的solidity版本上驗證智能合約

  • October 5, 2021

我想在單個文件和多個文件上建構我自己的智能合約驗證系統,其中包含所有 Solidity 版本,就像 etherscan 或其他區塊瀏覽器所做的那樣。

在這篇文章之後,我能夠驗證版本0.5.16上的單文件契約,但進行了一些修改。這篇文章說執行時字節碼以. 所以我修改了執行時字節碼的結束點作為一般案例。a165627a7a72305820``a265627a7a72315820``627a7a72

但是,當我嘗試驗證使用solidity 0.6.12版本創建的多個合約時,我意識到這個合約執行時字節碼不包括627a7a72作為尾端。

這份契約的所有資訊都在這裡

這是我為驗證所做的。

  1. 首先,我使用原始碼(2 個文件-FarmUtils.sol 和 VaultFarmsZapperStaker.sol)對混音進行了編譯
  2. 對於 remix 和ftmscan的兩種情況,abis 是相同的。
  3. 我在 ftmscan(“optimizer”: { “enabled”: true, “runs”: 400 },) 上獲得了 remix 上的執行時字節碼,這是兩種情況的字節碼。

Ftmscan 上

608060405260008055600060015534801561001957600080fd5b5060405161185e38038061185e8339818101604052606081101561003c57600080fd5b5080516020820151604090920151600780546001600160a01b039485166001600160a01b031991821617909155600580549385169382169390931790925560068054939091169282169290921790915560088054909116331790556117b8806100a66000396000f3fe6080604052600436106101595760003560e01c80636d33838a116100bb57806395b38c571161007f578063e9b8f54f11610059578063e9b8f54f1461042d578063f2eba50d14610466578063fbf238d21461047b57610160565b806395b38c57146103ca578063ac3b9d3714610403578063acc3e16e1461041857610160565b80636d33838a1461032e5780636fe29115146103585780637294b1171461038b578063780b0e64146103a05780637c32ae1b146103b557610160565b80632cde2aaa1161011d5780633d64e17a116100f75780633d64e17a146102d15780634be1c796146102e65780635a20fed2146102fb57610160565b80632cde2aaa146102745780632e73b45b146102a757806332fe7b26146102bc57610160565b806312d43a511461016557806318c83fc8146101965780631e6f3d8a146101e7578063264762041461022c5780632bc80f3a1461025f57610160565b3661016057005b600080fd5b34801561017157600080fd5b5061017a6104ae565b604080516001600160a01b039092168252519081900360200190f35b3480156101a257600080fd5b506101e5600480360360a08110156101b957600080fd5b508035906001600160a01b036020820135811691604081013590911690606081013590608001356104bd565b005b3480156101f357600080fd5b5061021a6004803603602081101561020a57600080fd5b50356001600160a01b03166109a8565b60408051918252519081900360200190f35b34801561023857600080fd5b5061021a6004803603602081101561024f57600080fd5b50356001600160a01b03166109ba565b34801561026b57600080fd5b5061021a6109cc565b34801561028057600080fd5b5061021a6004803603602081101561029757600080fd5b50356001600160a01b03166109d2565b3480156102b357600080fd5b5061017a6109e4565b3480156102c857600080fd5b5061017a6109f3565b3480156102dd57600080fd5b506101e5610a02565b3480156102f257600080fd5b5061021a610b03565b34801561030757600080fd5b5061021a6004803603602081101561031e57600080fd5b50356001600160a01b0316610b09565b34801561033a57600080fd5b506101e56004803603602081101561035157600080fd5b5035610b1b565b34801561036457600080fd5b5061021a6004803603602081101561037b57600080fd5b50356001600160a01b0316610ddf565b34801561039757600080fd5b5061021a610e5d565b3480156103ac57600080fd5b5061017a610f00565b3480156103c157600080fd5b506101e5610f0f565b3480156103d657600080fd5b5061021a600480360360408110156103ed57600080fd5b50803590602001356001600160a01b0316610f7a565b34801561040f57600080fd5b5061021a610fb4565b34801561042457600080fd5b5061021a610fba565b34801561043957600080fd5b5061021a6004803603604081101561045057600080fd5b50803590602001356001600160a01b0316611046565b34801561047257600080fd5b5061021a611098565b34801561048757600080fd5b5061021a6004803603602081101561049e57600080fd5b50356001600160a01b031661109e565b6008546001600160a01b031681565b6006546001600160a01b031633146104d457600080fd5b6000846001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561050f57600080fd5b505afa158015610523573d6000803e3d6000fd5b505050506040513d602081101561053957600080fd5b50516040805163d21220a760e01b815290519192506000916001600160a01b0388169163d21220a7916004808301926020929190829003018186803b15801561058157600080fd5b505afa158015610595573d6000803e3d6000fd5b505050506040513d60208110156105ab57600080fd5b50516005546040805163095ea7b360e01b81526001600160a01b0392831660048201819052602482018c9052915193945090929189169163095ea7b3916044808201926020929091908290030181600087803b15801561060a57600080fd5b505af115801561061e573d6000803e3d6000fd5b505050506040513d602081101561063457600080fd5b50506007546040805163188f54ef60e31b815230600482015290516000926001600160a01b03169163c47aa778916024808301926020929190829003018186803b15801561068157600080fd5b505afa158015610695573d6000803e3d6000fd5b505050506040513d60208110156106ab57600080fd5b505190506001600160a01b03821663baa2abde85858c8a8a306106d0426102586110e9565b6040518863ffffffff1660e01b815260040180886001600160a01b03168152602001876001600160a01b03168152602001868152602001858152602001848152602001836001600160a01b031681526020018281526020019750505050505050506040805180830381600087803b15801561074a57600080fd5b505af115801561075e573d6000803e3d6000fd5b505050506040513d604081101561077457600080fd5b50506007546001600160a01b0385811691161461080d5761080d846001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b1580156107db57600080fd5b505afa1580156107ef573d6000803e3d6000fd5b505050506040513d602081101561080557600080fd5b505185611133565b6007546001600160a01b038481169116146108a4576108a4836001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b15801561087257600080fd5b505afa158015610886573d6000803e3d6000fd5b505050506040513d602081101561089c57600080fd5b505184611133565b6007546040805163188f54ef60e31b815230600482015290516000926001600160a01b03169163c47aa778916024808301926020929190829003018186803b1580156108ef57600080fd5b505afa158015610903573d6000803e3d6000fd5b505050506040513d602081101561091957600080fd5b50519050600061092982846114a9565b60075460408051636deb085360e01b81526004810184905290519293506001600160a01b0390911691636deb08539160248082019260009290919082900301818387803b15801561097957600080fd5b505af115801561098d573d6000803e3d6000fd5b5050505061099b89826114cf565b5050505050505050505050565b60046020526000908152604090205481565b60026020526000908152604090205481565b60005481565b600a6020526000908152604090205481565b6007546001600160a01b031681565b6005546001600160a01b031681565b6000610a0d33610ddf565b33600090815260046020526040902054909150610a2a90826110e9565b33600090815260046020526040902055600b54610a4790826110e9565b600b556007546040805163a9059cbb60e01b81523360048201526024810184905290516001600160a01b039092169163a9059cbb916044808201926020929091908290030181600087803b158015610a9e57600080fd5b505af1158015610ab2573d6000803e3d6000fd5b505050506040513d6020811015610ac857600080fd5b505060408051828152905133917f6c26d5cf55429390ad618bed3660c538497dcfd2873e67dbb54ee669be0f0816919081900360200190a250565b60015481565b60036020526000908152604090205481565b6000610b2633610ddf565b33600090815260046020526040902054909150610b4390826110e9565b33600090815260046020526040902055600b54610b6090826110e9565b600b55600554604080516002808252606080830184526001600160a01b039094169392602083019080368337505060075482519293506001600160a01b031691839150600090610bac57fe5b60200260200101906001600160a01b031690816001600160a01b031681525050816001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015610c0557600080fd5b505afa158015610c19573d6000803e3d6000fd5b505050506040513d6020811015610c2f57600080fd5b5051815182906001908110610c4057fe5b6001600160a01b039283166020918202929092018101919091526007546005546040805163095ea7b360e01b815291851660048301526024820188905251919093169263095ea7b39260448083019391928290030181600087803b158015610ca757600080fd5b505af1158015610cbb573d6000803e3d6000fd5b505050506040513d6020811015610cd157600080fd5b50506001600160a01b03821663791ac94784868433610cf2426102586110e9565b6040518663ffffffff1660e01b81526004018086815260200185815260200180602001846001600160a01b03168152602001838152602001828103825285818151815260200191508051906020019060200280838360005b83811015610d62578181015183820152602001610d4a565b505050509050019650505050505050600060405180830381600087803b158015610d8b57600080fd5b505af1158015610d9f573d6000803e3d6000fd5b50506040805186815290513393507f6c26d5cf55429390ad618bed3660c538497dcfd2873e67dbb54ee669be0f081692509081900360200190a250505050565b6001600160a01b03811660009081526002602090815260408083205460039092528220546001548391610e1291906114a9565b90506000610e20838361160c565b6001600160a01b038616600090815260046020526040902054909150610e5490610e4e83633b9aca00611660565b906114a9565b95945050505050565b600754604080516370a0823160e01b8152306004820152905160009283926001600160a01b03909116916370a0823191602480820192602092909190829003018186803b158015610ead57600080fd5b505afa158015610ec1573d6000803e3d6000fd5b505050506040513d6020811015610ed757600080fd5b5051600b54909150610efa90633b9aca0090610ef49084906110e9565b9061160c565b91505090565b6006546001600160a01b031681565b6000610f19610e5d565b90506000610f32600954836114a990919063ffffffff16565b9050600054600014158015610f48575060005481115b15610f765760008054610f5c908390611660565b600154909150610f6c90826110e9565b6001555060098290555b5050565b6008546000906001600160a01b03163314610f9457600080fd5b6001600160a01b039091166000908152600a602052604090209190915590565b60095481565b600754604080516370a0823160e01b8152306004820152905160009283926001600160a01b03909116916370a0823191602480820192602092909190829003018186803b15801561100a57600080fd5b505afa15801561101e573d6000803e3d6000fd5b505050506040513d602081101561103457600080fd5b50519050610efa81633b9aca0061160c565b6001600160a01b0381166000908152600a60205260408120541561108e576001600160a01b0382166000908152600a6020526040902054611087908461160c565b9050611092565b5060005b92915050565b600b5481565b6008546000906001600160a01b031633146110b857600080fd5b6008805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b03939093169290921790915590565b60008282018381101561112c576040805162461bcd60e51b815260206004808301919091526024820152636164647760e01b604482015290519081900360640190fd5b9392505050565b600554604080516315ab88c960e31b815290516001600160a01b0390921691606091839163ad5c464891600480820192602092909190829003018186803b15801561117d57600080fd5b505afa158015611191573d6000803e3d6000fd5b505050506040513d60208110156111a757600080fd5b50516001600160a01b038481169116146112ce5760408051600380825260808201909252906020820160608036833701905050905082816000815181106111ea57fe5b60200260200101906001600160a01b031690816001600160a01b031681525050816001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b15801561124357600080fd5b505afa158015611257573d6000803e3d6000fd5b505050506040513d602081101561126d57600080fd5b505181518290600190811061127e57fe5b6001600160a01b0392831660209182029290920101526007548251911690829060029081106112a957fe5b60200260200101906001600160a01b031690816001600160a01b031681525050611348565b604080516002808252606082018352909160208301908036833701905050905082816000815181106112fc57fe5b6001600160a01b03928316602091820292909201015260075482519116908290600190811061132757fe5b60200260200101906001600160a01b031690816001600160a01b0316815250505b6005546040805163095ea7b360e01b81526001600160a01b0392831660048201526024810187905290519185169163095ea7b3916044808201926020929091908290030181600087803b15801561139e57600080fd5b505af11580156113b2573d6000803e3d6000fd5b505050506040513d60208110156113c857600080fd5b50506001600160a01b038216635c11d795856113e48187611046565b84306113f2426102586110e9565b6040518663ffffffff1660e01b81526004018086815260200185815260200180602001846001600160a01b03168152602001838152602001828103825285818151815260200191508051906020019060200280838360005b8381101561146257818101518382015260200161144a565b505050509050019650505050505050600060405180830381600087803b15801561148b57600080fd5b505af115801561149f573d6000803e3d6000fd5b5050505050505050565b600061112c8383604051806040016040528060018152602001607760f81b815250611686565b6114d7610f0f565b6001600160a01b0382166000908152600260205260409020546114fa81836110e9565b6001600160a01b0384166000908152600260209081526040808320939093556003905220541580611529575080155b1561154f576001546001600160a01b0384166000908152600360205260409020556115b8565b6001600160a01b03831660009081526002602052604081205461158090839061157a906103e861160c565b90611660565b905061159d6103e861157a8360015461160c90919063ffffffff16565b6001600160a01b038516600090815260036020526040902055505b6000546115c590836110e9565b6000556040805183815290516001600160a01b038516917febedb8b3c678666e7f36970bc8f57abf6d8fa2e828c0da91ea5b75bf68ed101a919081900360200190a2505050565b60008261161b57506000611092565b8282028284828161162857fe5b041461112c576040805162461bcd60e51b81526020600482015260026024820152616f7760f01b604482015290519081900360640190fd5b600061112c8383604051806040016040528060018152602001606f60f81b81525061171d565b600081848411156117155760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156116da5781810151838201526020016116c2565b50505050905090810190601f1680156117075780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6000818361176c5760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156116da5781810151838201526020016116c2565b50600083858161177857fe5b049594505050505056fea264697066735822122003230123b82c930f1c67bc875788ef28e85d5d02b06bd0e2377eea8322371a8a64736f6c634300060c0033000000000000000000000000f491e7b69e4244ad4002bc14e878a34207e38c2900000000000000000000000077216b8c728097993e9ef0e1fe527fa4506fd6bc0000000000000000000000007416ccc4b26535ad0580f5bba0d4d237de8d9d52

混音_

608060405260008055600060015534801561001957600080fd5b5060405161185e38038061185e8339818101604052606081101561003c57600080fd5b5080516020820151604090920151600780546001600160a01b039485166001600160a01b031991821617909155600580549385169382169390931790925560068054939091169282169290921790915560088054909116331790556117b8806100a66000396000f3fe6080604052600436106101595760003560e01c80636d33838a116100bb57806395b38c571161007f578063e9b8f54f11610059578063e9b8f54f1461042d578063f2eba50d14610466578063fbf238d21461047b57610160565b806395b38c57146103ca578063ac3b9d3714610403578063acc3e16e1461041857610160565b80636d33838a1461032e5780636fe29115146103585780637294b1171461038b578063780b0e64146103a05780637c32ae1b146103b557610160565b80632cde2aaa1161011d5780633d64e17a116100f75780633d64e17a146102d15780634be1c796146102e65780635a20fed2146102fb57610160565b80632cde2aaa146102745780632e73b45b146102a757806332fe7b26146102bc57610160565b806312d43a511461016557806318c83fc8146101965780631e6f3d8a146101e7578063264762041461022c5780632bc80f3a1461025f57610160565b3661016057005b600080fd5b34801561017157600080fd5b5061017a6104ae565b604080516001600160a01b039092168252519081900360200190f35b3480156101a257600080fd5b506101e5600480360360a08110156101b957600080fd5b508035906001600160a01b036020820135811691604081013590911690606081013590608001356104bd565b005b3480156101f357600080fd5b5061021a6004803603602081101561020a57600080fd5b50356001600160a01b03166109a8565b60408051918252519081900360200190f35b34801561023857600080fd5b5061021a6004803603602081101561024f57600080fd5b50356001600160a01b03166109ba565b34801561026b57600080fd5b5061021a6109cc565b34801561028057600080fd5b5061021a6004803603602081101561029757600080fd5b50356001600160a01b03166109d2565b3480156102b357600080fd5b5061017a6109e4565b3480156102c857600080fd5b5061017a6109f3565b3480156102dd57600080fd5b506101e5610a02565b3480156102f257600080fd5b5061021a610b03565b34801561030757600080fd5b5061021a6004803603602081101561031e57600080fd5b50356001600160a01b0316610b09565b34801561033a57600080fd5b506101e56004803603602081101561035157600080fd5b5035610b1b565b34801561036457600080fd5b5061021a6004803603602081101561037b57600080fd5b50356001600160a01b0316610ddf565b34801561039757600080fd5b5061021a610e5d565b3480156103ac57600080fd5b5061017a610f00565b3480156103c157600080fd5b506101e5610f0f565b3480156103d657600080fd5b5061021a600480360360408110156103ed57600080fd5b50803590602001356001600160a01b0316610f7a565b34801561040f57600080fd5b5061021a610fb4565b34801561042457600080fd5b5061021a610fba565b34801561043957600080fd5b5061021a6004803603604081101561045057600080fd5b50803590602001356001600160a01b0316611046565b34801561047257600080fd5b5061021a611098565b34801561048757600080fd5b5061021a6004803603602081101561049e57600080fd5b50356001600160a01b031661109e565b6008546001600160a01b031681565b6006546001600160a01b031633146104d457600080fd5b6000846001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561050f57600080fd5b505afa158015610523573d6000803e3d6000fd5b505050506040513d602081101561053957600080fd5b50516040805163d21220a760e01b815290519192506000916001600160a01b0388169163d21220a7916004808301926020929190829003018186803b15801561058157600080fd5b505afa158015610595573d6000803e3d6000fd5b505050506040513d60208110156105ab57600080fd5b50516005546040805163095ea7b360e01b81526001600160a01b0392831660048201819052602482018c9052915193945090929189169163095ea7b3916044808201926020929091908290030181600087803b15801561060a57600080fd5b505af115801561061e573d6000803e3d6000fd5b505050506040513d602081101561063457600080fd5b50506007546040805163188f54ef60e31b815230600482015290516000926001600160a01b03169163c47aa778916024808301926020929190829003018186803b15801561068157600080fd5b505afa158015610695573d6000803e3d6000fd5b505050506040513d60208110156106ab57600080fd5b505190506001600160a01b03821663baa2abde85858c8a8a306106d0426102586110e9565b6040518863ffffffff1660e01b815260040180886001600160a01b03168152602001876001600160a01b03168152602001868152602001858152602001848152602001836001600160a01b031681526020018281526020019750505050505050506040805180830381600087803b15801561074a57600080fd5b505af115801561075e573d6000803e3d6000fd5b505050506040513d604081101561077457600080fd5b50506007546001600160a01b0385811691161461080d5761080d846001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b1580156107db57600080fd5b505afa1580156107ef573d6000803e3d6000fd5b505050506040513d602081101561080557600080fd5b505185611133565b6007546001600160a01b038481169116146108a4576108a4836001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b15801561087257600080fd5b505afa158015610886573d6000803e3d6000fd5b505050506040513d602081101561089c57600080fd5b505184611133565b6007546040805163188f54ef60e31b815230600482015290516000926001600160a01b03169163c47aa778916024808301926020929190829003018186803b1580156108ef57600080fd5b505afa158015610903573d6000803e3d6000fd5b505050506040513d602081101561091957600080fd5b50519050600061092982846114a9565b60075460408051636deb085360e01b81526004810184905290519293506001600160a01b0390911691636deb08539160248082019260009290919082900301818387803b15801561097957600080fd5b505af115801561098d573d6000803e3d6000fd5b5050505061099b89826114cf565b5050505050505050505050565b60046020526000908152604090205481565b60026020526000908152604090205481565b60005481565b600a6020526000908152604090205481565b6007546001600160a01b031681565b6005546001600160a01b031681565b6000610a0d33610ddf565b33600090815260046020526040902054909150610a2a90826110e9565b33600090815260046020526040902055600b54610a4790826110e9565b600b556007546040805163a9059cbb60e01b81523360048201526024810184905290516001600160a01b039092169163a9059cbb916044808201926020929091908290030181600087803b158015610a9e57600080fd5b505af1158015610ab2573d6000803e3d6000fd5b505050506040513d6020811015610ac857600080fd5b505060408051828152905133917f6c26d5cf55429390ad618bed3660c538497dcfd2873e67dbb54ee669be0f0816919081900360200190a250565b60015481565b60036020526000908152604090205481565b6000610b2633610ddf565b33600090815260046020526040902054909150610b4390826110e9565b33600090815260046020526040902055600b54610b6090826110e9565b600b55600554604080516002808252606080830184526001600160a01b039094169392602083019080368337505060075482519293506001600160a01b031691839150600090610bac57fe5b60200260200101906001600160a01b031690816001600160a01b031681525050816001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015610c0557600080fd5b505afa158015610c19573d6000803e3d6000fd5b505050506040513d6020811015610c2f57600080fd5b5051815182906001908110610c4057fe5b6001600160a01b039283166020918202929092018101919091526007546005546040805163095ea7b360e01b815291851660048301526024820188905251919093169263095ea7b39260448083019391928290030181600087803b158015610ca757600080fd5b505af1158015610cbb573d6000803e3d6000fd5b505050506040513d6020811015610cd157600080fd5b50506001600160a01b03821663791ac94784868433610cf2426102586110e9565b6040518663ffffffff1660e01b81526004018086815260200185815260200180602001846001600160a01b03168152602001838152602001828103825285818151815260200191508051906020019060200280838360005b83811015610d62578181015183820152602001610d4a565b505050509050019650505050505050600060405180830381600087803b158015610d8b57600080fd5b505af1158015610d9f573d6000803e3d6000fd5b50506040805186815290513393507f6c26d5cf55429390ad618bed3660c538497dcfd2873e67dbb54ee669be0f081692509081900360200190a250505050565b6001600160a01b03811660009081526002602090815260408083205460039092528220546001548391610e1291906114a9565b90506000610e20838361160c565b6001600160a01b038616600090815260046020526040902054909150610e5490610e4e83633b9aca00611660565b906114a9565b95945050505050565b600754604080516370a0823160e01b8152306004820152905160009283926001600160a01b03909116916370a0823191602480820192602092909190829003018186803b158015610ead57600080fd5b505afa158015610ec1573d6000803e3d6000fd5b505050506040513d6020811015610ed757600080fd5b5051600b54909150610efa90633b9aca0090610ef49084906110e9565b9061160c565b91505090565b6006546001600160a01b031681565b6000610f19610e5d565b90506000610f32600954836114a990919063ffffffff16565b9050600054600014158015610f48575060005481115b15610f765760008054610f5c908390611660565b600154909150610f6c90826110e9565b6001555060098290555b5050565b6008546000906001600160a01b03163314610f9457600080fd5b6001600160a01b039091166000908152600a602052604090209190915590565b60095481565b600754604080516370a0823160e01b8152306004820152905160009283926001600160a01b03909116916370a0823191602480820192602092909190829003018186803b15801561100a57600080fd5b505afa15801561101e573d6000803e3d6000fd5b505050506040513d602081101561103457600080fd5b50519050610efa81633b9aca0061160c565b6001600160a01b0381166000908152600a60205260408120541561108e576001600160a01b0382166000908152600a6020526040902054611087908461160c565b9050611092565b5060005b92915050565b600b5481565b6008546000906001600160a01b031633146110b857600080fd5b6008805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b03939093169290921790915590565b60008282018381101561112c576040805162461bcd60e51b815260206004808301919091526024820152636164647760e01b604482015290519081900360640190fd5b9392505050565b600554604080516315ab88c960e31b815290516001600160a01b0390921691606091839163ad5c464891600480820192602092909190829003018186803b15801561117d57600080fd5b505afa158015611191573d6000803e3d6000fd5b505050506040513d60208110156111a757600080fd5b50516001600160a01b038481169116146112ce5760408051600380825260808201909252906020820160608036833701905050905082816000815181106111ea57fe5b60200260200101906001600160a01b031690816001600160a01b031681525050816001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b15801561124357600080fd5b505afa158015611257573d6000803e3d6000fd5b505050506040513d602081101561126d57600080fd5b505181518290600190811061127e57fe5b6001600160a01b0392831660209182029290920101526007548251911690829060029081106112a957fe5b60200260200101906001600160a01b031690816001600160a01b031681525050611348565b604080516002808252606082018352909160208301908036833701905050905082816000815181106112fc57fe5b6001600160a01b03928316602091820292909201015260075482519116908290600190811061132757fe5b60200260200101906001600160a01b031690816001600160a01b0316815250505b6005546040805163095ea7b360e01b81526001600160a01b0392831660048201526024810187905290519185169163095ea7b3916044808201926020929091908290030181600087803b15801561139e57600080fd5b505af11580156113b2573d6000803e3d6000fd5b505050506040513d60208110156113c857600080fd5b50506001600160a01b038216635c11d795856113e48187611046565b84306113f2426102586110e9565b6040518663ffffffff1660e01b81526004018086815260200185815260200180602001846001600160a01b03168152602001838152602001828103825285818151815260200191508051906020019060200280838360005b8381101561146257818101518382015260200161144a565b505050509050019650505050505050600060405180830381600087803b15801561148b57600080fd5b505af115801561149f573d6000803e3d6000fd5b5050505050505050565b600061112c8383604051806040016040528060018152602001607760f81b815250611686565b6114d7610f0f565b6001600160a01b0382166000908152600260205260409020546114fa81836110e9565b6001600160a01b0384166000908152600260209081526040808320939093556003905220541580611529575080155b1561154f576001546001600160a01b0384166000908152600360205260409020556115b8565b6001600160a01b03831660009081526002602052604081205461158090839061157a906103e861160c565b90611660565b905061159d6103e861157a8360015461160c90919063ffffffff16565b6001600160a01b038516600090815260036020526040902055505b6000546115c590836110e9565b6000556040805183815290516001600160a01b038516917febedb8b3c678666e7f36970bc8f57abf6d8fa2e828c0da91ea5b75bf68ed101a919081900360200190a2505050565b60008261161b57506000611092565b8282028284828161162857fe5b041461112c576040805162461bcd60e51b81526020600482015260026024820152616f7760f01b604482015290519081900360640190fd5b600061112c8383604051806040016040528060018152602001606f60f81b81525061171d565b600081848411156117155760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156116da5781810151838201526020016116c2565b50505050905090810190601f1680156117075780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6000818361176c5760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156116da5781810151838201526020016116c2565b50600083858161177857fe5b049594505050505056fea26469706673582212200dc42e2a2f3dbafcf33685dccc6db6e30dc2eeeb9b0720ec1db7e09c275e341264736f6c634300060c0033

字節碼長度:

  • Ftmscan : 12668
  • 混音:12476

我對它們進行了比較,它們在第 12390 個字元之前是相同的。之後從 12391 到 12453 表示 64 個字元(32 個字節),它們是不同的。

這裡是不同的部分。

  • 掃描器:3230123b82c930f1c67bc875788ef28e85d5d02b06bd0e2377eea8322371a8a
  • 混音:    dc42e2a2f3dbafcf33685dccc6db6e30dc2eeeb9b0720ec1db7e09c275e3412

之後從 12454 到 12476 表示 11 個字節,它們與64736f6c634300060c0033. 至此,重新混合字節碼完成,Ftmscan 字節碼繼續000000000000000000000000f491e7b69e4244ad4002bc14e878a34207e38c2900000000000000000000000077216b8c728097993e9ef0e1fe527fa4506fd6bc0000000000000000000000007416ccc4b26535ad0580f5bba0d4d237de8d9d52

我在Ftmscan上發現這是用於建構子參數的。

此外,我找不到任何627a7a72用作執行時字節碼的尾隨端點的地方,並且不確定它是用於solidity 版本還是多個合約。

所以總結我的問題

  • 如何在多個文件和單個文件上驗證智能合約。
  • 如何在上述情況下獲取建構子參數字節碼

我現在完全糊塗了,又回到了起點。任何幫助將不勝感激,並提前感謝。

文章比較老了。我建議看一下Contract Medatata 上的目前文件。它們包含以下註釋:

CBOR 映射還可以包含其他鍵,因此最好完全解碼數據而不是依賴以0xa264. 例如,如果使用了任何影響程式碼生成的實驗性功能,則映射也將包含"experimental": true.

編譯器目前預設使用元數據的 IPFS 雜湊,但將來也可能使用 bzzr1 雜湊或其他一些雜湊,所以不要依賴這個序列以0xa2 0x64 'i' 'p' 'f' 's'. 我們可能還會向這個 CBOR 結構添加額外的數據,所以最好的選擇是使用適當的 CBOR 解析器。

在 0.4.24 元數據中,過去只包含 Swarm 雜湊,這就是為什麼起始字節是0xa1. 三個高位表示它是一個映射(CBOR 中的101= = 映射),五個低位表示映射僅包含一個鍵( = )。在使用更高版本編譯的合約中,該映射包含 2 個項目(IPFS 雜湊和編譯器版本),這就是它更改為.5``00001``1``0xa2

接下來的字節 ( 0x65) 以類似的方式打包 - 它表示第一個映射鍵的類型和長度。它更改為0x64因為儲存在 key 下的 Swarm 散列bzzr0已被儲存在一個短一個字節 ( ipfs) 的 key 下的 IPFS 散列替換。

對於穩健的檢測,最好不要對元數據的結構做出太多假設。使用啟發式檢測它從哪裡開始,然後使用適當的 CBOR 解析器對其進行解碼。我認為最好只查找鍵並忽略類型/長度字節。在CompilerStack::createCBORMetadata()solc 0.8.9中查看,我只看到了幾種可能性:

  • ipfs
  • bzzr1
  • experimental
  • solc
  • bzzr0(存在於舊版本中)

對元數據的更改始終列在編譯器的更改日誌中,因此請留意較新的版本,但對於現有版本,這應該是關於它的​​。

此外,您只需要從從區塊鏈獲得的字節碼中去除它。對於您自己編譯的源,您可以使用該--metadata-hash none標誌來獲取沒有元數據雜湊的字節碼。

話雖如此,我強烈建議在驗證期間不要忽略元數據。如果你使用編譯器接受的 JSON 輸入(而不是扁平化的源)並使用正確版本的編譯器,你應該得到完全相同的字節碼,包括嵌入其中的元數據雜湊。元數據包含所有源文件的雜湊值、它們的路徑和用於建構字節碼的編譯器選項,因此如果您忽略這些差異,您可能會接受修改後的源文件——帶有誤導性註釋、完全不同的變數和契約名稱、更改的許可資訊或甚至是被優化的額外程式碼。實際上,擁有元數據 JSON 和原始原始碼總是足以重新創建精確再現字節碼的編譯器輸入。這就是為什麼建議保留和發布元數據(例如採購)。

忽略元數據的做法已經過時,並且來自舊版本編譯器和驗證工具的限制。例如,過去 etherscan 要求您送出單個源文件,這就是驗證工具使用的常用策略是將所有文件合併為一個的原因。這需要假設您可以簡單地將任何導入替換為相應文件的內容。這在過去可能是正確的,但不能保證現在可以工作,並且計劃了依賴於源單元之間分離的新功能。從 0.4.11 版本開始,編譯器提供了標準化的 JSON 介面,etherscan 也支持它,這是更安全的驗證方式。

引用自:https://ethereum.stackexchange.com/questions/110991