Loading…
package goe_dtr_mint import future.keywords # GOE × Newton · CFN Exporter Verification Rulebook (draft of 11 Nov 2026,# updated 12 Nov; parameters and evaluation_date 19 Nov), Mint flow: checked# before Custody mints the dTR.## A Mint request is allowed only when it passes every rule below: K1-K7 and# K9. If any rule fails, it is rejected, and `reasons` lists the code of every# rule that failed, not just the first.## Every rule fails closed: a missing or malformed value counts as a failure.# Newton checks completeness, format, dates, figures and duplicates. Whether# the information is true is CFN's responsibility (clause 15.2).## This policy reads three things:# input the request CFN signed, mintDtr(...); `request` names its fields# data.wasm what the data oracle (oracle/mint.js) found: the Tax ID check,# the on-chain invoice lookup and CFN's evaluation date# data.params the limits GOE can change without changing this code## Keep the word for "who someone is" (it starts "ident") out of this file: the# Sepolia testnet gateway sends any policy containing it down an enclave path# that isn't available yet, and every evaluation fails. default allow := false allow if count(reasons) == 0 # ---- The request ------------------------------------------------------------ mint_v1_signature := "function mintDtr(string requestId, string schemaVersion, bytes32 schemaHash, bytes32 exporterNameHash, bytes taxIdCiphertext, bytes32 importerNameHash, bytes32 contractNoHash, bytes32 invoiceNoHash, bytes32 invoiceKey, uint64 invoiceDate, uint16 paymentTermDays, uint64 faceValueCents, uint64 dueDate, address exporterWallet)" # Newton decodes the request's arguments into a list, in signature order.arguments := object.get(input, "decoded_function_arguments", []) # The same arguments, by name.request := { "request_id": arguments[0], "schema_version": arguments[1], "schema_hash": arguments[2], "exporter_name_hash": arguments[3], "tax_id_ciphertext": arguments[4], "importer_name_hash": arguments[5], "contract_no_hash": arguments[6], "invoice_no_hash": arguments[7], "invoice_key": arguments[8], "invoice_date": to_number(arguments[9]), "payment_term_days": to_number(arguments[10]), "face_value_cents": to_number(arguments[11]), "due_date": to_number(arguments[12]), "exporter_wallet": arguments[13],} # CFN sends names and numbers as 32-byte keyed hashes, and sends 32 zero bytes# when a value is missing.missing_hash := "0x0000000000000000000000000000000000000000000000000000000000000000" is_present(hash) if { is_string(hash) count(hash) == 66 lower(hash) != missing_hash} # CFN sends dates as unix seconds at 00:00 UTC, and 0 when a date is missing.# Rego compares times in nanoseconds.now := time.now_ns() one_second := 1000000000 as_time(unix_seconds) := unix_seconds * one_second if unix_seconds > 0 # ---- The evaluation date (Mint v1 evaluation_date, used by K4 and K6) -------- # CFN sends the evaluation date, today's date in Vietnam, in the oracle input,# and the oracle passes it back bound to this request. K4 and K6 compare the# Invoice Date and Due Date with it. As GOE asked (19 Nov), Newton doesn't# check it against its own clock: like the rest of the request, its accuracy# is CFN's responsibility (clause 15.2). If it is missing, K4 and K6 both fail.evaluation := data.wasm.evaluation evaluation_date := as_time(evaluation.date) if { evaluation.ok == true evaluation.request_id == request.request_id} # ---- K9 · SCHEMA_MISMATCH: the request follows Mint v1 ---------------------- follows_mint_v1 if { input.decoded_function_signature == mint_v1_signature count(arguments) == 14 request.schema_version == data.params.schema_version lower(request.schema_hash) == lower(data.params.schema_hash)} reasons contains "SCHEMA_MISMATCH" if not follows_mint_v1 # ---- K1 · EXPORTER_ID_INVALID: Exporter Name and a well-formed Tax ID -------- # The data oracle opened the encrypted Tax ID inside the Newton operator. It# reports only yes/no answers about it, never the Tax ID itself.tax_id_check := data.wasm.tax_id tax_id_is_valid if { tax_id_check.ok == true # The answers are about this request's Tax ID, checked against this # policy's format... tax_id_check.request_id == request.request_id tax_id_check.ciphertext == lower(request.tax_id_ciphertext) tax_id_check.pattern == data.params.tax_id_pattern # ...and the Tax ID opened, is not empty, and matches the format. tax_id_check.opened == true tax_id_check.present == true tax_id_check.format_ok == true} reasons contains "EXPORTER_ID_INVALID" if not is_present(request.exporter_name_hash) reasons contains "EXPORTER_ID_INVALID" if not tax_id_is_valid # ---- K2 · IMPORTER_MISSING, K3 · CONTRACT_MISSING ---------------------------- reasons contains "IMPORTER_MISSING" if not is_present(request.importer_name_hash) reasons contains "CONTRACT_MISSING" if not is_present(request.contract_no_hash) # ---- K4 · INVOICE_INVALID: Invoice No. present, Invoice Date not after the# evaluation date invoice_is_valid if { is_present(request.invoice_no_hash) as_time(request.invoice_date) <= evaluation_date} reasons contains "INVOICE_INVALID" if not invoice_is_valid # ---- K5 · DUPLICATE_INVOICE: this invoice was never allowed before ----------- # The data oracle looked up this request's invoice_key in Newton's on-chain# invoice record (DtrMintGate) at a block CFN named.invoice_lookup := data.wasm.invoice never_allowed_before if { invoice_lookup.ok == true # It looked up this request's invoice_key... is_present(request.invoice_key) invoice_lookup.key == lower(request.invoice_key) # ...in this policy's invoice record, through an approved RPC... invoice_lookup.registry == lower(data.params.invoice_registry) invoice_lookup.rpc in data.params.rpc_urls # ...at a recent block... now - (invoice_lookup.block_time * one_second) <= data.params.max_block_age_seconds * one_second # ...and found no entry. Status 0 means the invoice was never allowed. invoice_lookup.status == 0} # If the lookup failed, Newton can't confirm the invoice is new, so it rejects.reasons contains "DUPLICATE_INVOICE" if { is_present(request.invoice_key) not never_allowed_before} # CFN can't form an invoice_key without a Tax ID, and K1 already rejects that.# A missing key alongside a valid Tax ID can't be checked, so it is rejected.reasons contains "DUPLICATE_INVOICE" if { not is_present(request.invoice_key) tax_id_is_valid} # ---- K6 · PAST_DUE: Due Date after the Invoice Date and after the evaluation# date due_date_is_valid if { as_time(request.due_date) > as_time(request.invoice_date) as_time(request.due_date) > evaluation_date} reasons contains "PAST_DUE" if not due_date_is_valid # ---- K7 · FACE_VALUE_INVALID: above 0, within the per-invoice maximum -------- face_value_is_valid if { request.face_value_cents > 0 request.face_value_cents <= data.params.max_face_value_cents} reasons contains "FACE_VALUE_INVALID" if not face_value_is_valid| Client | Policy set | Revision | Slot |
|---|---|---|---|
| 0x5153…02da | 0xd001edb7…febe | 1 | 0 |
| Chain | Policy address |
|---|---|
| Sepolia | 0x91a3093b423f55ce9ef2d26b7ae02fb05b44f16d |
| Key | Type | Required |
|---|---|---|
| rpc_urlsK5: JSON-RPC endpoints the oracle may read the invoice record through | array | yes |
| schema_hashK9: the frozen Mint v1 schema hash, 0x hex | string | yes |
| schema_versionK9: the schema version requests must declare ("Mint v1") | string | yes |
| tax_id_patternK1: Vietnamese Tax ID format (10 or 13 digits), a regular expression the oracle applies to the decrypted Tax ID | string | yes |
| invoice_registryK5: the DtrMintGate whose on-chain invoice record the oracle reads | string | yes |
| max_face_value_centsK7: the per-invoice maximum Face Value, in US cents | integer | yes |
| max_block_age_secondsK5: how old the block the record is read at may be | integer | yes |
| Key | Type | Required |
|---|---|---|
| tax_id_keyCFN's 32-byte XChaCha20-Poly1305 data key, 0x hex | string | yes |
| Task | Sender | Policy | Function | Result | Age |
|---|---|---|---|---|---|
| 0xd2b4e52c… | 0x80da…c427 | goe-dtr-mint | function mintDtr | AUTHORIZED | 1h 14m |