Skip to content

Commit

Permalink
Writes bulk of VSR property logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel authored and danwt committed Dec 13, 2022
1 parent 0ba99e8 commit 92939cd
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/difference/core/model/src/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,53 @@ function stakingWithoutSlashing(hist: BlockHistory): boolean {
return true;
}

/**
* Checks the validator set replication property as defined
* https://github.com/cosmos/ibc/blob/main/spec/app/ics-028-cross-chain-validation/system_model_and_properties.md#system-properties
*
* @param hist A history of blocks.
* @returns Is the property satisfied?
*/
function validatorSetReplication(hist: BlockHistory): boolean {
const blocks = hist.blocks;
let good = true;
blocks[C].forEach((b: CommittedBlock) => {
const ss = b.invariantSnapshot;
if (ss.h[C] === 0) {
return
}
// Get the vscid of the last update which dictated
// the consumer valset valsetC committed at hC-1
const vscid = ss.hToVscID[ss.h[C]];
// The VSU packet was sent at height hP-1
const hP = ss.vscIDtoH[vscid];
// Compare the validator sets at hC-1 and hP-1
const valsetC = blocks[C].get(ss.h[C] - 1)!.invariantSnapshot.consumerPower;
// The provider set is implicitly defined by the status and tokens (power)
console.log(`hP: ${hP}`);
const statusP = blocks[P].get(hP - 1)!.invariantSnapshot.status;
const tokensP = blocks[P].get(hP - 1)!.invariantSnapshot.tokens;
assert(valsetC.length === statusP.length, 'this should never happen.');
assert(valsetC.length === tokensP.length, 'this should never happen.');
valsetC.forEach((power, i) => {
if (power !== undefined) { // undefined means the validator is not in the set
good = good && tokensP[i] === power;
}
})
statusP.forEach((status, i) => {
if (status === Status.BONDED) {
const power = tokensP[i];
good = good && valsetC[i] === power;
}
else {
good = good && valsetC[i] === undefined;
}
})

})
return good;
}

/**
* Checks the bond-based consumer voting power property as defined
* in https://github.com/cosmos/ibc/blob/main/spec/app/ics-028-cross-chain-validation/system_model_and_properties.md#system-properties
Expand Down Expand Up @@ -277,4 +324,5 @@ export {
BlockHistory,
stakingWithoutSlashing,
bondBasedConsumerVotingPower,
validatorSetReplication,
};

0 comments on commit 92939cd

Please sign in to comment.