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

PT-168025582 Relax protocol version checks in block serialization #2678

Merged

Conversation

jur0
Copy link
Contributor

@jur0 jur0 commented Aug 21, 2019

PT-168025582

Preparatory PR for fork signalling.

deserialize_[key|micro]_from_binary is called in aec_blocks:deserialize_from_binary which is used in:

  • aeu_import:disklog_fold/3 - not used anywhere?! - module was deleted
  • aec_peer_connection:deserialize_block/2 - when aec_peer_connection wants to insert a new block to the db, it calls aec_conductor:post_block/1 where the block is validated (including the version check).

serialization_template called in aec_blocks:serialize_to_binary used aec_hard_forks:protocol_effective_at_height which is not needed because aec_blocks:serialize_to_binary is called for blocks read from the db, so they were validated for the right protocol version when inserted into the db.

@jur0 jur0 added the status/wip Issues or PRs which are not ready for review or further actions label Aug 21, 2019
@jur0 jur0 self-assigned this Aug 26, 2019
@jur0 jur0 removed the status/wip Issues or PRs which are not ready for review or further actions label Aug 26, 2019
@jur0 jur0 marked this pull request as ready for review August 26, 2019 10:57
@jur0 jur0 force-pushed the PT-168025582-relax-protocol-version-checks-in-block-serialization branch 2 times, most recently from 231cac5 to 662d15f Compare September 4, 2019 10:49
@evdoks evdoks added this to the 5.1.0 milestone Sep 6, 2019
@jur0 jur0 force-pushed the PT-168025582-relax-protocol-version-checks-in-block-serialization branch 4 times, most recently from c111ffb to 4eaa99d Compare September 10, 2019 09:04
@jur0 jur0 force-pushed the PT-168025582-relax-protocol-version-checks-in-block-serialization branch from 4eaa99d to 7852b40 Compare September 13, 2019 10:53
@@ -581,26 +581,21 @@ deserialize_key_from_binary(<<Version:32,
Time:64,
Info/binary
>>) ->
case aec_hard_forks:protocol_effective_at_height(Height) =:= Version of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel uncomfortable by just removing these version checks... I don't see immediately how this can be exploited, but it needs a lot of reasoning to conclude that nobody in the future will add a block on Lima height with Minerva version...

@@ -337,24 +337,14 @@ update_micro_candidate(#mic_block{} = Block, TxsRootHash, RootHash, Txs) ->
serialize_to_binary(#key_block{} = Block) ->
aec_headers:serialize_to_binary(to_key_header(Block));
serialize_to_binary(#mic_block{} = Block) ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For avoiding future misuse of this function. Please add a comment:

%% Serialization assumes the protocol version in the header to be valid for the provided height. This should have been validated before calling this function.

},
{ok, H}
end;
PowEvidence = deserialize_pow_evidence_from_binary(PowEvidenceBin),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same kind of warning in comment here would be in place

Copy link
Contributor

@ThomasArts ThomasArts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some comments to the code to make suree that future generations use the function in the context you assume

@jur0 jur0 force-pushed the PT-168025582-relax-protocol-version-checks-in-block-serialization branch from f437214 to b4d2ea7 Compare September 16, 2019 08:56
%% The function does not check the validity of the protocol version based on
%% height. It gets the protocol version from the block header. The protocol
%% version check based on height is performed before inserting it into the
%% database (aec_conductor).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jur0 jur0 merged commit 6a551c8 into master Sep 24, 2019
@jur0 jur0 deleted the PT-168025582-relax-protocol-version-checks-in-block-serialization branch September 24, 2019 10:12
Err = {error, _} ->
Err
end.
Version = aec_headers:version(Header),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation height/Vsn is lost here. Perhaps add the comment here as well.

Are you sure this is validated elsewhere, and that we do not rely on these checks?

I am more worried about the deserialization than the serialization.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deserialization happens in peer connection which tries to add the deserialized block by calling aec_conductor:post_block and the version check is done there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants