Skip to content

Commit 7a4f5dd

Browse files
committed
refactor(accounting): inline bridge/lock/history modules into Accounting
Sapphire's 64 KiB runtime limit removes the need for the size-driven delegatecall split, so all bridge, lock, and history logic now lives in a single resident Accounting contract. Removes the fallback selector dispatcher, the mirrored storage prefix, module pointers, and cross-contract delegatecall; BridgeLib remains a separately-deployed linked library. History append helpers become internal so history cannot be forged by an external caller. Solidity tests call selectors directly and add selector-completeness and history-append-absence guards. Off-chain ABI collapses to Accounting + BridgeLib and drops module resolution and the bridgeModule startup check. Accounting NatSpec normalized to block style with full @param/@return coverage.
1 parent 387efd2 commit 7a4f5dd

50 files changed

Lines changed: 2208 additions & 5093 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,6 @@ jobs:
8787
run: |
8888
test -f solidity/artifacts/contracts/Accounting.sol/Accounting.json || (echo "Solidity artifacts not found!" && exit 1)
8989
90-
- name: Storage layout invariants (delegatecall safety)
91-
# Pre-flight the Accounting<->module delegatecall invariants (storage
92-
# layout, fallback dispatcher, signer/secret isolation) with --bail, so a
93-
# slot mismatch fails fast instead of being masked by the full suite below.
94-
run: cd solidity && bun run test:hardhat -- --bail --grep "storage|fallback dispatcher|setBridgeModule|signer isolation"
95-
env:
96-
BASE_SEPOLIA_RPC_URL: ${{ secrets.BASE_SEPOLIA_RPC_URL }}
97-
9890
- name: Run Solidity tests
9991
run: make solidity-test
10092

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ solidity-test:
5151
cd solidity && bun run test
5252

5353
# Mirrors the solidity job in .github/workflows/ci.yml: clean compile,
54-
# size gate, upgrade-safety, targeted storage-layout pre-flight, full suite.
54+
# size gate, upgrade-safety, full suite.
5555
# Run before pushing if you want CI-equivalent verification locally.
5656
solidity-ci: solidity-clean solidity-build
5757
cd solidity && bun run check:size
5858
cd solidity && npx hardhat run scripts/validate-upgrade.ts
59-
cd solidity && bun run test -- --bail --grep "storage|fallback dispatcher|setBridgeModule|signer isolation"
6059
cd solidity && bun run test
6160

6261
solidity-clean:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ A reusable library for apps running in ROFL that enables:
1010

1111
| Path | What's there |
1212
|------|--------------|
13-
| [`solidity/`](solidity/README.md) | On-chain contracts (Accounting, AccountingHistoryModule, EVMSignerAndVerifier, AccountingSiweAuth), deployment & Hardhat tasks. |
13+
| [`solidity/`](solidity/README.md) | On-chain contracts (Accounting, BridgeLib, EVMSignerAndVerifier, AccountingSiweAuth), deployment & Hardhat tasks. |
1414
| [`src/`](src/README.md) | Python service that runs in the ROFL TEE — deposit verification, sweep state machine, withdrawal resolution. |
1515
| [`docs/api-reference.md`](docs/api-reference.md) | HTTP API reference: request/response shapes, auth, error codes. |
1616

solidity/README.md

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ A cross-chain accounting system on Oasis Sapphire. Confidential balance manageme
66

77
The Accounting module consists of these main components:
88

9-
- **Accounting.sol** — Core accounting contract (UUPS upgradeable). Manages balances, deposits, locks, transfers, withdrawals, and emergency withdraws.
10-
- **AccountingHistoryModule.sol**non-upgradeable delegated history module. Accounting owns the history storage; the module supplies history read/write code via `delegatecall`.
9+
- **Accounting.sol** — Core accounting contract (UUPS upgradeable). Manages balances, deposits, locks, transfers, withdrawals, emergency withdraws, per-user history, and the ROSE bridge.
10+
- **BridgeLib.sol**delegatecall-linked library holding the bridge-withdrawal validation and signing helpers used by `Accounting`.
1111
- **EVMSignerAndVerifier.sol** — Sapphire-confidential EVM keypair management; signs sweep, gas-funding, and withdrawal transactions for source chains using the `EIP155Signer` precompile.
1212
- **EIP712SignatureVerifier.sol** — Verifies user-authored EIP-712 signatures for transfer / lock / withdrawal operations.
1313
- **auth/AccountingSiweAuth.sol** — SIWE-based authentication for confidential Sapphire view calls.
@@ -127,8 +127,8 @@ bun run coverage
127127

128128
## Deployment
129129

130-
The `deploy` task provisions the SIWE auth helper, Accounting proxy/implementation,
131-
AccountingHistoryModule, and links Accounting to the module in the same deploy task.
130+
The `deploy` task provisions the SIWE auth helper, the `BridgeLib` library, and the
131+
Accounting proxy/implementation (with `BridgeLib` linked) in a single deploy task.
132132

133133
### Deploy to Sapphire Localnet
134134

@@ -142,8 +142,8 @@ npx hardhat deploy --network sapphire-localnet --roflappid <rofl1…>
142142
npx hardhat deploy --network sapphire-testnet --roflappid <rofl1…>
143143
```
144144

145-
Outputs: SIWE-auth address, Accounting proxy/implementation address,
146-
AccountingHistoryModule address, EVM signing address, owner.
145+
Outputs: SIWE-auth address, BridgeLib address, Accounting proxy/implementation
146+
address, EVM signing address, owner.
147147

148148
### Standalone subtasks
149149

@@ -183,22 +183,10 @@ If the task cannot resolve `siweAuth()` from the existing proxy, pass it explici
183183
npx hardhat upgrade --network sapphire-testnet --proxy <proxy-address> --siweauth <siwe-auth-address>
184184
```
185185

186-
If an AccountingHistoryModule was deployed separately, attach it during upgrade:
187-
```shell
188-
npx hardhat upgrade --network sapphire-testnet --proxy <proxy-address> --history <history-module-address>
189-
```
190-
191-
The upgrade task validates the module marker and contract code. When upgrading from a
192-
pre-AccountingHistoryModule deployment, the task deploys or validates the module before upgrading
193-
Accounting, then links it with `upgradeToAndCall` so the upgraded proxy is never left without
194-
history code.
195-
196-
Existing history entries stored inside the old Accounting proxy remain in Accounting storage and
197-
are read by the delegated module after upgrade.
198-
199-
`getHistory` is exposed on Accounting and delegates to `AccountingHistoryModule` at the proxy
200-
address. `Accounting.historyModule()` returns the module code address, not a storage-owning
201-
history contract.
186+
The `upgrade` task links `BridgeLib` into the new implementation automatically. `getHistory`
187+
is a resident `Accounting` view — history is stored and read directly in the Accounting proxy's
188+
own storage (the append paths are internal-only, so there is no external surface to forge
189+
entries).
202190

203191
#### 3. Update the README
204192

@@ -282,7 +270,7 @@ User-driven escape hatch from a per-user deposit address, with no ROFL involveme
282270

283271
| Task | Purpose |
284272
|------|---------|
285-
| `deploy` | Deploy Accounting + AccountingHistoryModule + SIWE auth |
273+
| `deploy` | Deploy BridgeLib + Accounting (BridgeLib linked) + SIWE auth |
286274
| `deploy-siwe-auth` | Deploy `AccountingSiweAuth` standalone |
287275
| `force-import` | Import an existing proxy into hardhat-upgrades |
288276
| `upgrade` | UUPS upgrade Accounting implementation |
@@ -308,7 +296,7 @@ Run `npx hardhat <task> --help` for parameter details.
308296
| AccountingSiweAuth | `0xFc97d47F0bc8f4E50333D34c281705E0666D3fD7` |
309297
| Accounting (Proxy) | `0xad3C76e4E621C0cfF7540479Ee9B0A945723A642` |
310298
| Accounting (Implementation) | `0x12fb6720c445aa2d38009eb64e191e26C30b4CAA` (refresh after each upgrade) |
311-
| AccountingHistoryModule | TBD after deployment |
299+
| BridgeLib | TBD after deployment |
312300

313301
**ROFL App ID:** `rofl1qrmnjkx47f4tcfvfclnrtj2rad82akeum5jcpe8y`
314302

@@ -326,15 +314,15 @@ Run `npx hardhat <task> --help` for parameter details.
326314
| AccountingSiweAuth | TBD |
327315
| Accounting (Proxy) | TBD |
328316
| Accounting (Implementation) | TBD |
329-
| AccountingHistoryModule | TBD |
317+
| BridgeLib | TBD |
330318

331319
## Security Considerations
332320

333321
- **Trust anchor for deposits:** ROFL TEE attestation. `creditDeposit` is gated by `roflEnsureAuthorizedOrigin(roflAppID)` — no on-chain transaction proof is verified
334322
- **Confidential signing:** Sapphire's `EIP155Signer` + `SIGN_DIGEST` precompile keeps the contract-held EVM private key inside the secure environment; signed transactions are returned only to authorized callers
335323
- **EIP-712:** All user-authored balance operations require typed-data signatures, validated by `EIP712SignatureVerifier`
336324
- **Signed view-call auth:** `onlyROFLQuery` matches `msg.sender` against the ROFL-published `roflSignerAddress`. `roflEnsureAuthorizedOrigin` is unavailable inside `eth_call`, so signed-query reads use this alternative gate
337-
- **History module:** Accounting stores history in its own proxy storage and delegates history code to `AccountingHistoryModule`. Only the owner can update the module pointer; deployment tasks validate the module marker before linking.
325+
- **History:** Accounting stores and reads per-user history in its own storage via resident, internal-only append paths — there is no external history-append selector, so entries cannot be forged.
338326
- **1-block delays** on `resolveWithdrawal` and `executeEmergencyWithdraw` mitigate same-block read-then-act simulation attacks
339327

340328
## Development
@@ -344,7 +332,7 @@ Run `npx hardhat <task> --help` for parameter details.
344332
```
345333
contracts/
346334
├── Accounting.sol # Main accounting contract (UUPS proxy)
347-
├── AccountingHistoryModule.sol # Delegated history read/write code
335+
├── BridgeLib.sol # Bridge validation/signing library (delegatecall-linked)
348336
├── EVMSignerAndVerifier.sol # EVM keypairs + tx signing
349337
├── EIP712SignatureVerifier.sol # User auth via EIP-712
350338
├── Types.sol # Shared structs and enums

0 commit comments

Comments
 (0)