Skip to content

Commit

Permalink
fix trusted validators headers
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaczanowski committed Dec 9, 2021
1 parent a77ccaa commit 6113d52
Show file tree
Hide file tree
Showing 16 changed files with 40,929 additions and 31,457 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test/demo/target
test/demo/src/consts.rs
scripts/secret
solidity-protobuf
build
node_modules
2 changes: 1 addition & 1 deletion contracts/TendermintLightClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ contract TendermintLightClient is IClient {
TmHeader.Data memory tmHeader,
Duration.Data memory currentTime
) private view {
// checkTrustedHead
// checkTrustedHeader
// assert that trustedVals is NextValidators of last trusted header
// to do this, we check that trustedVals.Hash() == consState.NextValidatorsHash
require(
Expand Down
6 changes: 6 additions & 0 deletions contracts/mocks/MerkleTreeMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ contract MerkleTreeMock {
uint256 total
) public pure returns (bytes32) {
ValidatorSet.Data memory vs = ValidatorSet.decode(validators);

require(vs.validators.length == total, "requested vs provided validator size differ");
if (total > 0) {
require(vs.validators[0].pub_key.ed25519.length > 0, "expected ed25519 public key, got empty array");
}

return MerkleTree.merkleRootHash(vs.validators, start, total);
}
}
8 changes: 4 additions & 4 deletions contracts/proto/TendermintHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ library TendermintHelper {
});
}

function toConsensusState(TmHeader.Data memory lightBlock) internal pure returns (ConsensusState.Data memory) {
function toConsensusState(TmHeader.Data memory tmHeader) internal pure returns (ConsensusState.Data memory) {
return
ConsensusState.Data({
timestamp: lightBlock.signed_header.header.time,
root: MerkleRoot.Data({hash: lightBlock.signed_header.header.app_hash}),
next_validators_hash: lightBlock.signed_header.header.next_validators_hash
timestamp: tmHeader.signed_header.header.time,
root: MerkleRoot.Data({hash: tmHeader.signed_header.header.app_hash}),
next_validators_hash: tmHeader.signed_header.header.next_validators_hash
});
}

Expand Down
5 changes: 5 additions & 0 deletions scripts/fix_test_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

for f in $(ls test/data/header.*.validator_set.json); do
cat $f | jq -r '.validators=[(.validators[] | (.pub_key=.pub_key.sum))]' | sed 's/Ed25519/ed25519/g' > /tmp/tmp.jq && mv /tmp/tmp.jq $f
done
4 changes: 2 additions & 2 deletions test/Proto.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ const lib = require('./lib.js')

contract('ProtoMock', () => {
it('verifies TmHeader deserialization (with trusted_validator_set)', async () => {
await deserialize(28, 29, true)
await deserialize(8619996, 8619997, true)
})

it('verifies TmHeader deserialization (without trusted_validator_set)', async () => {
await deserialize(28, 29, false)
await deserialize(8619996, 8619997, false)
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ const lib = require('./lib.js')

contract('TendermintLightClient', () => {
it('verifies ingestion of valid continuous headers', async () => {
await ingest(28, 29)
await ingest(8619996, 8619997)
})

it('verifies ingestion of valid non-continuous headers', async () => {
await ingest(28, 30)
await ingest(8619996, 8619998)
})
})

Expand Down
Loading

0 comments on commit 6113d52

Please sign in to comment.