raiden-network / raiden-contracts

Raiden Network Smart Contracts
MIT License
52 stars 44 forks source link

submit the result of `join-contracts.py` to Etherscan by hand #527

Closed pirapira closed 5 years ago

pirapira commented 5 years ago

To see if outputs from join-contracts.py are useful for Etherscan verification.

pirapira commented 5 years ago

When I print the solc command line arguments from this line

I see

['solc', '--combined-json', 'abi,bin,bin-runtime,metadata,ast', 'raiden=contracts', 'test=contracts/test', 'services=contracts/services', 'contracts/EndpointRegistry.sol', 'contracts/SecretRegistry.sol', 'contracts/TokenNetworkRegistry.sol', 'contracts/Utils.sol', 'contracts/TokenNetwork.sol', 'contracts/Token.sol']
pirapira commented 5 years ago

In raiden-contracts/raiden_contracts I can call join-contracts.py like

utils/join-contracts.py --import-map {} contracts/TokenNetwork.sol flat.sol

and the command finishes with status code zero, but the resulting flat.sol does not contain the definition of Utils. I think this is a bug. https://github.com/raiden-network/raiden-contracts/issues/522

pirapira commented 5 years ago

When I call join-contracts.py with an imort map

utils/join-contracts.py --import-map '{"raiden": "contracts", "test": "contracts/test", "services": "contracts/services"}' contracts/TokenNetwork.sol flat.sol

the resulting flat.sol looks reasonable.

pirapira commented 5 years ago

When I call etherscan_verify with TokenNetwork it succeeds but does nothing. I should have tried TokenNetworkRegistry. The scrips should show the list of valid inputs in this case. https://github.com/raiden-network/raiden-contracts/issues/528

python -m raiden_contracts.deploy.etherscan_verify --apikey <snip> --contract-name TokenNetwork --chain-id 3
pirapira commented 5 years ago

join-contracts.py works on TokenNetworkRegistry.sol too, as expected.

utils/join-contracts.py --import-map '{"raiden": "contracts", "test": "contracts/test", "services": "contracts/services"}' contracts/TokenNetworkRegistry.sol flat.sol

I'm trying to compare the resulting flat.sol against the flatten.sol from the current implementation.

pirapira commented 5 years ago

From raiden-contracts I called

python -m raiden_contracts.deploy.etherscan_verify --apikey <snip> --contract-name TokenNetworkRegistry --chain-id 3

and

diff raiden_contracts/deploy/flatten.sol raiden_contracts/flat.sol

I see differences around solc version pragmas.

1c1,2
< pragma solidity ^0.4.23;pragma solidity ^0.5.2;
---
> pragma solidity ^0.5.2;
>
23d23
< pragma solidity ^0.5.2;
64c64
< pragma solidity ^0.5.2;
---
>
105d104
< pragma solidity ^0.5.2;
155,156d153
< pragma solidity ^0.5.2;
<
1835,1836d1831
< pragma solidity ^0.5.2;
<
1919c1914
< }
---
> }

It seems like the current concatenation in etherscan_verify.py leaves many version pragmas in the result. join-contracts.py leaves only one version pragma (correct).

pirapira commented 5 years ago

Now I'm ready to try the result of join-contracts.py against Etherscan.

First I modify Utils.py a little bit (otherwise Etherscan already knows the Solidity source. It will say: "Contract Source Code Verified (Similar Match)).

Then I compile the contracts by make compile_contracts.

I deploy the TokenNetworkRegistry (and others) by:

raiden-contracts$ python -m raiden_contracts.deploy raiden \
--rpc-provider <snip> \
--private-key <snip> \
--gas-price 30 --gas-limit 6000000

and I see an address on the console

    "TokenNetworkRegistry": "0xc48A9205745372A5bff6ebD5C6584920e784EC40"

I find it on Etherscan: https://kovan.etherscan.io/address/0xc48A9205745372A5bff6ebD5C6584920e784EC40#code and I don't see Solidity source (as expected).

I combine the Solidity sources locally

cd raiden_contracts
utils/join-contracts.py --import-map '{"raiden": "contracts", "test": "contracts/test", "services": "contracts/services"}' contracts/TokenNetworkRegistry.sol flat.sol

and submit it together with

ContractName: TokenNetworkRegistry
compiler: 0.5.2+commit.1df8f40c.Linux.g++
optimization: no
pirapira commented 5 years ago

It seems that was successful.

I see some Solidity code on https://kovan.etherscan.io/address/0xc48A9205745372A5bff6ebD5C6584920e784EC40#code .