ink! smart contract is using Rust so its verification is done by ensuring a certain Rust code + metadata == the code_hash of the wasm binariy deployed on chain.
The wasm binariy is deployed on-chain and is identified by its code_hash (the blake2b hash of the wasm binary). You can query the code_hash of a contract address by querying chain state contractsInfoOf(contractAdress)
Now we need to ensure that the code_hash of this account address is equal to a certain Rust code (ink!) and metadata.
ink!4.0 will integrate this new metadata type: https://github.com/paritytech/cargo-contract/pull/680è
"source": {
"hash": "0xccb6f8277de7a9d2c8161c2f9d7f86446819222b7f15807ea33958d7b5c170a7",
"language": "ink! 4.0.0",
"compiler": "rustc 1.64.0-nightly",
"build_info": {
"build_mode": "Debug",
"cargo_contract_version": "1.4.0",
"rustc_version": "nightly-2022-07-25",
"wasm_opt_settings": {
"optimization_passes": "Z",
"version": 109
}
}
}
This metadata file provides all information to ensure a certain Rust code as input will all time compile the same wasm binaries with the same code hash. As contracts are written in Rust rust compiler version is important "compiler": "rustc 1.64.0-nightly"
To compile smart contracts cargo-contract is used: https://github.com/paritytech/cargo-contract
cargo-contracts first builds the ink! contract as a Rust binary then compile it to wasm then optimize the wasm file (so it has the smallest size possible)
So different versions of cargo-contract can produce different wasm binaries (that’s why the version is mandatory).
Also, the wasm optimizer version is important (but it should be integrated to the next version of cargo-contract).
You can also build contracts using "build_mode": "Debug" or "build_mode": "Release"
Info needed by the user (who wants to verify a contract)