# opru node
## Creator defines
1. mapping of tx_type to fraud proof, we break the farud proof into components where each componetn changes the merkle root once.
```
tx_type_len = 2 # supports 4 differnt tx_types
fraud_proof[0] = function_call_1_phase_1, function_call_1_phase_2 , function_call_1_phase_3
fraud_proof[1] = function_call_2_phase_1, function_call_2_phase_2
```
## Get tx from user ( maybe generic - change in tx structure will change the API, but not too much work)
### Tx Structure
sign: signed message
message: the message that is signed.
Message = tx_type + rest of message.
## Get fraud proof data for tx ( non-generic)
Coordinator receives a TX.
``` python
# should create witness and validate any TX
def create_witness(signed_message, message):
# number of merkle proofs
merkle_proof_count = 0
# get tx type
tx_type = message[0:tx_type_len]
# find how many merkle proofs to provide
params = fraud_proofs[tx_type].parameters()
for param in params:
if(param contains "leaf_"):
merkle_proof_counts += 1
# for each merkle proof take the next tree_depth bits from message and look up that account
# we force the first parameters of the function call to be the leaf variables to lookup
for i in range(0, merkle_proof_counts):
for j in range(0,len(fraud_proofs[tx_type]))
leaf_index = message[tx_type_leaf:i*tree_depth]
new_root, new_leaf = merkle_proofs.append(get_proof(leaf_index, param[i]))
# we update the leaf with new_leaf
update_leaf(leaf_index, new_leaf)
return(merkle_proofs)
```
## Hit processTx with data ( non-generic)
```python
def hit_processTX():
for tx in txs:
proofs = create_witness(tx.signed_message, tx.message)
tx.proofs = proofs
return(process_tx(tx, tx.proofs))
```
Replace pre-image of accounts post `processTx`
## Get result post `processTx` and update database (non-generic)
Same as above
## Send batch ( non-generic)
How do we reason about fees we can do it but gets complicated
### Commitment
``` python
def create_commitment(txs, witness):
spoke_roots = {}
for tx in txs:
tx.validate()
root = check(tx, witness)
spoke_roots[tx.destintation_spoke_it] = update_root(spoke_roots[tx.destintation_spoke_it], tx.new_leaf)
return(root, spoke_roots)
```
### encode / decode
``` python
# first 10 bits address
# second 10 bits nonce
data = [0,10,20]
def bits_to_leaf(binary_array):
leaf.address = binary_array[data[0], data[1]]
leaf.nonce = binary_array[data[1], data[2]]
```
## Conclusion
OKay think i convinced mysefl it can work with just a few mappings defined in `create_witness` we do all the heavy lifting. I did not do create_batch yet beacues that involves reasonaing about fees which is not added yet and also gets a little complicated.
So at teh end of the day CC needs to define a mapping from TX_type - > frand_proof_phase_0 ... frand_proof_phase_N where each is a solidity function that takes the whole message as inputs and returns the new new leaf after it has been changed. So each phase updates a single leaf in the merkle tree.
## Apendix