Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix runtime bytecode check when deploying a contract #408

Closed
loredanacirstea opened this issue Jan 8, 2019 · 12 comments
Closed

Fix runtime bytecode check when deploying a contract #408

loredanacirstea opened this issue Jan 8, 2019 · 12 comments
Assignees
Labels
bug Something isn't working

Comments

@loredanacirstea
Copy link
Contributor

loredanacirstea commented Jan 8, 2019

From: #397
The runtime bytecode calculation is wrong here and might fail for other systems on which solc in stalled:

# Check that the deployed bytecode matches the precompiled data
blockchain_bytecode = web3.eth.getCode(endpoint_registry_address).hex()
compiled_bytecode = contract_manager.contracts[CONTRACT_ENDPOINT_REGISTRY]['bin']
# Compiled code contains some additional initial data compared to the blockchain bytecode
compiled_bytecode = compiled_bytecode[-len(blockchain_bytecode):]
compiled_bytecode = hex(int(compiled_bytecode, 16))
assert blockchain_bytecode == compiled_bytecode

Needs to be fixed for all subsequent occurrences.

@pirapira started working on this in #405.

@pirapira
Copy link
Contributor

pirapira commented Jan 8, 2019

@loredanacirstea Do you mean
a. we should use solc --runtime-bin to get the runtime code, or
b. there is a mistake in those few lines that should be changed?

@pirapira
Copy link
Contributor

pirapira commented Jan 8, 2019

Maybe I can see this problem with solc 0.5.*.

@loredanacirstea
Copy link
Contributor Author

loredanacirstea commented Jan 8, 2019

@pirapira I suspect there might be a mistake in compiled_bytecode = compiled_bytecode[-len(blockchain_bytecode):] if this verification fails for some systems.
We need a clear understanding of how the compiled_bytecode is produced and what it contains (length, meaning).

Otherwise, determine the external failure reason. In the initial complaint (#397), there was also another bug that recompiled the contracts when deploying, fixed by #407.
So, the above bytecode assert was between that newly recompiled data and the locally deployed contract. I asked for the compiled data, to see if we can reproduce it: #397 (comment)

@pirapira
Copy link
Contributor

pirapira commented Jan 8, 2019

Now I can reproduce the issue.

  File "/home/yh/src/raiden-contracts/raiden_contracts/deploy/__main__.py", line 520, in verify_deployed_contracts
    assert blockchain_bytecode == compiled_bytecode, f"different\n{blockchain_bytecode}\n{compiled_bytecode}"
AssertionError: different
0x608060405260043610610057576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063028a582e1461005c57806308b5a85a14610118578063b32c65c814610181575b600080fd5b34801561006857600080fd5b5061009d600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610211565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100dd5780820151818401526020810190506100c2565b50505050905090810190601f16801561010a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561012457600080fd5b5061017f600480360381019080803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091929192905050506102f1565b005b34801561018d57600080fd5b5061019661051a565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101d65780820151818401526020810190506101bb565b50505050905090810190601f1680156102035780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60606000808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102e55780601f106102ba576101008083540402835291602001916102e5565b820191906000526020600020905b8154815290600101906020018083116102c857829003601f168201915b50505050509050919050565b60008160011515610312826020604051908101604052806000815250610553565b15151415151561032157600080fd5b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000209150610404828054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156103f95780601f106103ce576101008083540402835291602001916103f9565b820191906000526020600020905b8154815290600101906020018083116103dc57829003601f168201915b505050505084610553565b1561040e57610515565b826000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000209080519060200190610460929190610715565b503373ffffffffffffffffffffffffffffffffffffffff167f3a62a9d7855df5303e50b0440124304fefafde7f677fc33787b784fc92cfa618846040518080602001828103825283818151815260200191508051906020019080838360005b838110156104da5780820151818401526020810190506104bf565b50505050905090810190601f1680156105075780820380516001836020036101000a031916815260200191505b509250505060405180910390a25b505050565b6040805190810160405280600581526020017f302e342e3000000000000000000000000000000000000000000000000000000081525081565b6000816040516020018082805190602001908083835b60208310151561058e5780518252602082019150602081019050602083039250610569565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040516020818303038152906040526040518082805190602001908083835b6020831015156105f757805182526020820191506020810190506020830392506105d2565b6001836020036101000a038019825116818451168082178552505050505050905001915050604051809103902060001916836040516020018082805190602001908083835b602083101515610661578051825260208201915060208101905060208303925061063c565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040516020818303038152906040526040518082805190602001908083835b6020831015156106ca57805182526020820191506020810190506020830392506106a5565b6001836020036101000a038019825116818451168082178552505050505050905001915050604051809103902060001916141561070a576001905061070f565b600090505b92915050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061075657805160ff1916838001178555610784565b82800160010185558215610784579182015b82811115610783578251825591602001919060010190610768565b5b5090506107919190610795565b5090565b6107b791905b808211156107b357600081600090555060010161079b565b5090565b905600a165627a7a723058202e51600359afb37e313d2e4e164e3b30fa212402b886de76edeb837154e15acc0029
0x608060405260043610610057576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063028a582e1461005c57806308b5a85a14610118578063b32c65c814610181575b600080fd5b34801561006857600080fd5b5061009d600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610211565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100dd5780820151818401526020810190506100c2565b50505050905090810190601f16801561010a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561012457600080fd5b5061017f600480360381019080803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091929192905050506102f1565b005b34801561018d57600080fd5b5061019661051a565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101d65780820151818401526020810190506101bb565b50505050905090810190601f1680156102035780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60606000808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102e55780601f106102ba576101008083540402835291602001916102e5565b820191906000526020600020905b8154815290600101906020018083116102c857829003601f168201915b50505050509050919050565b60008160011515610312826020604051908101604052806000815250610553565b15151415151561032157600080fd5b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000209150610404828054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156103f95780601f106103ce576101008083540402835291602001916103f9565b820191906000526020600020905b8154815290600101906020018083116103dc57829003601f168201915b505050505084610553565b1561040e57610515565b826000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000209080519060200190610460929190610715565b503373ffffffffffffffffffffffffffffffffffffffff167f3a62a9d7855df5303e50b0440124304fefafde7f677fc33787b784fc92cfa618846040518080602001828103825283818151815260200191508051906020019080838360005b838110156104da5780820151818401526020810190506104bf565b50505050905090810190601f1680156105075780820380516001836020036101000a031916815260200191505b509250505060405180910390a25b505050565b6040805190810160405280600581526020017f302e342e3000000000000000000000000000000000000000000000000000000081525081565b6000816040516020018082805190602001908083835b60208310151561058e5780518252602082019150602081019050602083039250610569565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040516020818303038152906040526040518082805190602001908083835b6020831015156105f757805182526020820191506020810190506020830392506105d2565b6001836020036101000a038019825116818451168082178552505050505050905001915050604051809103902060001916836040516020018082805190602001908083835b602083101515610661578051825260208201915060208101905060208303925061063c565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040516020818303038152906040526040518082805190602001908083835b6020831015156106ca57805182526020820191506020810190506020830392506106a5565b6001836020036101000a038019825116818451168082178552505050505050905001915050604051809103902060001916141561070a576001905061070f565b600090505b92915050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061075657805160ff1916838001178555610784565b82800160010185558215610784579182015b82811115610783578251825591602001919060010190610768565b5b5090506107919190610795565b5090565b6107b791905b808211156107b357600081600090555060010161079b565b5090565b905600a165627a7a72305820c3cbd322f60d7e7b226eadd043fc54df6c59af0a84fa6e39489f483b8d00e2cb0029

@pirapira
Copy link
Contributor

pirapira commented Jan 8, 2019

Now the differences are only at the end. These are probably contract metadata hashes.

@pirapira
Copy link
Contributor

pirapira commented Jan 8, 2019

The metadata contains the absolute path where things are compiled, so it can be different on each machine

\"remappings\":[\":raiden=/Users/loredana/ETH/raiden-contracts/raiden_contracts/contracts\",

pirapira added a commit to pirapira/raiden-contracts that referenced this issue Jan 8, 2019
Previously, contracts.json contained some absolute paths with user names
and so on. This caused verification failures after a user compiles a
contract locally. The absolute paths were used in the contract metadata
and were included in the metadata hash at the end of the deployed code.

This was one cause of
raiden-network#408
@pirapira
Copy link
Contributor

pirapira commented Jan 8, 2019

This issue will go away after #414 is merged and a new version of contracts are deployed. Because the user names like /home/yh will not be contained in the metadata.

@loredanacirstea do you also want a temporary fix that works with the currently deployed contracts?

@loredanacirstea
Copy link
Contributor Author

I don't think we need the temporary fix for now. We should not get this issue in practice, after fixing the deploy script to not recompile.
Your PR should be enough, thank you!

@loredanacirstea loredanacirstea added the Needs redeployment The issue/PR results in a breaking change in the precompiled data in `contracts.json` ->redeployment label Jan 9, 2019
@pirapira
Copy link
Contributor

So #430 will close this issue. Since we change contracts.json frequently, we don't need a redeployment.

@pirapira pirapira removed the Needs redeployment The issue/PR results in a breaking change in the precompiled data in `contracts.json` ->redeployment label Jan 10, 2019
@pirapira
Copy link
Contributor

And #435 removes all iffy code.

@pirapira
Copy link
Contributor

@loredanacirstea please close this when the relevant PRs are merged.

@pirapira pirapira assigned loredanacirstea and unassigned pirapira Jan 10, 2019
@loredanacirstea
Copy link
Contributor Author

Done, #435 and #434 have been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants