# L{CORE} IoT SDK Demo

## Overview
This demo serves as [**Mod Society Labs'**](https://www.modernsociety.xyz) Milestone 3 submission for the [**Arbitrum DAO DDA3 program**](https://questbook.app/dashboard/?grantId=67d805737397096a7269962e&chainId=10&role=community&proposalId=67f55aba16e7410ad71111c2&isRenderingProposalBody=true). We're the applied think tank behind [**Locale Network**](https://www.locale.cash) and we're showcasing an integral part of the **City Chain** initiative: our [**L{CORE} IoT SDK**](https://www.locale.cash/lcore).
### Key Use Cases
Our City Chain initiative champions localized data networks geared specifically towards local economic development and commerce and with the L{CORE} SDK we can provide trustless, privacy-first off-chain data directly to smart contracts on Arbritrum Orbit chains for:
- Real World Asset (RWA) lending
- Decentralized health/car insurance
- Small business loans backed by SBA
The system accomplishes this **without oracles** while maintaining determinism, decentralization, privacy & security.
## System Architecture

> *Built on [**Arbitrum**](https://arbitrum.io/) • Powered by [**Cartesi**](https://cartesi.io/) • Deployed with [**Alchemy**](https://www.alchemy.com/)*
### Architecture Components
This diagram shows our complete data pipeline from: IoT Device → Encryption Layer → Smart Contract Layer
- **Encryption Layer**: Powered by Cartesi network's off-chain Linux VMs acting as co-processors
- **Data Management**: Encrypted data stored in SQLite database
- **Smart Contract Layer**: Handles execution logic and transaction settlement
- **Blockchain**: Custom L2 Arbitrum Orbit chain provided by Alchemy
**Key Feature**: Raw sensor data never leaves the device unencrypted. All processing happens through our privacy-preserving infrastructure before reaching smart contracts.
## Demo
### Hardware Setup

Starting at the device level, we're using two Raspberry Pi 5 devices with Sense HAT add-ons. This enables real-time environmental monitoring and demonstrates our multi-device capability
### Device-Level Data Collection

The Pi devices stream their environmental data to this terminal, where we can monitor the deployment process as it sends data to our privacy node onchain. The data includes information like temperature, humidity, and elevation.
### Dual Encryption Process

Before any data submission, we implement **dual encryption** through:
1. **JWE (JSON Web Encryption)** - Data encryption
2. **JWS (JSON Web Signature)** - Digital signing
The encryption layer stores device-specific keys during registration. This demonstration device is already registered in our SQLite database.
### Onchain Verification

Let's verify this on our custom Orbit chain with Alchemy:
- **Transaction**: `[TRANSACTION_HASH_BA99]`
- **Block**: `154323`
- **Explorer**: [**View on Block Explorer**](LINK_TO_BLOCK_EXPLORER)


When we decode the raw input, you can see:
```json
{
"deviceId": "masked_device_id_different_from_actual",
"counter": "submission_count",
"timestamp": "block_timestamp",
"jwe_payload": "encrypted_sensor_data",
"jws_signature": "verification_signature"
}
```
> **Privacy Note**: Device ID is completely masked. Only the device owner can identify their device on-chain through our backend processes.
### Privacy Layer Processing

The Cartesi privacy node processes encrypted IoT data through a structured pipeline:
**ZK Proof Generation → Dual Decryption → SQLite Storage → Stylus Contract**.
- **ZK Proof Generation**: Verifies computation integrity without exposing raw data.
- **Dual Decryption**: Utilizes the device's unique JWE/JWS keys (stored during registration) to unlock the data.
- **SQLite Storage**: Persists decrypted output locally, maintaining proofs and a queryable state.
- **Stylus Contract**: Forwards the result to the on-chain [Device Registry](LINK_TO_STYLUS_CONTRACT) for access control.
This cycle runs continuously, with new data submissions every **30 seconds** and a 10-block processing delay for enhanced security.
#### Database Architecture

**PostgreSQL** serves as the main data store, receiving real-time emissions via GraphQL:
| Table | Purpose | Key Data |
|-------|---------|----------|
| `inputs` | Device payloads | Masked device_id, encrypted data (JWE/JWS), data queries |
| `reports` | Pipeline errors | Submission failure details |
| `vouchers` | Settlement records | Transaction hashes, base layer interactions |
| `notices` | Decryption failures | Internal city-chain node logs |
**ZK Proof Verification** happens off-chain through decentralized verifier nodes deployable on any cloud platform, ensuring anyone can validate the encryption/decryption computations.
```mermaid
erDiagram
inputs {
id PRIMARY_KEY
device_id VARCHAR
counter INTEGER
timestamp DATETIME
jwe_payload TEXT
jws_signature TEXT
block_number INTEGER
}
reports {
id PRIMARY_KEY
input_id FOREIGN_KEY
error_type VARCHAR
error_message TEXT
created_at DATETIME
}
vouchers {
id PRIMARY_KEY
input_id FOREIGN_KEY
transaction_hash VARCHAR
settlement_status VARCHAR
created_at DATETIME
}
notices {
id PRIMARY_KEY
input_id FOREIGN_KEY
payload TEXT
error_details TEXT
created_at DATETIME
}
inputs ||--o{ reports : "has errors"
inputs ||--o{ vouchers : "generates"
inputs ||--o{ notices : "may fail"
```
## System Summary
![SCREEN_RECORDING_12: Complete pipeline demonstration]
**Complete data flow**:
1. Sensor data collected on-device
2. Data encrypted and sent to input box contract
3. Information flows to encryption layer node
4. Data posted onchain to device registry
5. Registry manages data access per wallet
6. System populates SQLite and PostgreSQL databases
7. Databases govern frontend presentation
## Conclusion
This concludes our Milestone 3 submission for the Arbitrum DAO DDA3 program. All documentation and code will be available in our [**GitHub repository**](https://github.com/Modern-Society-Labs/kc-chain-m3) attached to the submission.
---
### Connect With Us
- [**Website**](https://www.modernsociety.xyz)
- [**Twitter**](https://www.locale.cash/lcore)
- [**Contact**](mailto:hello@modernsociety.xyz)
---