Innovation Blockchain

Documentation · Coston2 testnet prototype · invented data

Documentation Contracts

Contracts

Two small contracts carry the gate. The proof registry keeps the latest record for each facility. The loan vault allows a draw only when that record is a fresh pass.

Both are prototypes for the Coston2 testnet. The vault is a mock: its credit limit and its draws are plain numbers, and it holds no token.

The proof registry#

ProofRegistry stores one record per facility: the latest one. One address, the submitter, may post records. In the demo the submitter is the extension's contract, so a record reaches the registry only with a machine's signature behind it.

FunctionWhoWhat
submit(facilityKey, record)The submitterStores the record as the facility's latest, if every rule below holds
latest(facilityKey)AnyoneThe stored record, and whether one exists
status(facilityKey)AnyoneThe effective result: a record past its valid-until date reads as FAIL
isFresh(facilityKey)AnyoneTrue while a record exists and is inside its valid-until date
setSubmitter(address)The ownerChanges who may post

What the registry refuses#

RuleError
Only the submitter postsNotSubmitter
A record needs a facility key and a digestZeroFacilityKey, ZeroRecordDigest
A record needs a resultResultNone
The valid-until date is not before the inspection dateValidUntilBeforeInspection
The inspection date is not more than a day in the futureInspectionDateInFuture
No rollback: a record dated before the stored one is refusedOlderThanStoredRecord
No replay: each record digest is accepted onceRecordAlreadyPosted
Matched units cannot exceed scheduled unitsMatchedExceedsScheduled

Two details matter. 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. And 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, so nothing old can come back.

The loan vault#

MockLoanVault is bound to one registry, one facility and one borrower when it is deployed.

FunctionWhoWhat
draw(amount)The borrowerDraws, or reverts with the reason
repay(amount)The borrowerLowers the drawn amount
canDraw(amount)AnyoneWhether a draw would go through, and the reason if not
setAllowDrawWithExceptions(bool)The ownerWhether a PASS_WITH_EXCEPTIONS record lets a draw through
What the vault checks before a draw draw(amount) called by the borrower Is the amount above zero? ZeroAmount Does the registry hold a record? ProofMissing reason NO_RECORD Is it inside its valid-until date? ProofStale reason STALE Is the result other than FAIL? ProofFailed reason FAILED PASS, or exceptions allowed by this vault? ProofHasExceptions EXCEPTIONS_NOT_ALLOWED Within the credit limit? CreditLimitExceeded OVER_CREDIT_LIMIT Draw allowed event DrawAllowed no yes no yes no yes no yes no yes no yes
What the vault checks before a draw. The checks run in this order. The first one that fails refuses the draw with the error on the right.
The same flow in words
  1. The amount must be above zero, or the draw reverts with ZeroAmount.
  2. The registry must hold a record for the facility, or ProofMissing.
  3. The record must be inside its valid-until date, or ProofStale. No transaction is needed for a record to go stale: the clock does it.
  4. The result must not be FAIL, or ProofFailed.
  5. A PASS_WITH_EXCEPTIONS record lets a draw through only if this vault was set to allow it, or ProofHasExceptions.
  6. The amount must fit under the credit limit, or CreditLimitExceeded.
  7. Otherwise the draw goes through and the vault emits DrawAllowed with the record’s digest.
Reason from canDrawError from drawMeaning
NO_RECORDProofMissingThe registry holds no record for the facility
STALEProofStaleThe record is past its valid-until date
FAILEDProofFailedThe latest record is a FAIL
EXCEPTIONS_NOT_ALLOWEDProofHasExceptionsThe record has exceptions and this vault does not lend on them
OVER_CREDIT_LIMITCreditLimitExceededThe amount does not fit under the credit limit

Design points#

Tests#

The contracts have 47 unit tests (Hardhat), and 22 end-to-end cases run the real registry and vault behind the extension's contract and a mock FlareTeeManager (Foundry). The runner runs both every cycle.