Skip to content

Commit

Permalink
random source generatation doc/postconditions
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanschalm committed Oct 17, 2024
1 parent 4a8ec3b commit e519e2c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions contracts/epochs/FlowEpoch.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ access(all) contract FlowEpoch {
/// using the same procedure as during a spork.
/// CAUTION: Validity of the QCs is not explicitly verified during the recovery process. An
/// invalid cluster QC will prevent the respective cluster from starting its local consensus
/// and hence prevent if from functioning for the entire epoch. If all cluster QCs are invalid,
/// and hence prevent it from functioning for the entire epoch. If all cluster QCs are invalid,
/// the blockchain cannot ingest transactions, which can only be resolved through a spork!
clusterQCVoteData: [FlowClusterQC.ClusterQCVoteData],

Expand Down Expand Up @@ -433,15 +433,16 @@ access(all) contract FlowEpoch {
}
}

/// Generates 128 bits of randomness using system random (derived from Random Beacon).
access(contract) fun generateRandomSource(): String {
/// random source must be a hex string of 32 characters (i.e 16 bytes or 128 bits)
/// `revertibleRandom` returns a UInt64 (8 bytes)
post {
result.length == 32:
"FlowEpoch.generateRandomSource: Critical invariant violated! "
.concat("Expected hex random source with length 32 (128 bits) but got length ")
.concat(result.length.toString())
.concat(" instead.")
}
var randomSource = String.encodeHex(revertibleRandom<UInt128>().toBigEndianBytes())
assert (
randomSource.length == 32,
message: "Random source must be a hex string of 32 characters"
)

return randomSource
}

Expand Down

0 comments on commit e519e2c

Please sign in to comment.