Skip to content
Open
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
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,13 @@ tmp/
temp/
*.js
!migrations/*.js

# Working specs (do not commit — internal scratch docs)
ANONBETA1_SPEC.md

# Keypairs — ALL Solana keypairs must be gitignored (defense in depth)
*testpair*.json
*-keypair.json
*_keypair.json
id.json
solana-*.json
9 changes: 3 additions & 6 deletions Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@ resolution = true
skip-lint = false

[programs.devnet]
ble_revshare = "7xeQNUggKc2e5q6AQxsFBLBkXGg2p54kSx11zVainMks"
anonbeta1 = "anon7uu8UtVoFgS8GCSfw2RqyphJhkN3xEjgPwznYDe"

[programs.localnet]
ble_revshare = "7xeQNUggKc2e5q6AQxsFBLBkXGg2p54kSx11zVainMks"
anonbeta1 = "anon7uu8UtVoFgS8GCSfw2RqyphJhkN3xEjgPwznYDe"

[registry]
url = "https://api.apr.dev"

[provider]
cluster = "devnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "ARCIUM_CLUSTER_OFFSET=456 node --import tsx --test 'tests/**/*.ts'"
wallet = "./anontestpair_01.json"

[test]
startup_wait = 60000
Expand Down
24 changes: 12 additions & 12 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["programs/*", "encrypted-ixs"]
members = ["programs/anonbeta1", "encrypted-ixs"]
resolver = "2"

[profile.release]
Expand Down
70 changes: 45 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
# BLE Revenue Sharing
# Anonmesh Contract

A Solana smart contract for handling revenue sharing payments with encrypted computation support via Arcium.
Solana programs and Arcium circuits for anonmesh beacon registration, co-signed
settlement, and private relay accounting.

## Overview

This program implements a payment distribution system where payments can be split between recipients and broadcasters. It uses Arcium's confidential computing infrastructure for encrypted payment processing.
`anonbeta1` binds an operator wallet to an encrypted RNS transport identity,
then lets mobile clients send partially signed transfer transactions over
anonmesh/RNS. The announced beacon co-signs the transaction, submits it to
Solana, and receives its revenue share inside the same on-chain settlement.
Arcium is used for private operator-to-RNS binding and private relay stats.

## Architecture

### Programs

- `ble-revshare`: Main program handling payment execution and revenue distribution
- `anonbeta1`: RNS beacon registry, co-signed token settlement, and
Arcium-private operator-to-RNS binding / relay stats

### Key Features

- Token whitelist management
- Payment execution with broadcaster revenue sharing (70/30 split)
- Arcium encrypted computation integration
- Payment statistics tracking via confidential computations
- Private operator-to-RNS binding through the `beacon_bind` Arcium circuit
- Co-signed SPL-token settlement: sender signs first, beacon co-signs and earns
the configured share
- Encrypted relay count through the `relay_increment` Arcium circuit
- Public state limited to beacon metadata, binding verification state,
settlement receipts, and relay liveness timestamps

## Mobile Flow

1. The beacon announces itself over anonmesh/RNS.
2. The mobile app creates a transfer with the beacon operator as a required
co-signer, fills `{ settlement_id, recipient ATA, amount, beacon_share_bps }`,
and partially signs as the sender.
3. The partial transaction is sent over anonmesh/RNS to the beacon.
4. The beacon co-signs and submits `execute_cosigned_transfer`.
5. `anonbeta1` verifies the beacon is registered and Arcium-bound, transfers
funds to the recipient and beacon ATA, and writes a settlement receipt.
6. The beacon can call `record_relay` with the settlement hash to update its
encrypted Arcium relay counter.

## Prerequisites

Expand Down Expand Up @@ -58,41 +79,36 @@ arcium deploy \
--rpc-url "https://devnet.helius-rpc.com/?api-key=YOUR_API_KEY"
```

### 3. Initialize computation definition
### 3. Initialize computation definitions

```bash
npx ts-node init-comp-def-final.ts
# Initialize beacon_bind and relay_increment definitions after deploy.
# Use generated anonbeta1 client code; standalone init scripts are not included.
```

### 4. Whitelist tokens

```bash
npx ts-node scripts/whitelist-tokens.ts
```

## Testing
## Verification

```bash
export ANCHOR_PROVIDER_URL="https://devnet.helius-rpc.com/?api-key=YOUR_API_KEY"
export ANCHOR_WALLET="~/.config/solana/id.json"
export ARCIUM_CLUSTER_OFFSET=456

yarn test
arcium build
```

`arcium build` is the canonical verification command for this repo. It compiles
the encrypted instructions and the Arcium-enabled Anchor program together.
Anchor-only builds are not sufficient for audit or release.

## Project Structure

```
.
├── programs/
│ └── ble-revshare/
│ └── anonbeta1/
│ └── src/
│ └── lib.rs # Main program logic
├── tests/
│ └── ble-revshare.ts # Test suite
├── encrypted-ixs/ # Encrypted instruction artifacts
├── migrations/ # Deployment migrations
└── Arcium.toml # Arcium configuration
└── encrypted-ixs/ # Encrypted instruction artifacts
```

## Environment Variables
Expand All @@ -103,9 +119,13 @@ yarn test
| `ANCHOR_WALLET` | Path to wallet keypair | Yes |
| `ARCIUM_CLUSTER_OFFSET` | Arcium cluster offset | Yes |

The repository expects a local deploy keypair at the path you set in
`ANCHOR_WALLET` or pass with `--keypair-path`. Keypair files are intentionally
gitignored; fresh clones must provide their own.

## Program IDs

- Program ID: `7fvHNYVuZP6EYt68GLUa4kU8f8dCBSaGafL9aDhhtMZN`
- anonbeta1 Program ID: `anon7uu8UtVoFgS8GCSfw2RqyphJhkN3xEjgPwznYDe`
- Arcium Program ID: `Arcj82pX7HxYKLR92qvgZUAd7vGS1k4hQvAFcPATFdEQ`

## License
Expand Down
45 changes: 38 additions & 7 deletions encrypted-ixs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,46 @@ use arcis::*;
mod circuits {
use arcis::*;

pub struct PaymentInput {
amount: u64,
pub struct BindingInput {
rns_dest_hash: u128,
region_code: u32,
}

#[instruction]
pub fn payment_v3(
payment_input: Enc<Shared, PaymentInput>,
) -> Enc<Shared, u64> {
let payment = payment_input.to_arcis();
payment_input.owner.from_arcis(payment.amount)
pub fn beacon_bind(input: Enc<Shared, BindingInput>) -> Enc<Shared, u128> {
let binding = input.to_arcis();
let rns_bytes = binding.rns_dest_hash.to_le_bytes();
let region_bytes = binding.region_code.to_le_bytes();

let mut msg = [0u8; 20];
for i in 0..16 {
msg[i] = rns_bytes[i];
}
for i in 0..4 {
msg[16 + i] = region_bytes[i];
}

let hash = SHA3_256::new().digest(&msg);
let mut commitment: u128 = 0;
let mut shift: u128 = 1;
for i in 0..16 {
commitment = commitment + (hash[i] as u128) * shift;
shift = shift * 256;
}

input.owner.from_arcis(commitment)
}

pub struct RelayCount {
count: u64,
}

#[instruction]
pub fn relay_increment(current: Enc<Shared, RelayCount>) -> Enc<Shared, RelayCount> {
let current_count = current.to_arcis();
let next = RelayCount {
count: current_count.count + 1,
};
current.owner.from_arcis(next)
}
}
68 changes: 0 additions & 68 deletions finalize-comp-def.ts

This file was deleted.

Loading