Skip to main content

A simple language for Bitcoin non-custodial smart contracts

Project description

Sophi

A simple language for Bitcoin non-custodial smart contracts.

Sophi is not a smart contract language like Solidity. It has no runtime, no blockchain execution, and no custody of funds. You describe what a fair exchange looks like — and Sophi proves it is mathematically valid.

Install

pip install sophi

Write a swap

swap {
  before:
    alice = 0.5 BTC
    bob = 50000 USDT

  after:
    alice = 50000 USDT
    bob = 0.5 BTC
}

Save as trade.sph and run:

sophi compile trade.sph

That's it. Sophi checks that no value was created or destroyed — per asset, per participant. If the math holds, it produces a validity proof. If not, you get a clear error before anything touches a network.

Works for any number of participants

swap {
  before:
    alice = 0.5 BTC
    bob = 50000 USDT
    carol = 1 ETH

  after:
    alice = 50000 USDT
    bob = 1 ETH
    carol = 0.5 BTC
}

2 people, 3, 8, or any number. Sophi handles it automatically.

How it works

Every Sophi program is verified against two mathematical rules:

1. Conservation per asset — the total of each asset before must equal the total after.

BTC before  == BTC after
USDT before == USDT after

This means 1 BTC → 1 USDT is always rejected. BTC is not USDT. Each asset is verified separately.

2. Delta per participant — Sophi calculates exactly what each person gave and received.

alice: -0.5 BTC, +50000 USDT
bob:   +0.5 BTC, -50000 USDT

No value created. No value destroyed. The math either holds or it doesn't.

Proof output

{
  "status": "valid",
  "conservation": {
    "BTC":  { "before": "0.5",   "after": "0.5"   },
    "USDT": { "before": "50000", "after": "50000"  }
  },
  "delta": {
    "alice": { "BTC": "-0.5",  "USDT": "+50000" },
    "bob":   { "BTC": "+0.5",  "USDT": "-50000" }
  },
  "before": { "alice": "0.5 BTC",    "bob": "50000 USDT" },
  "after":  { "alice": "50000 USDT", "bob": "0.5 BTC"    }
}

This proof is portable. Bitcoin, Lightning, your own backend — any system can consume it to coordinate settlement without trusting a third party.

The four primitives

These exist under the hood. You never write them — Sophi infers them from your swap.

Resource — anything with value. BTC, USDT, ETH, or any asset you name.

State — who holds what. before and after are states.

Rule — conservation per asset. Verified automatically for every asset in the swap.

Proof — the output. A portable JSON with conservation, delta, and status.

Non-custodial by construction

Your funds never leave your control. Sophi has no concept of custody. It is mathematically impossible to write a custodial program in Sophi.

Independent from any platform

Sophi is a standalone language. It does not depend on any specific platform, exchange, or settlement system. The proof it produces can be used by anyone.

License

Business Source License 1.1 — converts to Apache 2.0 after 4 years.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sophi-0.2.2.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sophi-0.2.2-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file sophi-0.2.2.tar.gz.

File metadata

  • Download URL: sophi-0.2.2.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for sophi-0.2.2.tar.gz
Algorithm Hash digest
SHA256 e64b0bc9df05c765ceb1bff2eb618f18dcb91d9f70d0c64868ff2355f0c64619
MD5 dde225125419d976ef2dd2bf826cf6e3
BLAKE2b-256 e98eceb0292ad03d15390b06d6f343484a4f40a66f243f57efa7f755bf2cb485

See more details on using hashes here.

File details

Details for the file sophi-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: sophi-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for sophi-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 40396ec1b6409bc7303ebdebe2bf6bd7c341249581ecaae5765ce02191f4c604
MD5 2183fc24460b76fbd56f422592339ae5
BLAKE2b-256 56e655a3965e689ac7698e91f62b02eb2ed5a8c5a8a27aed5205de3d470f9eed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page