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.