Skip to main content

14. Transaction Log Format

Log entry definition (16 bytes)

FieldSizeTypeDescription
deltaTime2 Buint16Seconds elapsed since session.startTime; wraps at 65535 s (~18 h)
amount3 Buint24Transaction amount in smallest currency unit; unsigned
balanceAfter4 Buint32Balance after this transaction; used for consistency checks
flags/type1 Buint8Transaction type and operational flags (see below)
hash6 BbytesTruncated SHA-256 chain hash linking this entry to the previous one

Total per entry: 16 bytes. Capacity on NTAG215: 7 entries (112 bytes).

flags/type field (1 byte)

BitsNameValues / Meaning
3:0txType0x0 = debit, 0x1 = credit/top-up, 0x2 = check-in, 0x3 = check-out, 0xF = system/admin
4offlineFlag1 = transaction was processed offline without backend confirmation
5suspectFlag1 = terminal flagged this transaction as potentially suspicious
7:6reservedMust be zero on write; ignored on read

Ring buffer

  • Logs are stored in a fixed-size ring buffer of 7 slots.
  • When the buffer is full, the oldest entry is overwritten.
  • The current write position is tracked implicitly by the rootHash trailer field (which always equals the hash of the most recent entry).
  • On readback, the terminal reconstructs the chain from the anchor and validates each entry in order.

Chain initialization and integrity

  • The first entry in a session uses session.startTime bytes (4 bytes, little-endian, zero-padded to 6) as the initial prevHash.
  • Each subsequent entry: hash[n] = SHA256(deltaTime || amount || balanceAfter || flags || hash[n-1])[0..5]
  • rootHash in the trailer equals hash[lastEntry] — the chain head.
  • After a ring buffer wrap, the chain continues from the overwritten slot's predecessor; the full chain back to session start is no longer available, but each surviving entry is still individually verifiable from its predecessor.

Integrity guarantees

  • Any modification to a log entry invalidates its hash and all subsequent hashes.
  • The rootHash trailer field ties the chain head to the overall card authentication (HMAC).
  • A chain break is a hard tamper condition (see §5).