Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 36 additions & 35 deletions solidity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ The Accounting module consists of these main components:
▼ │ │ onlyROFL │ │
┌─────────────────┐ │ ▼ │ │
│ ROFL TEE │◀──▶│ ┌──────────────────────┐ │ │
│ (Python svc) │ │ │ creditDeposit │ │ │
│ (Python svc) │ │ │ creditDeposit │ │ │
├─────────────────┤ │ │ resolveWithdrawal │ │ │
│ • Verify deps. │ │ │ setRoflSignerAddress │ │ │
│ • Sweep engine │ │ └──────────────────────┘ │ │
│ • Withdraw poll│ └────────────────────────────┘ │
│ • Verify deps. │ │ │ setRoflSignerAddress │ │ │
│ • Sweep engine │ │ └──────────────────────┘ │ │
│ • Withdraw poll │ └────────────────────────────┘ │
└────────┬────────┘ │
│ │
└───────── RPC reads / broadcasts ──────────────────────┘
Expand Down Expand Up @@ -124,32 +124,38 @@ Generate test coverage reports:
bun run coverage
```

## Deployment
## Deployment and Upgrades

The `deploy` task provisions both the SIWE auth helper and the Accounting proxy/implementation in one step.

### Deploy to Sapphire Localnet
If the contract will be owned by an EOA, define `SECRET_KEY` env variable.

```shell
npx hardhat deploy --network sapphire-localnet --roflappid <rofl1…>
export SECRET_KEY=0x...
```

### Deploy to Sapphire Testnet
If the contract will be owned by a multisig Safe contract, use `--output-safe`
parameter to generate the Safe Transaction Builder JSON file, sign and submit.
In this case `SECRET_KEY` is only mandatory for contract upgrades to deploy
proposed upgrade implementation.

### Deploy

The `deploy` task provisions both the SIWE auth helper and the Accounting proxy/implementation in one step.

```shell
# Sapphire Localnet
npx hardhat deploy --network sapphire-localnet --roflappid <rofl1…>

# Sapphire Testnet
npx hardhat deploy --network sapphire-testnet --roflappid <rofl1…>
```

Outputs: SIWE-auth address, proxy address, implementation address, EVM signing address, owner.

### Standalone subtasks
#### Standalone subtasks

```shell
# Deploy AccountingSiweAuth alone (e.g., to roll the auth contract):
npx hardhat deploy-siwe-auth --network sapphire-testnet --roflappid <rofl1…>

# Force-import an existing proxy into hardhat-upgrades' deployment registry:
npx hardhat force-import --network sapphire-testnet --proxy <proxy-address>
```

### Upgrade
Expand All @@ -165,35 +171,30 @@ bun run build

#### 2. Run the upgrade task

For staging (Sapphire Testnet):
```shell
npx hardhat upgrade --network sapphire-testnet --proxy 0xad3C76e4E621C0cfF7540479Ee9B0A945723A642
```
##### With EOA

For production (Sapphire Mainnet):
```shell
npx hardhat upgrade --network sapphire --proxy <accounting-proxy-address>
# Sapphire Testnet
npx hardhat upgrade --network sapphire-testnet --address 0xad3C76e4E621C0cfF7540479Ee9B0A945723A642

# Sapphire Mainnet
npx hardhat upgrade --network sapphire --address <accounting-proxy-address>
```

If the task cannot resolve `siweAuth()` from the existing proxy, pass it explicitly:
##### With Safe multisig

```shell
npx hardhat upgrade --network sapphire-testnet --proxy <proxy-address> --siweauth <siwe-auth-address>
# Sapphire Testnet
npx hardhat upgrade --network sapphire-testnet --address 0xad3C76e4E621C0cfF7540479Ee9B0A945723A642 --output-safe accounting-upgrade-safe.json

# Sapphire Mainnet
npx hardhat upgrade --network sapphire --address <accounting-proxy-address> --output-safe accounting-upgrade-safe.json
```

#### 3. Update the README

After a successful upgrade, refresh the implementation address in the [Contract Addresses](#contract-addresses) section below.

#### Troubleshooting

If the proxy was deployed outside of hardhat-upgrades (or on a fresh machine), you may need to import it first:

```shell
npx hardhat force-import --network sapphire-testnet --proxy <accounting-proxy-address>
```

The upgrade task uses `redeployImplementation: 'always'` to ensure a fresh implementation is deployed. If you see the same implementation address after an upgrade, verify the contract was actually recompiled with your changes.

## Configuration

### Adding Token Support
Expand Down Expand Up @@ -245,7 +246,7 @@ User-driven escape hatch from a per-user deposit address, with no ROFL involveme
| Task | Purpose |
|------|---------|
| `deploy` | Deploy Accounting + SIWE auth |
| `deploy-siwe-auth` | Deploy `AccountingSiweAuth` standalone |
| `deploy-siwe-auth` | Deploy `SiweAuth.sol` standalone |
| `force-import` | Import an existing proxy into hardhat-upgrades |
| `upgrade` | UUPS upgrade Accounting implementation |
| `getBalance` | Read user balance |
Expand Down Expand Up @@ -290,7 +291,7 @@ Run `npx hardhat <task> --help` for parameter details.

- **Trust anchor for deposits:** ROFL TEE attestation. `creditDeposit` is gated by `roflEnsureAuthorizedOrigin(roflAppID)` — no on-chain transaction proof is verified
- **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
- **EIP-712:** All user-authored balance operations require typed-data signatures, validated by `EIP712SignatureVerifier`
- **EIP-712:** All user-authored balance operations require typed-data signatures, validated by `EIP712Verifier.sol`
- **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
- **1-block delays** on `resolveWithdrawal` and `executeEmergencyWithdraw` mitigate same-block read-then-act simulation attacks

Expand All @@ -312,7 +313,7 @@ contracts/

test/
├── Accounting.E2E.ts # End-to-end integration test
├── EVMSignerAndVerifier.ts # EVM signing tests
├── EVMSignerVerifier.ts # EVM signing tests
├── AuthTokenDecryption.ts # SIWE auth-token tests
├── RoflAppId.ts # ROFL app ID parsing tests
└── utils.ts # Test utilities
Expand Down
36 changes: 28 additions & 8 deletions solidity/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading