# Bid v/s Ask Balance Updates

|                               **Bid Case ($O\_{\text{own}}.t.\phi=0$)**                               |          **Ask Case ($O\_{\text{own}}.t.\phi=1$)**          |
| :---------------------------------------------------------------------------------------------------: | :---------------------------------------------------------: |
|                                              **Initial**                                              |                         **Initial**                         |
|                  $b\_{\text{own}} = (0, (O\_{\text{own}}.s.p) (O\_{\text{own}}.s.v))$                 |               $b\_{\text{own}} = (\gamma, 0)$               |
|                                       $b\_i = (\gamma\_{i}, 0)$                                       |     $b\_i = (0, (O\_{\text{i}}.s.p)(O\_{\text{i}}.s.v))$    |
|                                               **Final**                                               |                          **Final**                          |
|                               $\gamma = \sum\_{i=0}^{n-1} \gamma\_i + k$                              |         $\gamma = \sum\_{i=0}^{n-1} O\_{i}.s.v + k$         |
|                                    Orders 0 to $n-1$ fully filled,                                    |               Orders 0 to $n-1$ fully filled,               |
|                               $n^{th}$ order at least partially filled.                               |          $n^{th}$ order at least partially filled.          |
|                                           $k \leq \gamma\_n$                                          |                      $k \leq O\_{n}.v$                      |
| $\nu=(O\_{\text{own}}.s.p)(O\_{\text{own}}.s.v)-\sum\_{i=0}^{n-1} \gamma\_i(O\_i.s.p) - k (O\_n.s.p)$ | $\nu= \sum\_{i=0}^{n-1} (O\_i.s.v)(O\_i.s.p) + k(O\_n.s.p)$ |
|                                    $b\_{\text{own}}=(\gamma, \nu)$                                    |                  $b\_{\text{own}}=(0,\nu)$                  |
|               $b\_i$ for $0\leq i < n= (0, (O\_{\text{own}}.s.p) (O\_{\text{own}}.s.v))$              |            $b\_i$ for $0\leq i < n= (O\_i.s.v,0)$           |
|                                     Here, $\gamma\_i == O\_i.s.v$                                     |                                                             |
|                                   $b\_n=(\gamma\_n-k, k (O\_n.s.p))$                                  |              $b\_n=(k, (O\_n.s.p)(O\_n.s.v-k))$             |

7. Construct $O\_{cho}$ with all attributes of $O\_{own}$, subtracting $\gamma$ from volume and replacing the access key with a newly sampled $\alpha$. If $\gamma == O\_{own}.s.v$, then use dummy values for $O\_{cho}$.
8. Construct $O\_{chn}$ with all attributes of $O\_{n}$, subtracting $\gamma - \sum\_{i=0}^{n-1} O\_i.s.v$ from volume and replacing the access key with a newly sampled $\alpha$. If $\gamma == \sum\_{i=0}^n O\_i.s.v$, then use dummy values for $O\_{chn}$.
9. Construct $\bar O\_{cho} = (O\_{cho}.t, H(O\_{cho}.s))$ and $\bar O\_{chn} = (O\_{chn}.t, H(O\_{chn}.s))$.
10. Add ${\bar O\_{own}, {\bar O\_i}*{i=0}^n, b*{own}, {b\_i}*{i=0}^n, O*{n-1}.p, \bar O\_{cho}, \bar O\_{chn}}$ as public outputs.
