-
Notifications
You must be signed in to change notification settings - Fork 130
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
Solidity contract that accepts unverified substrate headers #65
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, I'd like to see contract metadata file fixed in this PR and the small grumbles, but major things (like RPC caling refactor, or constant extraction) can be done in separate PRs. I will turn them into issues.
} | ||
|
||
/// Initializes bridge contract. | ||
/// @param rawInitialHeader Raw finalized header that will be ancestor of all importing headers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// @param rawInitialHeader Raw finalized header that will be ancestor of all importing headers. | |
/// @param rawInitialHeader Raw finalized header that will be ancestor of all imported headers. |
) public { | ||
// check that header that we're going to finalize is already imported | ||
require( | ||
headerByHash[finalityTargetHash].number == finalityTargetNumber, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It think we should make sure that finalityTargetNumber
is not 0
too:
headerByHash[finalityTargetHash].number == finalityTargetNumber, | |
headerByHash[finalityTargetHash].number == finalityTargetNumber && finalityTargetNumber != 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[SOLIDITY] I'm not against that (will consider that when preparing final version of the contract), but I see nothing criminal in re-finalizing finalized block (genesis in this case) - it just should be a noop. Do you have any other concerns to mention?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since 0
is used for initialized storage as well, I'd prefer to keep it on the safe side here. i.e. with finalityTargetNumber ==0
this check would pass with arbitrarty finalityTargetHash
(i.e. non-existent).
So nothing very specific for now, but just my internal warning side lightning up :)
require( | ||
!headerByHash[header.hash].isKnown, | ||
"Header is already known" | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add an extra check that we are not importing a header with hash=0
or number=0
. We can optimize this later if it turns out not needed.
Just to be on the safe side :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[SOLIDITY] This is checked by the parentHeader.isKnown && parentHeader.number == header.number - 1,
later. So unless we'll have 2^32 headers (which will break contract assumptions anyway), we won't allow to import such headers.
Solc version: 0.6.6+commit.6c089d02 | ||
Source hash (keccak256): 0xdc46aff04e37129265223e507d17f1407a70cb1ecea3230e1eaa77a17586724d | ||
Source gist: https://gist.github.com/svyatonik/876b388f9507a8de242cb2db9547c4f0 | ||
Compiler flags used (command to produce the file): `docker run -i ethereum/solc:0.6.6 --optimize --bin - < substrate-bridge.sol` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙇♂️
) public { | ||
// check that header that we're going to finalize is already imported | ||
require( | ||
headerByHash[finalityTargetHash].number == finalityTargetNumber, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since 0
is used for initialized storage as well, I'd prefer to keep it on the safe side here. i.e. with finalityTargetNumber ==0
this check would pass with arbitrarty finalityTargetHash
(i.e. non-existent).
So nothing very specific for now, but just my internal warning side lightning up :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good for me. There are couple of rename suggestions by @HCastano - I don't really have a strong opinion, cause the plural sounds ok to me, but I'm not a native speaker.
@@ -0,0 +1,5 @@ | |||
Last Change Date: 2020-04-28 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this date necessary? Could we not get this from the commit info?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commits sometimes get lost (when you move to a new repo) or we might move stuff around. I'd prefer to keep it explicitly.
If the structs were some sort of collection I'd be okay with the plurals. Since they're not the naming is a bit awkward. While I would prefer to see them changed, I also don't have a strong enough opinion that I'm going to block this over the naming, lol |
ethabi = "12.0" | ||
ethabi-contract = "11.0" | ||
ethabi-derive = "11.0" | ||
ethereum-tx-sign = { git = "https://github.com/svyatonik/ethereum-tx-sign.git", branch = "up-ethereum-types" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The biggest change of latest merge-with-master - PR is already opened in original repo, but let's refer to my branch for now
…ch#65) * solidity contract * continue * upd * cargo update * fixes * ehtereum_headers -> headers * extracted some common stuff * ethereum_sync.rs -> sync.rs * make sync generic * continue extracting * continue * add eth-contract argument * continue * some fixes * contract v2 * continue * more fixes * more fixes * deal with duplicated params * removed multiple call_rpc variants * bail_on_error!() * fn submit_ethereum_transaction * more fixes * cargo fmt --all * fix * bail_on_arg_error!() * fix * fix * remove async_extra stuff * substrate-bridge.json -> substrate-bridge-abi.json * get rid of substrate transactions hashes * get rid of ethereum transactions hashes * extracted contract bytecode to separate file * cargo fmt --all * avoid duplicate import in contracts * removed Default::default() * swapped configurations for sub2eth && eth2sub * fix compilation * do not double gas limit when submitting Substrate headers * cargo fmt --all * solidity contract removed * consts * extracted solc compilation details to separate file * removed (obsolete in future Vec<u8> justification) * fixed cli option description * fix typos * fix grumble * extracted constants * log decoded header * cargo fmt --all * comment
…ch#65) * solidity contract * continue * upd * cargo update * fixes * ehtereum_headers -> headers * extracted some common stuff * ethereum_sync.rs -> sync.rs * make sync generic * continue extracting * continue * add eth-contract argument * continue * some fixes * contract v2 * continue * more fixes * more fixes * deal with duplicated params * removed multiple call_rpc variants * bail_on_error!() * fn submit_ethereum_transaction * more fixes * cargo fmt --all * fix * bail_on_arg_error!() * fix * fix * remove async_extra stuff * substrate-bridge.json -> substrate-bridge-abi.json * get rid of substrate transactions hashes * get rid of ethereum transactions hashes * extracted contract bytecode to separate file * cargo fmt --all * avoid duplicate import in contracts * removed Default::default() * swapped configurations for sub2eth && eth2sub * fix compilation * do not double gas limit when submitting Substrate headers * cargo fmt --all * solidity contract removed * consts * extracted solc compilation details to separate file * removed (obsolete in future Vec<u8> justification) * fixed cli option description * fix typos * fix grumble * extracted constants * log decoded header * cargo fmt --all * comment
part of #50
This PR introduces:
fn parse_substrate_header()
, which is (almost) completed andfn verify_substrate_finality_proof()
which is unimplemented. This combination allows contract to import Substrate headers, but not to import finality proofs;sub-to-eth
subcommand for the relay to be able to test that headers sync. The pipeline is almost the same as ineth-to-sub
, but we have no extra data to be submitted along with header (like transactions receipts in eth-to-sub). Also just realized that there are some parts of futureAsyncExtra
data sync (which is finality proof in our case) - can remove on demand, just wanted to make separate PRs for headers import and finality proof import;eth-deploy-contract
subcommand for the relay which deploys bridge contract on eth-like chain. We may throw it later, or make a separate binary, but right now I find it much more convenient to have it as a subcommand in relay.Some details:
function importHeaders(bytes[] calldata rawHeaders, bytes calldata rawFinalityProof)
instead of two functions (function importHeader()
andfunction importFinalityProof()
) now. But it might be impossible to fit this data in single transaction in some cases (like when GRANDA validators were unable to finalize headers for some long time);