Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Aura: Report malice on sibling blocks from the same validator #11160

Merged
merged 4 commits into from
Oct 14, 2019

Conversation

afck
Copy link
Contributor

@afck afck commented Oct 10, 2019

Calls report_malicious if a validator creates multiple sibling blocks in the same step.

This was originally written by @vkomenda (poanetwork#165), then squashed for easier rebasing on master. Cleanup of received_step_hashes was moved to verify_block_family, since on_prepare_block does not exist on master, and a unit test was added.

Original commit messages:

  • added the map of received block header hashes
  • do not return an error and remove older received block records
  • optimised older record removal
  • block hash comparison optimisation and the weak client ref fix
  • SIBLING_MALICE_DETECTION_PERIOD constant
  • review comments
  • using step numbers instead of block numbers

@parity-cla-bot
Copy link

It looks like @afck signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

@seunlanlege
Copy link
Member

failing RPC test strikes again

Copy link
Collaborator

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

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

So the code looks good to me (modulo minor nitpick) but I do not understand the full background&context to the change. Not sure if it's obvious to an expert Aura code reader but I for one would greatly appreciate some more info (perhaps as module-level docs, or if too trivial for that, here in the PR description).

// Report malice if the validator produced other sibling blocks in the same step.
let received_step_key = (step, *header.author());
let new_hash = header.hash();
if self.received_step_hashes.read().get(&received_step_key).into_iter().any(|h| *h != new_hash) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I must be missing something, self.received_step_hashes.read().get(&received_step_key) returns a single H256 yes? Why not if self.received_step_hashes.read().get(&received_step_key) != Some(&new_hash)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

a != Some(b) is true if a is None.
a.into_iter().any(|h| h != b) is false if a is None.

We could use a.map_or(false, |h| h != b). Not sure if that's more readable. After all, we want to say something like: "If the map already contains a hash, and that's different from new_hash, report the block author."

Copy link
Collaborator

@niklasad1 niklasad1 Oct 11, 2019

Choose a reason for hiding this comment

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

IMHO, map_or is more readable in this case

}

// Remove older step hash records.
const SIBLING_MALICE_DETECTION_PERIOD: u64 = 100;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It'd be nice to see a comment on why 100 was chosen.

@afck
Copy link
Contributor Author

afck commented Oct 11, 2019

an expert Aura code reader

It would be really great to get the opinion of one of those!

As far as I understand, this PR fixes an omission: A validator does get reported as malicious if they create a block whose step is not greater than its parent's step. However, they do not get reported if they create two sibling blocks in the same step, which shouldn't be allowed in Aura either.

There's no good reason for the number 100, I think: It just needs to be large enough so that it's likely that any single-slot sibling block pair that could still do damage to consensus would be detected and reported. And not large enough to waste too much memory. (In that respect, 100 seems like a conservative choice to me.)

I'll add some documentation and comments, as far as I can.

@afck
Copy link
Contributor Author

afck commented Oct 11, 2019

I think it might make sense to use the number of validators N instead of 100 here, or maybe 2 N: That would mean we are always able to detect multiple blocks per step in the current and the previous full cycle of steps. After a full cycle, blocks are likely to be finalized, since every validator has already built on top of them, and an attack would not be effective.

If you're okay with that, I'll change the 100 to 2 * validators.count().

Copy link
Collaborator

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

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

LGTM, and thank you for the doc-additions, good stuff, much appreciated.

@afck
Copy link
Contributor Author

afck commented Oct 11, 2019

Great, thank you!
(So I don't replace the 100 with 2 * validators.count()?)

@dvdplm
Copy link
Collaborator

dvdplm commented Oct 11, 2019

Oh missed that, sure that’s not a bad idea.

vkomenda and others added 4 commits October 14, 2019 10:23
This was originally written by @vkomenda, then squashed for
easier rebasing on master. Cleanup of `received_step_hashes`
was moved to `verify_block_family`, since `on_prepare_block`
does not exist on master, and a unit test was added.
Original commit messages:

added the map of received block header hashes

do not return an error and remove older received block records

optimised older record removal

block hash comparison optimisation and the weak client ref fix

SIBLING_MALICE_DETECTION_PERIOD constant

review comments

using step numbers instead of block numbers
Co-Authored-By: David <dvdplm@gmail.com>
@afck
Copy link
Contributor Author

afck commented Oct 14, 2019

Another runner system failure: Cannot connect to the Docker daemon at unix:///var/run/docker.sock..
(I had just rebased to restart the flaky unit test.)

@dvdplm dvdplm merged commit f59ed47 into openethereum:master Oct 14, 2019
@dvdplm
Copy link
Collaborator

dvdplm commented Oct 14, 2019

Best merge before the beast wakes up. ;)

@afck afck deleted the poanetwork-sibling-blocks branch October 14, 2019 11:02
@ordian ordian added this to the 2.7 milestone Oct 16, 2019
@ordian ordian added A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust. labels Oct 16, 2019
dvdplm added a commit that referenced this pull request Oct 24, 2019
* master:
  Type annotation for next_key() matching of json filter options (#11192)
  Crypto primitives removed from ethkey (#11174)
  Made ecrecover implementation trait public (#11188)
  Remove unused macro_use. (#11191)
  [dependencies]: jsonrpc `14.0.1` (#11183)
  [receipt]: add `sender` & `receiver` to `RichReceipts` (#11179)
  [dependencies] bump rand 0.7 (#11022)
  [ethcore/builtin]: do not panic in blake2pricer on short input (#11180)
  TxPermissions ver 3: gas price & data (#11170)
  [ethash] chainspec validate `ecip1017EraRounds` non-zero (#11123)
  util Host: fix a double Read Lock bug in fn Host::session_readable() (#11175)
  ethcore client: fix a double Read Lock bug in fn Client::logs() (#11172)
  Aura: Report malice on sibling blocks from the same validator (#11160)
dvdplm added a commit that referenced this pull request Oct 24, 2019
* master:
  Pause pruning while snapshotting (#11178)
  Type annotation for next_key() matching of json filter options (#11192)
  Crypto primitives removed from ethkey (#11174)
  Made ecrecover implementation trait public (#11188)
  Remove unused macro_use. (#11191)
  [dependencies]: jsonrpc `14.0.1` (#11183)
  [receipt]: add `sender` & `receiver` to `RichReceipts` (#11179)
  [dependencies] bump rand 0.7 (#11022)
  [ethcore/builtin]: do not panic in blake2pricer on short input (#11180)
  TxPermissions ver 3: gas price & data (#11170)
  [ethash] chainspec validate `ecip1017EraRounds` non-zero (#11123)
  util Host: fix a double Read Lock bug in fn Host::session_readable() (#11175)
  ethcore client: fix a double Read Lock bug in fn Client::logs() (#11172)
  Aura: Report malice on sibling blocks from the same validator (#11160)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants