Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Add check on total weight and certificate threshold in verifyValidatorsUpdate in LIP 0053 #488

Merged
merged 3 commits into from
Sep 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion proposals/lip-0053.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Discussions-To: https://research.lisk.com/t/introduce-cross-chain-update-mechani
Status: Draft
Type: Standards Track
Created: 2021-05-22
Updated: 2023-08-28
Updated: 2023-09-26
Requires: 0045, 0049, 0058, 0061
```

Expand Down Expand Up @@ -224,7 +224,25 @@ def verifyValidatorsUpdate(ccu: CCU) -> None:
if len(newActiveValidators) < 1 or len(newActiveValidators) > MAX_NUM_VALIDATORS:
raise Exception(f"Invalid validators array. It must have at least 1 element and at most {MAX_NUM_VALIDATORS} elements.")

totalWeight = 0
for validator in newActiveValidators:
# The bftWeight property of each element is a positive integer.
if validator.bftWeight == 0:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This check is redundant in principle, but I kept it for symmetry with LIP0043. Let me know if you prefer to remove it

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is good to have it. Otherwise, there could maybe be the case that the total weight is 0.

raise Exception("Invalid bftWeight property.")
totalWeight += validator.bftWeight
# Total BFT weight has to be less than or equal to MAX_UINT64.
if totalWeight > MAX_UINT64:
raise Exception("Total BFT weight exceeds maximum value.")

certificateThreshold = ccu.params.certificateThreshold
# The range of valid values of the certificate threshold is given by the total sum of the validators weights:
# Minimum value: floor(1/3 * total BFT weight) + 1.
# Maximum value = total BFT weight.
if certificateThreshold < totalWeight//3 + 1:
raise Exception("Certificate threshold is too small.")
if certificateThreshold > totalWeight:
raise Exception("Certificate threshold is too large.")

# computeValidatorsHash is defined in LIP 0058.
certificate = decode(certificateSchema, ccu.params.certificate)
if certificate.validatorsHash != computeValidatorsHash(newActiveValidators, certificateThreshold):
Expand Down