Let's investigate the Bad Contract deployed on the Neutron as seen here: https://neutron.celat.one/neutron-1/contracts/neutron1y6s52fuhnqtank3wjfgrkcvcp3t3anw6yj72jtk5alufy6ldwrxsa9nzkj code id: 559
git clone https://github.com/neutron-org/neutron
cd neutron && git checkout v2.0.0
make install
neutrond query wasm contract neutron1y6s52fuhnqtank3wjfgrkcvcp3t3anw6yj72jtk5alufy6ldwrxsa9nzkj --node https://neutron-rpc.publicnode.com:443
Output
address: neutron1y6s52fuhnqtank3wjfgrkcvcp3t3anw6yj72jtk5alufy6ldwrxsa9nzkj
contract_info:
admin: ""
code_id: "559"
created:
block_height: "5416932"
tx_index: "579760"
creator: neutron143wp6g8paqasnuuey6zyapucknwy9rhnld8hkr
extension: null
ibc_port_id: ""
label: Bad Contract
neutrond query wasm contract-state raw neutron1y6s52fuhnqtank3wjfgrkcvcp3t3anw6yj72jtk5alufy6ldwrxsa9nzkj 636F6E74726163745F696E666F --node https://neutron-rpc.publicnode.com:443 --output json | jq -r .data | base64 -d | jq
What in the world is 636F6E74726163745F696E666F? 😕 ContractInfo is must be stored under "contract_info" key which translates to "636F6E74726163745F696E666F" in hex format. As documented here.
{
"contract": "crates.io:cw20-merkle-airdrop",
"version": "0.14.2"
}
neutrond query wasm code 559 559_code.wasm --node https://neutron-rpc.publicnode.com:443
sha256sum 559_code.wasm
Output
0a514d35b6759d5e448afcebe04f2ce33d1665dcf76f614d2a9d95fc3d3c63a9 559_code.wasm
Now we clone the the git clone https://github.com/CosmWasm/cw-tokens.git
repo which conatisn the merkle-drop contract.
git clone https://github.com/CosmWasm/cw-tokens.git
cd cw-tokens
Usually on Linux you would build it like this:
docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/workspace-optimizer:0.12.8
However I reached out to the BadCoin dev and he mentioned he used wasmpack to build the contract. So I did the same.
cargo install [email protected]
Build
cd contracts/cw20-merkle-airdrop
wasm-pack build --target web --out-dir dist
I got this error so I had to add wasm-bindgen to the Cargo.toml file.
Error: Ensure that you have "wasm-bindgen" as a dependency in your Cargo.toml file:
[dependencies]
wasm-bindgen = "0.2"
Caused by: Ensure that you have "wasm-bindgen" as a dependency in your Cargo.toml file:
[dependencies]
wasm-bindgen = "0.2"
Ran it again and it worked, we now have the contract in the dist folder.
Let's verify the hash of the contract.
sha256sum dist/cw20_merkle_airdrop_bg.wasm
The hash of the contract is ca4f6766efad00a54cf553e6c76185b4905365c094d7c7ce6ff2d07ae7450cec
and the hash of the downloaded contract from chain is 0a514d35b6759d5e448afcebe04f2ce33d1665dcf76f614d2a9d95fc3d3c63a9
so we can see that they are not the same.
Next steps is to figure out what platform the contract wa built on and make sure we are on the same platform ,currently I'm on a m1.
I'm trying to get more details on how the Binary was originally built, stay tuned but in the meantime if you want to run this on Linux that would be great. I ran this on M1 and I know the hashes do vary between OS.