Verifying a settlement
Check another party's flexibility settlement: recompute its sha256 digest outside Rust, read it back, diff it, and check a UFTP settlement.
UFTP has the DSO send its settlement to the aggregator for verification. This page is the aggregator's (or an auditor's) side: from the cheapest check to the most thorough.
1. Is the digest the digest of this text?#
A digest is sha256: and the SHA-256 of the canon@1 text, nothing more. Anyone holding the canonical text can recompute it with a standard tool, no Rust needed. The repository ships scripts/digest.sh:
scripts/digest.sh settlement.json # or: ... | scripts/digest.shThe file holds the text exactly as Settlement::canonical() (or Baseline::canonical()) returns it. A single trailing newline is ignored; nothing else is changed. The script uses sha256sum where it exists and shasum -a 256 otherwise. It is equivalent to:
printf 'sha256:%s\n' "$(printf '%s' "$CANONICAL" | shasum -a 256 | cut -d' ' -f1)"Any RFC 8785 (JCS) library gives the same bytes from the parsed text, since every integer is within ±2^53.
For the settlement of UFTP's example:
$ scripts/digest.sh settlement.json
sha256:c7b9655aae3dffb93cd5dfdc321ce95b4518e6289cccccf3905a456e18440efdThe crate's test suite runs this script against the Rust digest.
2. Read the received settlement#
Settlement::from_canonical(&text, zone) turns the received text back into a Settlement. The zone is not in the text; it only labels the ISPs.
let theirs = Settlement::from_canonical(&text, berlin)?;
assert_eq!(theirs.digest(), Digest::of(text.as_bytes()));It refuses (Error::Receipt, naming where in the text) anything that is not what it claims:
| Received | Refused as |
|---|---|
| any whitespace, other key order, an extra or duplicated field, a non-canonical escape | receipt: not in canonical form … |
a profile other than flexibility.settlement@1, an unknown method | a receipt error at profile or method |
| a line or total that the rule does not give from that line's baseline, actual and ordered | receipt at `lines[0].deficiency`: sent 0, the rule gives 500 |
more than MAX_RECEIPT_BYTES, nesting deeper than 8, an integer beyond ±2^53 | before or while reading, without panicking |
So a Settlement you hold is always one the rule computed, whether you computed it or read it, and its digest is the digest of the bytes you received. Disagreement on inputs is what the next step finds.
3. Do I get the same settlement from my own inputs?#
Run the same baseline method with the same parameters and settle on your own copy of the meter data and orders, then compare:
use flexibility::baseline::{self, Mbma};
use flexibility::settle;
let ours = settle(
&baseline::mbma(&our_copy, evening, Mbma { n: 4, gap: 1 })?,
&our_copy.over(evening)?,
&ordered, MeasurementPoint::ConnectionPoint,
)?;
if ours.digest() == their_digest {
// Same method, same parameters, same inputs, same lines.
} else if let Some(difference) = ours.diff(&theirs) {
println!("{difference}"); // e.g. ISP 71 (17:30–17:45 +01:00): actual ours 4 kW, theirs 4.001 kW
}theirs is what step 2 read; their_digest can also be parsed from text: "sha256:00af5069…".parse::<flexibility::Digest>()?. The full program is examples/verify_a_receipt.rs: cargo run --example verify_a_receipt. The input digests in the canonical text (inputs.actual, inputs.baseline, inputs.ordered) tell you which input disagrees before you compare a single line; see Comparing two settlements.
4. Is a received UFTP settlement consistent?#
With the uftp feature, uftp::check checks a FlexOrderSettlement message from its own fields (no baseline or meter data needed), and uftp::compare against your own settlement; see UFTP for both.
use flexibility::uftp::{self, FlexSign};
assert_eq!(uftp::check(&message, FlexSign::AsOrdered)?, []);
assert_eq!(uftp::compare(&message, &ours, FlexSign::AsOrdered)?, []);A DSO that forgot the deficiency in ISP 73:
ISP 73: PowerDeficiency sent 0 W, expected -50 kWBoth return every discrepancy, in ISP order. sign is how the wire signs delivered and deficiency; see UFTP.
What verification does not prove#
- That the inputs are true. A wrong meter series gives a correct settlement of a wrong series. Digests prove which series was used, not that it is right.
- Who sent it.
Provenanceis opaque. Identity and signatures are the transport's: UFTP messages are signed. - That the method is fit for the site. Accuracy measures that; the grid operator decides.