# Transaction lifetime

Let $T$ be a transaction on the DarkFi network. Each transaction consists of multiple ordered contract calls:

$T=[C_{1},…,C_{n}]$

Associate with each contract call an operator $fC=$
**contract_function**. Each contract consists of arbitrary data which
is interpreted by the contract. So for example sending money to a
person, the transaction $T=[C_{1}]$ has a single call with $fC_{1}=$
`Money::Transfer`

. To enforce a transaction fee, we can add another
call to `Money::Fee`

and now our transaction $T$ would have two calls:
$[C_{1},C_{2}]$.

To move money from a DAO's treasury, we can build a transaction $T=[C_{1},C_{2},C_{3}]$ where:

- $fC_{1}=$
`Money::Fee`

- $fC_{2}=$
`Money::Transfer`

- $fC_{3}=$
`DAO::Exec`

This illustrates the concept of chaining function calls together in a single transaction.

`Money::Transfer`

Denote the call data here simply by $C$. Since payments on DarkFi use
the Sapling UTXO model, there are $n$ inputs $I_{i}$ and $m$ outputs
$O_{j}$ in $C$. There are also $π_{n}$ input *burn* zero-knowledge
proofs, and $μ_{m}$ output *mint* zero-knowledge proofs.

Each input $I_{i}$ contains a nullifier $N_{i}$ which is deterministically generated from the previous output's (the output which is being spent) serial code $ρ_{i}$ and secret key $x_{i}$. The ZK burn proof $π_{i}$ states:

- Correct construction of the nullifier $N_{i}=hash(x_{i},ρ_{i})$, revealing this value publicly.
- Derive the public key $P_{i}=x_{i}G$.
- Construct the coin commitment $C_{i}=hash(x_{i},v_{i},τ_{i},ρ_{i},…,b_{i})$, where $v_{i}$ is the coin value, $τ_{i}$ is the token ID, and $b_{i}$ is a random blinding factor. Additional metadata may be stored in this coin commitment for additional functionality.
- Set membership proof that $C_{i}∈R$ where $R$ represents the set of all presently existing coins.
- Any additional checks such as value and token commitments.

Outputs $O_{j}$ contain the public coin commitment $C_{j}$, a proof of their construction $μ_{j}$, and corresponding value/token commitments. The unlinkability property comes from only the nullifier $N$ being revealed in inputs (while $C$ is hidden), while the coin $C$ appears in outputs (but without nullifiers). Since there is a deterministic derivation of nullifiers from $C$, you cannot double spend coins.

The ZK mint proof is simpler and consists of proving the correct construction of $C$ and the corresponding value/token commitments.

To hide amounts, both proofs export value commitments on the coin amounts. They use a commitment function with a homomorphic property:

$ϕ:F→E$ $ϕ(x+y)=ϕ(x)+ϕ(y)$

So to check value is preserved across inputs and outputs, it's merely sufficient to check: $u_{i}∈U∑ ϕ(u_{i})=v_{j}∈V∑ ϕ(v_{j})$

`DAO::Exec`

Earlier we mentioned that bullas/coins can contain arbitrary metadata (indicated by …). This allows us to construct the concept of protocol owned liquidity. Inside the coin we can store metadata that is checked for correctness by subsequent contract calls within the same transaction. Take for example $T=[C_{1},C_{2}]$ mentioned earlier. We have:

- $fC_{1}=$
`Money::Transfer`

- $fC_{2}=$
`DAO::Exec`

Now the contract $C_{2}$ will use the encrypted DAO value exported from $C_{1}$ in its ZK proof when attempting to debit money from the DAO treasury. This enables secure separation of contracts and also enables composability in the anonymous smart contract context.

The DAO proof states:

- There is a valid active proposal $P$, and $P=hash(Q,v,…,D)$, where $(Q,v)$ are the destination public key and amount, and $D$ is the DAO commitment.
- That $D=hash(q,r,…)$ where $q$ is the quorum threshold that must be met (minimum voting activity) and $r$ is the required approval ratio for votes to pass (e.g. 0.6).
- Correct construction of the output coins for $C_{1}$ which are sending money from the DAO treasury to $(Q,v)$ are specified by the proposal, and returning the change back to the DAO's treasury.
- Total sum of votes meet the required thresholds $q$ and $r$ as specified by the DAO.

By sending money to the DAO's treasury, you add metadata into the coin which when spent requires additional contract calls to be present in the transaction $T$. These additional calls then enforce additional restrictions on the structure and data of $T$ such as is specified above.