Documentation Contracts
Contracts
Two small contracts carry the gate. The proof registry is a notice board for signed records, with no owner. The loan vault belongs to the lender, who pins the one inspector key and the one schedule it accepts.
Status. ProofRegistryV2 and LoanVaultV2 are tested on a local chain. The owner has not deployed them on Coston2. The pair that is on Coston2 is registry v1, the earlier demo, described in the second half of this page. Both vaults are mocks: the credit limit and the draws are plain numbers, and no token or value moves.
The proof registry: ProofRegistryV2#
A notice board. It has no owner, no submitter, no constructor argument, no admin function and no upgrade hook. Anyone may relay a record. The registry recomputes the digest from the fields it is given, checks the signature over that digest, and files the record under the signing address: one slot per facility and signer.
It does not say who is an inspector. A signature shows who issued a record and that no field changed afterwards. It does not show that the facts in the record are true.
| Function | Who | What |
|---|---|---|
submit(facilityKey, record, signer, signature) | Anyone | Stores the record in the slot of that facility and signer, if every rule below holds |
revoke(signer, signature) | Anyone | Revokes a key for good. The signature must be the signer's own, over revocationDigest(signer) |
recordDigest(facilityKey, record) | Anyone, a pure read | SHA-256 over the record tag, the facility key and the 13 fields: 480 bytes |
revocationDigest(signer) | Anyone, a pure read | SHA-256 over the revocation tag and the address: 64 bytes |
latest(facilityKey, signer) | Anyone | The stored record, its digest (recomputed, not stored) and whether one exists |
status(facilityKey, signer) | Anyone | The effective result. No record, a record past its valid-until, or a revoked signer reads as FAIL |
isFresh(facilityKey, signer) | Anyone | True when a record exists, is not past its valid-until and the signer is not revoked |
isRevoked(signer), revokedAt(signer) | Anyone | Whether a key was revoked, and the block time when |
The record on chain#
Thirteen fields, in exactly the order of the digest, so the digest is one encoding of the struct.
| Field | Type |
|---|---|
inspectorKey | bytes32, SHA-256 of the inspector id |
scheduleHash, reportHash | bytes32 |
inspectionDate, issuedAt, validUntil | uint64, unix seconds |
scheduled, matched, sighted, exceptions | uint32 |
procedures | uint16, bit 0 = procedure 6.1 up to bit 7 = procedure 6.8 |
engagementType | F = 0, Q = 1, E = 2 |
result | NONE = 0 (never stored), PASS = 1, PASS_WITH_EXCEPTIONS = 2, FAIL = 3 |
What the registry refuses#
submit reverts with the first of these that applies, in this order. Nothing is stored on a revert.
| Order | Error | When |
|---|---|---|
| 1 | ZeroFacilityKey | The facility key is zero |
| 2 | ZeroInspectorKey | inspectorKey is zero |
| 3 | ResultNone | The result is NONE |
| 4 | BadSignatureLength | The signature is not 65 bytes. An unsigned record stops here |
| 5 | BadSignature | The last byte is not 27 or 28, s is above half the curve order, or no address can be recovered |
| 6 | SignerMismatch | The signature does not recover to signer. Any field changed after signing ends here, and so does a signature by another key |
| 7 | SignerRevoked | The signer has been revoked |
| 8 | IssuedInFuture | issuedAt is more than 15 minutes ahead of the block time |
| 9 | InspectionAfterIssue | inspectionDate is more than one day after issuedAt |
| 10 | ValidUntilBeforeInspection | validUntil is earlier than inspectionDate |
| 11 | ValidityTooLong | validUntil is more than 105 days after inspectionDate |
| 12 | NoProcedures | procedures is zero |
| 13 | UnknownProcedure | procedures has a bit above bit 7 |
| 14 | MatchedExceedsScheduled | matched is above scheduled |
| 15 | SightedExceedsScheduled | sighted is above scheduled |
| 16 | SightedWithoutProcedure | sighted is not zero and procedure 6.3 is not listed |
| 17 | EmptySchedule | A PASS or PASS_WITH_EXCEPTIONS with scheduled zero |
| 18 | InconsistentPass | A PASS with exceptions, or with matched below scheduled |
| 19 | NotNewerThanStored | issuedAt is not later than the stored record of this signer for this facility |
A result or engagement type outside the allowed values reverts while the call data is decoded, with no named error.
There is no check that a record is still inside its validity. A FAIL must be able to land late. A late PASS is stored too, and reads as stale.
revoke refuses BadSignatureLength, BadSignature, SignerMismatch and AlreadyRevoked. A revocation is permanent. A lost key cannot be revoked. See Keys.
Constants#
| Constant | Value | Meaning |
|---|---|---|
RECORD_TAG | SHA-256 of the text ibc-proof-record/1 | Word 0 of the record digest |
REVOKE_TAG | SHA-256 of the text ibc-key-revocation/1 | Word 0 of the revocation digest |
MAX_VALIDITY | 105 days (9,072,000 seconds) | The longest time from inspectionDate to validUntil |
CLOCK_TOLERANCE | 15 minutes (900 seconds) | How far ahead of the block time issuedAt may be |
DATE_TOLERANCE | 1 day | How far ahead of issuedAt the inspection date may be. It covers a site east of UTC |
KNOWN_PROCEDURES | 0x00ff | Procedures 6.1 to 6.8 |
PROCEDURE_SIGHTING | 0x0004 | Bit 2: procedure 6.3, physical sighting |
Events: ProofSubmitted(facilityKey, signer, inspectorKey, digest, result, relayer) and KeyRevoked(signer, revokedAt, relayer). The relayer has no standing.
The lender's vault: LoanVaultV2#
A mock loan facility for one facility. What it shows is the gate, and that the gate belongs to the lender. Nobody else can open a draw: not the registry, not a relayer, not the borrower. A record signed by any other address than the pinned one is not read.
Fixed at deployment: registry, facilityKey, lender, borrower, creditLimit. The constructor takes, in this order: registry, facilityKey, lender, borrower, creditLimit, inspector, scheduleHash, maxRecordAge, requiredProcedures, allowDrawWithExceptions. It refuses a zero address, a zero facility key, a zero schedule hash, and a requiredProcedures of zero or with a bit above bit 7.
Only the lender can change these. Each change emits an event.
| Setting | Call | Meaning |
|---|---|---|
inspector | setInspector(address) | The one signing address whose records the vault reads. Take it from the engagement letter |
scheduleHash | setScheduleHash(bytes32) | The collateral schedule the loan was made against |
maxRecordAge | setMaxRecordAge(uint64) | Longest age in seconds from inspectionDate. Zero means no limit beyond validUntil |
requiredProcedures | setRequiredProcedures(uint16) | The procedures a record must cover. Never zero |
allowDrawWithExceptions | setAllowDrawWithExceptions(bool) | Whether PASS_WITH_EXCEPTIONS allows a draw |
paused | setPaused(bool) | While true, every draw is refused. Repayment stays open |
secondFact | setSecondFact(address) | A contract that must confirm a second fact about the record. Zero means none |
| Function | Who | What |
|---|---|---|
draw(amount) | The borrower | Records a draw, or reverts with a named error |
repay(amount) | The borrower | A mock. The borrower reports the repayment itself. Nothing checks it, and it is not gated by the proof or the pause |
canDraw(amount) | Anyone | Whether a draw would go through, and the reason if not |
drawRefusal(amount) | Anyone | The same check as a code, for other contracts |
available() | Anyone | The credit limit minus the drawn amount |
What the vault refuses#
The reason is the first of these that applies, in this order.
The same flow in words
- The amount must be above zero, or the draw reverts with
ZeroAmount. - The lender must not have paused the vault, or
VaultPaused. - The registry must hold a record for the facility in the slot of the pinned signing address, or
ProofMissing. A record signed by any other address is not read. - The pinned address must not be revoked, or
InspectorRevoked. - The record’s schedule hash must equal the one the lender pinned, or
ScheduleMismatch. - The block time must not be past the record’s valid-until, or past the inspection date plus the lender’s maximum age, or
ProofStale. No transaction is needed for a record to go stale: the clock does it. - The result must not be FAIL, or
ProofFailed. - The record must cover every procedure the lender requires, or
ScopeTooNarrow. - A PASS_WITH_EXCEPTIONS record lets a draw through only if the lender allowed it, or
ProofHasExceptions. - If the lender named a second-fact contract, it must answer true for this record’s digest, or
SecondFactMissing. - The amount must fit under the credit limit, or
CreditLimitExceeded. - Otherwise the draw goes through and the vault emits
DrawAllowedwith the record’s digest and the pinned address.
| Order | Reason from canDraw | Error from draw | When |
|---|---|---|---|
| 1 | ZERO_AMOUNT | ZeroAmount | The amount is zero |
| 2 | PAUSED | VaultPaused | The lender has paused the vault |
| 3 | NO_RECORD | ProofMissing | The registry holds no record signed by the pinned address for this facility |
| 4 | INSPECTOR_REVOKED | InspectorRevoked | The pinned address has been revoked |
| 5 | SCHEDULE_MISMATCH | ScheduleMismatch | The record's scheduleHash is not the pinned one |
| 6 | STALE | ProofStale | The block time is past validUntil, or past inspectionDate plus maxRecordAge |
| 7 | FAILED | ProofFailed | The result is FAIL |
| 8 | SCOPE_TOO_NARROW | ScopeTooNarrow | The record does not cover every required procedure |
| 9 | EXCEPTIONS_NOT_ALLOWED | ProofHasExceptions | The result is PASS_WITH_EXCEPTIONS and the lender has not allowed it |
| 10 | SECOND_FACT_MISSING | SecondFactMissing | A second-fact contract is set and does not answer true for this record's digest |
| 11 | OVER_CREDIT_LIMIT | CreditLimitExceeded | The amount is above what is left of the credit limit |
The second fact#
ISecondFact is one read function: holds(facilityKey, recordDigest). When the lender names such a contract, the vault asks it about the record it is reading, by that record's digest.
- Only a call that succeeds and returns exactly one word with the value 1 counts as true.
- A call that reverts or runs out of gas, an address with no code, and any other return data count as not true.
- The call is a static call, so the second-fact contract cannot change the vault.
Nothing implements ISecondFact yet, except mocks used in the tests. The Flare Confidential Compute extension is planned to become an implementation in a later package. See FCC extension.
Design points#
- The signature decides, not the sender. The registry takes a record from anyone. What matters is whose key signed it.
- The lender's pin is the control. Names are self-declared. The registry binds no name to a key. The vault reads one key's slot and nothing else.
- The clock closes the gate. A record goes stale with no transaction. A lender does not depend on anyone to act.
- The vault reads, the registry stores. The vault holds no copy of a record. It asks the registry at every draw.
- Nothing signed names a chain. A signed record, and a signed revocation, can be relayed to any copy of this registry. Sample records carry names that say they are tests.
Limits of the signed-record pair#
- Whoever holds the pinned key can post a PASS until the lender repins or the key is revoked.
- After the lender repins, the vault reads
NO_RECORDuntil the new key has signed a record. - A stored FAIL that is past its
validUntilreadsSTALEin the vault, notFAILED. The draw is refused either way. - A record with the same
issuedAtas the stored one is refused, also when it is a FAIL. A correction needs a laterissuedAt. issuedAtmay be up to 15 minutes ahead of the block time. For that long, a signer's own future-dated record holds back his earlier-dated one.- The registry stores what is relayed to it. A signed FAIL that nobody relays is not seen.
- The vault reads the registry address it was deployed with and cannot change it. Whoever deploys a vault chooses that address, the lender, the borrower and the first settings. A lender should read them back before relying on the vault.
- The contract folder has no deploy script for this pair. The Coston2 driver
coston2-v2.shdeploys it; see Coston2 demo.
The wider picture is on Who is trusted for what.
Tests#
The Hardhat suite has 126 tests for both pairs, as measured on 23 November 2026: 79 for the signed-record pair, which read the shared test vectors, and 47 for registry v1. A further 22 end-to-end cases run registry v1 and its vault behind the extension's contract and a mock FlareTeeManager (Foundry). The runner runs both suites every cycle.
Registry v1 and its vault, the earlier demo shown on Coston2#
The rest of this page describes ProofRegistry and MockLoanVault, as deployed on Coston2 on 22 November 2026. They are kept unchanged as a dated demo. Their addresses are on Addresses and reference.
ProofRegistry stores one record per facility: the latest one. One address, the submitter, may post records. It checks no signature and does not recompute the digest. Its owner can change the submitter at any time. In the demo the submitter is the extension's contract, so a record reaches the registry only with a test machine's signature behind it.
| Function | Who | What |
|---|---|---|
submit(facilityKey, record) | The submitter | Stores the record as the facility's latest, if every rule below holds |
latest(facilityKey) | Anyone | The stored record, and whether one exists |
status(facilityKey) | Anyone | The effective result: a record past its valid-until date reads as FAIL |
isFresh(facilityKey) | Anyone | True while a record exists and is inside its valid-until date |
setSubmitter(address) | The owner | Changes who may post |
What registry v1 refuses#
| Rule | Error |
|---|---|
| Only the submitter posts | NotSubmitter |
| A record needs a facility key and a digest | ZeroFacilityKey, ZeroRecordDigest |
| A record needs a result | ResultNone |
| The valid-until date is not before the inspection date | ValidUntilBeforeInspection |
| The inspection date is not more than a day in the future | InspectionDateInFuture |
| No rollback: a record dated before the stored one is refused | OlderThanStoredRecord |
| No replay: each record digest is accepted once | RecordAlreadyPosted |
| Matched units cannot exceed scheduled units | MatchedExceedsScheduled |
A record with the same date as the stored one is accepted, so a correction can be posted the same day as a new record with a new digest. A FAIL for the record that is stored now may always land, so a later failed check of the same record closes the gate, while a PASS for a used digest stays refused.
The v1 vault#
MockLoanVault is bound to one registry, one facility and one borrower when it is deployed.
| Function | Who | What |
|---|---|---|
draw(amount) | The borrower | Draws, or reverts with the reason |
repay(amount) | The borrower | Lowers the drawn amount |
canDraw(amount) | Anyone | Whether a draw would go through, and the reason if not |
setAllowDrawWithExceptions(bool) | The owner | Whether a PASS_WITH_EXCEPTIONS record lets a draw through |
Reason from canDraw | Error from draw | Meaning |
|---|---|---|
NO_RECORD | ProofMissing | The registry holds no record for the facility |
STALE | ProofStale | The record is past its valid-until date |
FAILED | ProofFailed | The latest record is a FAIL |
EXCEPTIONS_NOT_ALLOWED | ProofHasExceptions | The record has exceptions and this vault does not lend on them |
OVER_CREDIT_LIMIT | CreditLimitExceeded | The amount does not fit under the credit limit |
Trust that remains in v1#
- The registry trusts its submitter. It does not check that the digest matches the other fields.
- The registry's owner can call
setSubmitteragain at any time, and so can open the vault. - A record dated tomorrow is accepted, and then blocks a record dated today.
- The lender has no role in the contracts.
These are the gaps the signed record closes. See Who is trusted for what.