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

Commit

Permalink
Add check on total weight and certificate threshold in `verifyValidat…
Browse files Browse the repository at this point in the history
…orsUpdate` in LIP 0053 (#488)

* add check on total weight and certificate threshold

* Perform editorial edits

---------

Co-authored-by: janhack <29209167+janhack@users.noreply.github.com>
  • Loading branch information
ricott1 and janhack authored Sep 26, 2023
1 parent 1885e14 commit 6bdc73c
Showing 1 changed file with 19 additions and 1 deletion.
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:
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

0 comments on commit 6bdc73c

Please sign in to comment.