Skip to content

Commit

Permalink
Merge latest changes from master
Browse files Browse the repository at this point in the history
Signed-off-by: Thane Thomson <[email protected]>
  • Loading branch information
thanethomson committed Oct 23, 2020
2 parents 953f9a0 + 34a2386 commit 335e7e9
Show file tree
Hide file tree
Showing 11 changed files with 442 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# These are log files emitted by model-based tests
**/*.log
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## Unreleased

### BUG FIXES:

- `[light-client]` Fix bug where a commit with only absent signatures would be
deemed valid instead of invalid ([#650])

[#652]: https://github.com/informalsystems/tendermint-rs/issues/650

## v0.17.0-rc1

*Oct 15, 2020*
Expand Down
14 changes: 9 additions & 5 deletions light-client/src/operations/commit_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,22 @@ impl CommitValidator for ProdCommitValidator {
signed_header: &SignedHeader,
validator_set: &ValidatorSet,
) -> Result<(), VerificationError> {
// TODO: `self.commit.block_id` cannot be zero in the same way as in Go
// Clarify if this another encoding related issue
if signed_header.commit.signatures.len() == 0 {
let signatures = &signed_header.commit.signatures;

// Check the the commit contains at least one non-absent signature.
// See https://github.com/informalsystems/tendermint-rs/issues/650
let has_present_signatures = signatures.iter().any(|cs| !cs.is_absent());
if !has_present_signatures {
bail!(VerificationError::ImplementationSpecific(
"no signatures for commit".to_string()
));
}

if signed_header.commit.signatures.len() != validator_set.validators().len() {
// Check that that the number of signatures matches the number of validators.
if signatures.len() != validator_set.validators().len() {
bail!(VerificationError::ImplementationSpecific(format!(
"pre-commit length: {} doesn't match validator length: {}",
signed_header.commit.signatures.len(),
signatures.len(),
validator_set.validators().len()
)));
}
Expand Down
14 changes: 7 additions & 7 deletions light-client/src/predicates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@ pub fn verify(
&trusted.signed_header.header,
)?;

// Verify that more than 2/3 of the validators correctly committed the block.
vp.has_sufficient_signers_overlap(
&untrusted.signed_header,
&untrusted.validators,
voting_power_calculator,
)?;

let trusted_next_height = trusted.height().increment();

if untrusted.height() == trusted_next_height {
Expand All @@ -285,12 +292,5 @@ pub fn verify(
)?;
}

// Verify that more than 2/3 of the validators correctly committed the block.
vp.has_sufficient_signers_overlap(
&untrusted.signed_header,
&untrusted.validators,
voting_power_calculator,
)?;

Ok(())
}
2 changes: 1 addition & 1 deletion testgen/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl Generator<block::Commit> for Commit {
let block_header = header.generate()?;
let block_id = block::Id {
hash: block_header.hash(),
part_set_header: PartSetHeader::default(),
part_set_header: PartSetHeader::new(1, block_header.hash()),
};
let votes = match &self.votes {
None => self.clone().generate_default_votes().votes.unwrap(),
Expand Down
20 changes: 19 additions & 1 deletion testgen/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ impl Header {
set_option!(height, u64);
set_option!(time, u64);
set_option!(proposer, usize);

pub fn next(&self) -> Self {
let height = self.height.expect("Missing previous header's height");
let time = self.time.unwrap_or(height); // if no time is found, then we simple correspond it to the header height
let validators = self.validators.clone().expect("Missing validators");
let next_validators = self.next_validators.clone().unwrap_or(validators);

Self {
validators: Some(next_validators.clone()),
next_validators: Some(next_validators),
chain_id: self.chain_id.clone(),
height: Some(height + 1),
time: Some(time + 1),
proposer: self.proposer, // TODO: proposer must be incremented
}
}
}

impl std::str::FromStr for Header {
Expand Down Expand Up @@ -106,7 +122,9 @@ impl Generator<block::Header> for Header {
tendermint::Time::now()
};
let header = block::Header {
version: block::header::Version { block: 0, app: 0 },
// block version in Tendermint-go is hardcoded with value 11
// so we do the same with MBT for now for compatibility
version: block::header::Version { block: 11, app: 0 },
chain_id,
height: block::Height::try_from(self.height.unwrap_or(1))
.map_err(|_| SimpleError::new("height out of bounds"))?,
Expand Down
4 changes: 4 additions & 0 deletions testgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ pub mod commit;
pub mod consensus;
pub mod generator;
pub mod header;
pub mod light_block;
pub mod light_chain;
pub mod time;
pub mod validator;
pub mod vote;

pub use commit::Commit;
pub use generator::Generator;
pub use header::Header;
pub use light_block::LightBlock;
pub use light_chain::LightChain;
pub use time::Time;
pub use validator::Validator;
pub use vote::Vote;
Expand Down
Loading

0 comments on commit 335e7e9

Please sign in to comment.