COBOL in Big 25
Source: Dev.to
💀 The Inspiration: The Floating Point Ghost
In the world of Web3 and modern SaaS, we have forgotten the old gods. We build financial systems on JavaScript and Python, languages that rely on IEEE 754 floating‑point arithmetic. In a standard modern environment, simple addition can yield terrifying results due to binary approximation errors:
0.1 + 0.2 = 0.30000000000000004
In a payroll run of $10,000,000, these “micro‑pennies” accumulate. In the traditional banking world, this leads to audit failures. In the crypto world, where transactions are immutable, it leads to irreversible financial loss.
We asked ourselves: “What if we brought the dead back to life to save the future?”
⚡ What It Is
DarkLedger (formerly Ledger‑De‑Main) is a “Frankenstein” architecture that stitches together the oldest, most reliable financial engine (COBOL) with the newest, fastest settlement layer (Base L2).
- The core payroll logic runs in a compiled COBOL binary—the same technology that powers 95 % of the world’s ATM swipes—ensuring 100 % decimal precision.
- A Python “nervous system” executes payouts on the blockchain.
🏗 How We Built It (The Architecture)
The Brain: COBOL (Legacy Core)
We generated a GnuCOBOL program using Vibe Coding. This component handles the Gross‑to‑Net logic using Fixed‑Point Arithmetic.
For a monetary value (V) stored as an integer (I) with a scale of (10^2):
[ V = \frac{I}{10^{2}} ]
This guarantees exact tax calculations, e.g.:
[ \text{Net Pay} = (\text{Hours} \times \text{Rate}) - \lfloor \text{Gross} \times 0.15 \rfloor - \lfloor \text{Gross} \times 0.05 \rfloor ]
The Stitch: Python & Agent Hooks
The biggest challenge was connecting a modern JSON‑based frontend to a legacy binary that expects fixed‑width text files. We used Kiro Agent Hooks to automate the stitching process.
Hook behavior:
On every save of payroll.cbl, Kiro parses the DATA DIVISION, extracts the byte positions (e.g., PIC X(10)), and auto‑generates a Python struct parser.
Interface specification
| Direction | Bytes | Fields |
|---|---|---|
| Input | 23 Bytes | Employee ID, Hours, Rate, Tax Code |
| Output | 60 Bytes | ID, Gross, Taxes, Net, Status |
The Hands: Settlement on Base
Once the math is verified by the “Brain,” the “Body” (Python) uses the Coinbase CDP SDK to convert the Net Pay into a USDC transaction on the Base L2 network.
🧟♂️ Challenges & Lessons Learned
Challenge 1: The Language Barrier
COBOL does not speak JSON; it speaks bytes.
Lesson: Modern ease‑of‑use can make us lazy with data types. We built a rigid byte‑level contract (defined in design.md) to ensure Python never sent malformed data to the mainframe.
Challenge 2: Containerizing a Monster
Running COBOL in the cloud isn’t standard.
Lesson: We created a custom Docker container that acts as a “time machine”: it installs a lightweight Linux OS, pulls the GnuCOBOL compiler dependencies, compiles the legacy code at build time, and then spins up a FastAPI server to listen for requests.
Challenge 3: “Audit‑Proofing”
“Close enough” isn’t good enough for payroll. By enforcing Banker’s Rounding in COBOL (COMPUTE ROUNDED), we achieved a precision level that standard JavaScript libraries struggle to replicate without heavy dependencies.
🚀 Usage
Run the Container
docker build -t ledger-de-main .
Execute Payroll
Navigate to the Retro‑Terminal UI and run a batch command:
RUN PAYROLL --BATCH 2025-10-31
The system will:
- Generate a fixed‑width
input.dat. - Spawn a subprocess to run
cobol/bin/payroll. - Read the
output.rpt. - Execute a gasless USDC transfer on Base.
📜 Kiro Implementation Details
- Specs:
requirements.mddefines the 23‑byte input constraint. - Steering: A “Sacred Timeline” rule in
.kiro/steering/tech.mdforbids refactoring COBOL logic into Python. - Hooks: Automated binary compilation and Python model updates.
Built with 💚 (and 🧟♂️) for Kiroween 2025.