Verify smart contracts on different solidity versions

bytecodesolidityswarmverify

I'd like to build my own smart contract verify system with all solidity versions both on single file and multiple files just like what etherscan or other block explorer does.

I was able to verify for single file contract on version 0.5.16 following this post but with some modification.
This post said that runtime bytecode ends with a165627a7a72305820 but in my case it was a265627a7a72315820. So I modified ending point of runtime bytecode as 627a7a72 for general use cases.

But when I am trying to verify multiple contracts created with solidity version 0.6.12 I recognized that this contract runtime bytecode does not include 627a7a72 as a trailing end.

All information of this contract is here.

Here is what I have done for verification.

  1. First I did a compilation on remix with the source code(2 files-FarmUtils.sol and VaultFarmsZapperStaker.sol)
  2. For both cases on remix and ftmscan, abis were identical.
  3. I got the runtime bytecode on remix with same settings on the ftmscan( "optimizer": {
    "enabled": true,
    "runs": 400
    },)
    Here are bytecodes for both cases.

On Ftmscan

608060405260008055600060015534801561001957600080fd5b5060405161185e38038061185e8339818101604052606081101561003c57600080fd5b5080516020820151604090920151600780546001600160a01b039485166001600160a01b031991821617909155600580549385169382169390931790925560068054939091169282169290921790915560088054909116331790556117b8806100a66000396000f3fe6080604052600436106101595760003560e01c80636d33838a116100bb57806395b38c571161007f578063e9b8f54f11610059578063e9b8f54f1461042d578063f2eba50d14610466578063fbf238d21461047b57610160565b806395b38c57146103ca578063ac3b9d3714610403578063acc3e16e1461041857610160565b80636d33838a1461032e5780636fe29115146103585780637294b1171461038b578063780b0e64146103a05780637c32ae1b146103b557610160565b80632cde2aaa1161011d5780633d64e17a116100f75780633d64e17a146102d15780634be1c796146102e65780635a20fed2146102fb57610160565b80632cde2aaa146102745780632e73b45b146102a757806332fe7b26146102bc57610160565b806312d43a511461016557806318c83fc8146101965780631e6f3d8a146101e7578063264762041461022c5780632bc80f3a1461025f57610160565b3661016057005b600080fd5b34801561017157600080fd5b5061017a6104ae565b604080516001600160a01b039092168252519081900360200190f35b3480156101a257600080fd5b506101e5600480360360a08110156101b957600080fd5b508035906001600160a01b036020820135811691604081013590911690606081013590608001356104bd565b005b3480156101f357600080fd5b5061021a6004803603602081101561020a57600080fd5b50356001600160a01b03166109a8565b60408051918252519081900360200190f35b34801561023857600080fd5b5061021a6004803603602081101561024f57600080fd5b50356001600160a01b03166109ba565b34801561026b57600080fd5b5061021a6109cc565b34801561028057600080fd5b5061021a6004803603602081101561029757600080fd5b50356001600160a01b03166109d2565b3480156102b357600080fd5b5061017a6109e4565b3480156102c857600080fd5b5061017a6109f3565b3480156102dd57600080fd5b506101e5610a02565b3480156102f257600080fd5b5061021a610b03565b34801561030757600080fd5b5061021a6004803603602081101561031e57600080fd5b50356001600160a01b0316610b09565b34801561033a57600080fd5b506101e56004803603602081101561035157600080fd5b5035610b1b565b34801561036457600080fd5b5061021a6004803603602081101561037b57600080fd5b50356001600160a01b0316610ddf565b34801561039757600080fd5b5061021a610e5d565b3480156103ac57600080fd5b5061017a610f00565b3480156103c157600080fd5b506101e5610f0f565b3480156103d657600080fd5b5061021a600480360360408110156103ed57600080fd5b50803590602001356001600160a01b0316610f7a565b34801561040f57600080fd5b5061021a610fb4565b34801561042457600080fd5b5061021a610fba565b34801561043957600080fd5b5061021a6004803603604081101561045057600080fd5b50803590602001356001600160a01b0316611046565b34801561047257600080fd5b5061021a611098565b34801561048757600080fd5b5061021a6004803603602081101561049e57600080fd5b50356001600160a01b031661109e565b6008546001600160a01b031681565b6006546001600160a01b031633146104d457600080fd5b6000846001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561050f57600080fd5b505afa158015610523573d6000803e3d6000fd5b505050506040513d602081101561053957600080fd5b50516040805163d21220a760e01b815290519192506000916001600160a01b0388169163d21220a7916004808301926020929190829003018186803b15801561058157600080fd5b505afa158015610595573d6000803e3d6000fd5b505050506040513d60208110156105ab57600080fd5b50516005546040805163095ea7b360e01b81526001600160a01b0392831660048201819052602482018c9052915193945090929189169163095ea7b3916044808201926020929091908290030181600087803b15801561060a57600080fd5b505af115801561061e573d6000803e3d6000fd5b505050506040513d602081101561063457600080fd5b50506007546040805163188f54ef60e31b815230600482015290516000926001600160a01b03169163c47aa778916024808301926020929190829003018186803b15801561068157600080fd5b505afa158015610695573d6000803e3d6000fd5b505050506040513d60208110156106ab57600080fd5b505190506001600160a01b03821663baa2abde85858c8a8a306106d0426102586110e9565b6040518863ffffffff1660e01b815260040180886001600160a01b03168152602001876001600160a01b03168152602001868152602001858152602001848152602001836001600160a01b031681526020018281526020019750505050505050506040805180830381600087803b15801561074a57600080fd5b505af115801561075e573d6000803e3d6000fd5b505050506040513d604081101561077457600080fd5b50506007546001600160a01b0385811691161461080d5761080d846001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b1580156107db57600080fd5b505afa1580156107ef573d6000803e3d6000fd5b505050506040513d602081101561080557600080fd5b505185611133565b6007546001600160a01b038481169116146108a4576108a4836001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b15801561087257600080fd5b505afa158015610886573d6000803e3d6000fd5b505050506040513d602081101561089c57600080fd5b505184611133565b6007546040805163188f54ef60e31b815230600482015290516000926001600160a01b03169163c47aa778916024808301926020929190829003018186803b1580156108ef57600080fd5b505afa158015610903573d6000803e3d6000fd5b505050506040513d602081101561091957600080fd5b50519050600061092982846114a9565b60075460408051636deb085360e01b81526004810184905290519293506001600160a01b0390911691636deb08539160248082019260009290919082900301818387803b15801561097957600080fd5b505af115801561098d573d6000803e3d6000fd5b5050505061099b89826114cf565b5050505050505050505050565b60046020526000908152604090205481565b60026020526000908152604090205481565b60005481565b600a6020526000908152604090205481565b6007546001600160a01b031681565b6005546001600160a01b031681565b6000610a0d33610ddf565b33600090815260046020526040902054909150610a2a90826110e9565b33600090815260046020526040902055600b54610a4790826110e9565b600b556007546040805163a9059cbb60e01b81523360048201526024810184905290516001600160a01b039092169163a9059cbb916044808201926020929091908290030181600087803b158015610a9e57600080fd5b505af1158015610ab2573d6000803e3d6000fd5b505050506040513d6020811015610ac857600080fd5b505060408051828152905133917f6c26d5cf55429390ad618bed3660c538497dcfd2873e67dbb54ee669be0f0816919081900360200190a250565b60015481565b60036020526000908152604090205481565b6000610b2633610ddf565b33600090815260046020526040902054909150610b4390826110e9565b33600090815260046020526040902055600b54610b6090826110e9565b600b55600554604080516002808252606080830184526001600160a01b039094169392602083019080368337505060075482519293506001600160a01b031691839150600090610bac57fe5b60200260200101906001600160a01b031690816001600160a01b031681525050816001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015610c0557600080fd5b505afa158015610c19573d6000803e3d6000fd5b505050506040513d6020811015610c2f57600080fd5b5051815182906001908110610c4057fe5b6001600160a01b039283166020918202929092018101919091526007546005546040805163095ea7b360e01b815291851660048301526024820188905251919093169263095ea7b39260448083019391928290030181600087803b158015610ca757600080fd5b505af1158015610cbb573d6000803e3d6000fd5b505050506040513d6020811015610cd157600080fd5b50506001600160a01b03821663791ac94784868433610cf2426102586110e9565b6040518663ffffffff1660e01b81526004018086815260200185815260200180602001846001600160a01b03168152602001838152602001828103825285818151815260200191508051906020019060200280838360005b83811015610d62578181015183820152602001610d4a565b505050509050019650505050505050600060405180830381600087803b158015610d8b57600080fd5b505af1158015610d9f573d6000803e3d6000fd5b50506040805186815290513393507f6c26d5cf55429390ad618bed3660c538497dcfd2873e67dbb54ee669be0f081692509081900360200190a250505050565b6001600160a01b03811660009081526002602090815260408083205460039092528220546001548391610e1291906114a9565b90506000610e20838361160c565b6001600160a01b038616600090815260046020526040902054909150610e5490610e4e83633b9aca00611660565b906114a9565b95945050505050565b600754604080516370a0823160e01b8152306004820152905160009283926001600160a01b03909116916370a0823191602480820192602092909190829003018186803b158015610ead57600080fd5b505afa158015610ec1573d6000803e3d6000fd5b505050506040513d6020811015610ed757600080fd5b5051600b54909150610efa90633b9aca0090610ef49084906110e9565b9061160c565b91505090565b6006546001600160a01b031681565b6000610f19610e5d565b90506000610f32600954836114a990919063ffffffff16565b9050600054600014158015610f48575060005481115b15610f765760008054610f5c908390611660565b600154909150610f6c90826110e9565b6001555060098290555b5050565b6008546000906001600160a01b03163314610f9457600080fd5b6001600160a01b039091166000908152600a602052604090209190915590565b60095481565b600754604080516370a0823160e01b8152306004820152905160009283926001600160a01b03909116916370a0823191602480820192602092909190829003018186803b15801561100a57600080fd5b505afa15801561101e573d6000803e3d6000fd5b505050506040513d602081101561103457600080fd5b50519050610efa81633b9aca0061160c565b6001600160a01b0381166000908152600a60205260408120541561108e576001600160a01b0382166000908152600a6020526040902054611087908461160c565b9050611092565b5060005b92915050565b600b5481565b6008546000906001600160a01b031633146110b857600080fd5b6008805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b03939093169290921790915590565b60008282018381101561112c576040805162461bcd60e51b815260206004808301919091526024820152636164647760e01b604482015290519081900360640190fd5b9392505050565b600554604080516315ab88c960e31b815290516001600160a01b0390921691606091839163ad5c464891600480820192602092909190829003018186803b15801561117d57600080fd5b505afa158015611191573d6000803e3d6000fd5b505050506040513d60208110156111a757600080fd5b50516001600160a01b038481169116146112ce5760408051600380825260808201909252906020820160608036833701905050905082816000815181106111ea57fe5b60200260200101906001600160a01b031690816001600160a01b031681525050816001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b15801561124357600080fd5b505afa158015611257573d6000803e3d6000fd5b505050506040513d602081101561126d57600080fd5b505181518290600190811061127e57fe5b6001600160a01b0392831660209182029290920101526007548251911690829060029081106112a957fe5b60200260200101906001600160a01b031690816001600160a01b031681525050611348565b604080516002808252606082018352909160208301908036833701905050905082816000815181106112fc57fe5b6001600160a01b03928316602091820292909201015260075482519116908290600190811061132757fe5b60200260200101906001600160a01b031690816001600160a01b0316815250505b6005546040805163095ea7b360e01b81526001600160a01b0392831660048201526024810187905290519185169163095ea7b3916044808201926020929091908290030181600087803b15801561139e57600080fd5b505af11580156113b2573d6000803e3d6000fd5b505050506040513d60208110156113c857600080fd5b50506001600160a01b038216635c11d795856113e48187611046565b84306113f2426102586110e9565b6040518663ffffffff1660e01b81526004018086815260200185815260200180602001846001600160a01b03168152602001838152602001828103825285818151815260200191508051906020019060200280838360005b8381101561146257818101518382015260200161144a565b505050509050019650505050505050600060405180830381600087803b15801561148b57600080fd5b505af115801561149f573d6000803e3d6000fd5b5050505050505050565b600061112c8383604051806040016040528060018152602001607760f81b815250611686565b6114d7610f0f565b6001600160a01b0382166000908152600260205260409020546114fa81836110e9565b6001600160a01b0384166000908152600260209081526040808320939093556003905220541580611529575080155b1561154f576001546001600160a01b0384166000908152600360205260409020556115b8565b6001600160a01b03831660009081526002602052604081205461158090839061157a906103e861160c565b90611660565b905061159d6103e861157a8360015461160c90919063ffffffff16565b6001600160a01b038516600090815260036020526040902055505b6000546115c590836110e9565b6000556040805183815290516001600160a01b038516917febedb8b3c678666e7f36970bc8f57abf6d8fa2e828c0da91ea5b75bf68ed101a919081900360200190a2505050565b60008261161b57506000611092565b8282028284828161162857fe5b041461112c576040805162461bcd60e51b81526020600482015260026024820152616f7760f01b604482015290519081900360640190fd5b600061112c8383604051806040016040528060018152602001606f60f81b81525061171d565b600081848411156117155760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156116da5781810151838201526020016116c2565b50505050905090810190601f1680156117075780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6000818361176c5760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156116da5781810151838201526020016116c2565b50600083858161177857fe5b049594505050505056fea264697066735822122003230123b82c930f1c67bc875788ef28e85d5d02b06bd0e2377eea8322371a8a64736f6c634300060c0033000000000000000000000000f491e7b69e4244ad4002bc14e878a34207e38c2900000000000000000000000077216b8c728097993e9ef0e1fe527fa4506fd6bc0000000000000000000000007416ccc4b26535ad0580f5bba0d4d237de8d9d52

On Remix

608060405260008055600060015534801561001957600080fd5b5060405161185e38038061185e8339818101604052606081101561003c57600080fd5b5080516020820151604090920151600780546001600160a01b039485166001600160a01b031991821617909155600580549385169382169390931790925560068054939091169282169290921790915560088054909116331790556117b8806100a66000396000f3fe6080604052600436106101595760003560e01c80636d33838a116100bb57806395b38c571161007f578063e9b8f54f11610059578063e9b8f54f1461042d578063f2eba50d14610466578063fbf238d21461047b57610160565b806395b38c57146103ca578063ac3b9d3714610403578063acc3e16e1461041857610160565b80636d33838a1461032e5780636fe29115146103585780637294b1171461038b578063780b0e64146103a05780637c32ae1b146103b557610160565b80632cde2aaa1161011d5780633d64e17a116100f75780633d64e17a146102d15780634be1c796146102e65780635a20fed2146102fb57610160565b80632cde2aaa146102745780632e73b45b146102a757806332fe7b26146102bc57610160565b806312d43a511461016557806318c83fc8146101965780631e6f3d8a146101e7578063264762041461022c5780632bc80f3a1461025f57610160565b3661016057005b600080fd5b34801561017157600080fd5b5061017a6104ae565b604080516001600160a01b039092168252519081900360200190f35b3480156101a257600080fd5b506101e5600480360360a08110156101b957600080fd5b508035906001600160a01b036020820135811691604081013590911690606081013590608001356104bd565b005b3480156101f357600080fd5b5061021a6004803603602081101561020a57600080fd5b50356001600160a01b03166109a8565b60408051918252519081900360200190f35b34801561023857600080fd5b5061021a6004803603602081101561024f57600080fd5b50356001600160a01b03166109ba565b34801561026b57600080fd5b5061021a6109cc565b34801561028057600080fd5b5061021a6004803603602081101561029757600080fd5b50356001600160a01b03166109d2565b3480156102b357600080fd5b5061017a6109e4565b3480156102c857600080fd5b5061017a6109f3565b3480156102dd57600080fd5b506101e5610a02565b3480156102f257600080fd5b5061021a610b03565b34801561030757600080fd5b5061021a6004803603602081101561031e57600080fd5b50356001600160a01b0316610b09565b34801561033a57600080fd5b506101e56004803603602081101561035157600080fd5b5035610b1b565b34801561036457600080fd5b5061021a6004803603602081101561037b57600080fd5b50356001600160a01b0316610ddf565b34801561039757600080fd5b5061021a610e5d565b3480156103ac57600080fd5b5061017a610f00565b3480156103c157600080fd5b506101e5610f0f565b3480156103d657600080fd5b5061021a600480360360408110156103ed57600080fd5b50803590602001356001600160a01b0316610f7a565b34801561040f57600080fd5b5061021a610fb4565b34801561042457600080fd5b5061021a610fba565b34801561043957600080fd5b5061021a6004803603604081101561045057600080fd5b50803590602001356001600160a01b0316611046565b34801561047257600080fd5b5061021a611098565b34801561048757600080fd5b5061021a6004803603602081101561049e57600080fd5b50356001600160a01b031661109e565b6008546001600160a01b031681565b6006546001600160a01b031633146104d457600080fd5b6000846001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561050f57600080fd5b505afa158015610523573d6000803e3d6000fd5b505050506040513d602081101561053957600080fd5b50516040805163d21220a760e01b815290519192506000916001600160a01b0388169163d21220a7916004808301926020929190829003018186803b15801561058157600080fd5b505afa158015610595573d6000803e3d6000fd5b505050506040513d60208110156105ab57600080fd5b50516005546040805163095ea7b360e01b81526001600160a01b0392831660048201819052602482018c9052915193945090929189169163095ea7b3916044808201926020929091908290030181600087803b15801561060a57600080fd5b505af115801561061e573d6000803e3d6000fd5b505050506040513d602081101561063457600080fd5b50506007546040805163188f54ef60e31b815230600482015290516000926001600160a01b03169163c47aa778916024808301926020929190829003018186803b15801561068157600080fd5b505afa158015610695573d6000803e3d6000fd5b505050506040513d60208110156106ab57600080fd5b505190506001600160a01b03821663baa2abde85858c8a8a306106d0426102586110e9565b6040518863ffffffff1660e01b815260040180886001600160a01b03168152602001876001600160a01b03168152602001868152602001858152602001848152602001836001600160a01b031681526020018281526020019750505050505050506040805180830381600087803b15801561074a57600080fd5b505af115801561075e573d6000803e3d6000fd5b505050506040513d604081101561077457600080fd5b50506007546001600160a01b0385811691161461080d5761080d846001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b1580156107db57600080fd5b505afa1580156107ef573d6000803e3d6000fd5b505050506040513d602081101561080557600080fd5b505185611133565b6007546001600160a01b038481169116146108a4576108a4836001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b15801561087257600080fd5b505afa158015610886573d6000803e3d6000fd5b505050506040513d602081101561089c57600080fd5b505184611133565b6007546040805163188f54ef60e31b815230600482015290516000926001600160a01b03169163c47aa778916024808301926020929190829003018186803b1580156108ef57600080fd5b505afa158015610903573d6000803e3d6000fd5b505050506040513d602081101561091957600080fd5b50519050600061092982846114a9565b60075460408051636deb085360e01b81526004810184905290519293506001600160a01b0390911691636deb08539160248082019260009290919082900301818387803b15801561097957600080fd5b505af115801561098d573d6000803e3d6000fd5b5050505061099b89826114cf565b5050505050505050505050565b60046020526000908152604090205481565b60026020526000908152604090205481565b60005481565b600a6020526000908152604090205481565b6007546001600160a01b031681565b6005546001600160a01b031681565b6000610a0d33610ddf565b33600090815260046020526040902054909150610a2a90826110e9565b33600090815260046020526040902055600b54610a4790826110e9565b600b556007546040805163a9059cbb60e01b81523360048201526024810184905290516001600160a01b039092169163a9059cbb916044808201926020929091908290030181600087803b158015610a9e57600080fd5b505af1158015610ab2573d6000803e3d6000fd5b505050506040513d6020811015610ac857600080fd5b505060408051828152905133917f6c26d5cf55429390ad618bed3660c538497dcfd2873e67dbb54ee669be0f0816919081900360200190a250565b60015481565b60036020526000908152604090205481565b6000610b2633610ddf565b33600090815260046020526040902054909150610b4390826110e9565b33600090815260046020526040902055600b54610b6090826110e9565b600b55600554604080516002808252606080830184526001600160a01b039094169392602083019080368337505060075482519293506001600160a01b031691839150600090610bac57fe5b60200260200101906001600160a01b031690816001600160a01b031681525050816001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015610c0557600080fd5b505afa158015610c19573d6000803e3d6000fd5b505050506040513d6020811015610c2f57600080fd5b5051815182906001908110610c4057fe5b6001600160a01b039283166020918202929092018101919091526007546005546040805163095ea7b360e01b815291851660048301526024820188905251919093169263095ea7b39260448083019391928290030181600087803b158015610ca757600080fd5b505af1158015610cbb573d6000803e3d6000fd5b505050506040513d6020811015610cd157600080fd5b50506001600160a01b03821663791ac94784868433610cf2426102586110e9565b6040518663ffffffff1660e01b81526004018086815260200185815260200180602001846001600160a01b03168152602001838152602001828103825285818151815260200191508051906020019060200280838360005b83811015610d62578181015183820152602001610d4a565b505050509050019650505050505050600060405180830381600087803b158015610d8b57600080fd5b505af1158015610d9f573d6000803e3d6000fd5b50506040805186815290513393507f6c26d5cf55429390ad618bed3660c538497dcfd2873e67dbb54ee669be0f081692509081900360200190a250505050565b6001600160a01b03811660009081526002602090815260408083205460039092528220546001548391610e1291906114a9565b90506000610e20838361160c565b6001600160a01b038616600090815260046020526040902054909150610e5490610e4e83633b9aca00611660565b906114a9565b95945050505050565b600754604080516370a0823160e01b8152306004820152905160009283926001600160a01b03909116916370a0823191602480820192602092909190829003018186803b158015610ead57600080fd5b505afa158015610ec1573d6000803e3d6000fd5b505050506040513d6020811015610ed757600080fd5b5051600b54909150610efa90633b9aca0090610ef49084906110e9565b9061160c565b91505090565b6006546001600160a01b031681565b6000610f19610e5d565b90506000610f32600954836114a990919063ffffffff16565b9050600054600014158015610f48575060005481115b15610f765760008054610f5c908390611660565b600154909150610f6c90826110e9565b6001555060098290555b5050565b6008546000906001600160a01b03163314610f9457600080fd5b6001600160a01b039091166000908152600a602052604090209190915590565b60095481565b600754604080516370a0823160e01b8152306004820152905160009283926001600160a01b03909116916370a0823191602480820192602092909190829003018186803b15801561100a57600080fd5b505afa15801561101e573d6000803e3d6000fd5b505050506040513d602081101561103457600080fd5b50519050610efa81633b9aca0061160c565b6001600160a01b0381166000908152600a60205260408120541561108e576001600160a01b0382166000908152600a6020526040902054611087908461160c565b9050611092565b5060005b92915050565b600b5481565b6008546000906001600160a01b031633146110b857600080fd5b6008805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b03939093169290921790915590565b60008282018381101561112c576040805162461bcd60e51b815260206004808301919091526024820152636164647760e01b604482015290519081900360640190fd5b9392505050565b600554604080516315ab88c960e31b815290516001600160a01b0390921691606091839163ad5c464891600480820192602092909190829003018186803b15801561117d57600080fd5b505afa158015611191573d6000803e3d6000fd5b505050506040513d60208110156111a757600080fd5b50516001600160a01b038481169116146112ce5760408051600380825260808201909252906020820160608036833701905050905082816000815181106111ea57fe5b60200260200101906001600160a01b031690816001600160a01b031681525050816001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b15801561124357600080fd5b505afa158015611257573d6000803e3d6000fd5b505050506040513d602081101561126d57600080fd5b505181518290600190811061127e57fe5b6001600160a01b0392831660209182029290920101526007548251911690829060029081106112a957fe5b60200260200101906001600160a01b031690816001600160a01b031681525050611348565b604080516002808252606082018352909160208301908036833701905050905082816000815181106112fc57fe5b6001600160a01b03928316602091820292909201015260075482519116908290600190811061132757fe5b60200260200101906001600160a01b031690816001600160a01b0316815250505b6005546040805163095ea7b360e01b81526001600160a01b0392831660048201526024810187905290519185169163095ea7b3916044808201926020929091908290030181600087803b15801561139e57600080fd5b505af11580156113b2573d6000803e3d6000fd5b505050506040513d60208110156113c857600080fd5b50506001600160a01b038216635c11d795856113e48187611046565b84306113f2426102586110e9565b6040518663ffffffff1660e01b81526004018086815260200185815260200180602001846001600160a01b03168152602001838152602001828103825285818151815260200191508051906020019060200280838360005b8381101561146257818101518382015260200161144a565b505050509050019650505050505050600060405180830381600087803b15801561148b57600080fd5b505af115801561149f573d6000803e3d6000fd5b5050505050505050565b600061112c8383604051806040016040528060018152602001607760f81b815250611686565b6114d7610f0f565b6001600160a01b0382166000908152600260205260409020546114fa81836110e9565b6001600160a01b0384166000908152600260209081526040808320939093556003905220541580611529575080155b1561154f576001546001600160a01b0384166000908152600360205260409020556115b8565b6001600160a01b03831660009081526002602052604081205461158090839061157a906103e861160c565b90611660565b905061159d6103e861157a8360015461160c90919063ffffffff16565b6001600160a01b038516600090815260036020526040902055505b6000546115c590836110e9565b6000556040805183815290516001600160a01b038516917febedb8b3c678666e7f36970bc8f57abf6d8fa2e828c0da91ea5b75bf68ed101a919081900360200190a2505050565b60008261161b57506000611092565b8282028284828161162857fe5b041461112c576040805162461bcd60e51b81526020600482015260026024820152616f7760f01b604482015290519081900360640190fd5b600061112c8383604051806040016040528060018152602001606f60f81b81525061171d565b600081848411156117155760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156116da5781810151838201526020016116c2565b50505050905090810190601f1680156117075780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6000818361176c5760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156116da5781810151838201526020016116c2565b50600083858161177857fe5b049594505050505056fea26469706673582212200dc42e2a2f3dbafcf33685dccc6db6e30dc2eeeb9b0720ec1db7e09c275e341264736f6c634300060c0033

Bytecode lengths:

  • Ftmscan: 12668
  • Remix: 12476

I made a comparison of them and they are the same till 12390th character.
After that from 12391 to 12453 meaning 64 characters (32 bytes) they are different.

Here is different parts.

  • Ftmscan: 3230123b82c930f1c67bc875788ef28e85d5d02b06bd0e2377eea8322371a8a
  • Remix:    dc42e2a2f3dbafcf33685dccc6db6e30dc2eeeb9b0720ec1db7e09c275e3412

After that from 12454 to 12476 meaning 11 bytes they were same as 64736f6c634300060c0033.
And at this point remix bytecode finishes and Ftmscan bytecode continues with 000000000000000000000000f491e7b69e4244ad4002bc14e878a34207e38c2900000000000000000000000077216b8c728097993e9ef0e1fe527fa4506fd6bc0000000000000000000000007416ccc4b26535ad0580f5bba0d4d237de8d9d52

I found on Ftmscan that this is for constructor arguments.

Also I couldn't find anywhere 627a7a72 that I used as a trailing end point of runtime bytecode and am not sure if it's for solidity version or multiple contracts.

So summing up my problems

  • How to verify smart contracts on both multiple and single files.
  • How to get constructor arguments bytecode on above case

I am now totally confused and back to the starting point.
Any help will be really appreciated and thanks in advance.

Best Answer

The article is fairly old. I'd suggest taking a look at the current docs on Contract Medatata. They contain these notes:

The CBOR mapping can also contain other keys, so it is better to fully decode the data instead of relying on it starting with 0xa264. For example, if any experimental features that affect code generation are used, the mapping will also contain "experimental": true.

The compiler currently uses the IPFS hash of the metadata by default, but it may also use the bzzr1 hash or some other hash in the future, so do not rely on this sequence to start with 0xa2 0x64 'i' 'p' 'f' 's'. We might also add additional data to this CBOR structure, so the best option is to use a proper CBOR parser.

In 0.4.24 metadata used to contain only the Swarm hash, which is why the starting byte was 0xa1. The three higher bits say that it's a map (101 = 5 = map in CBOR) and five lower ones say that the map contains only one key (00001 = 1). In contracts compiled with later versions the map contains 2 items (IPFS hash and the compiler version) which is why it changed to 0xa2.

The following byte (0x65) is packed in a similar way - it represents the type and the length of the first mapping key. It changed to 0x64 because the Swarm hash stored under bzzr0 key has been replaced with an IPFS hash stored under a key that is one byte shorter (ipfs).

For robust detection it's best not to make too many assumptions about how this metadata is structured. Use a heuristic to detect where it starts but then use a proper CBOR parser to decode it. I think it might be best to look only for keys and ignore the type/length bytes. Looking at CompilerStack::createCBORMetadata() in solc 0.8.9, I see just a few possibilities:

  • ipfs
  • bzzr1
  • experimental
  • solc
  • bzzr0 (was present in older versions)

Changes to metadata are always listed in compiler's changelog so keep an eye for newer versions but for the existing ones this should be about it.

Also, you only really need to strip this from the bytecode you get from the blockchain. For the sources you are compiling yourself you can use the --metadata-hash none flag to get bytecode without a metadata hash.

Having said that, I'd strongly recommend not to ignore metadata during verification. If you use the JSON input that the compiler accepts (rather than flattened sources) and use the right version of the compiler, you should really get the same exact bytecode, including metadata hash embedded in it. Metadata contains hashes of all source files, their paths and compiler options used to build the bytecode so if you ignore these differences, you'll be potentially accepting modified sources - files with misleading comments, completely different variable and contract names, changed licensing info or even extra code that got optimized out. Actually, having the metadata JSON and original sources is always enough to recreate compiler input that exactly reproduces the bytecode. This is why it's recommended to keep and publish the metadata (e.g. using Sourcify).

The practice of ignoring metadata is outdated and comes from the limitations of older versions of the compiler and the verification tools. For example, in the past etherscan required you to submit a single source file, which is why a common strategy used by verification tools is to combine all your files into one. This requires an assumption that you can simply replace any import with the content of the corresponding file. This might have been true in the past but is not guaranteed to work now and new features that depend on separation between source units are planned. Since version 0.4.11 the compiler provides a standardized JSON interface and etherscan supports it too and this is the safer way to do verification.

Related Topic