hermeznetwork / circuits

Implements hermez network zk-Snarks circuits
GNU Affero General Public License v3.0
56 stars 21 forks source link

L2 tx data: maxNumBatch #18

Closed krlosMata closed 3 years ago

krlosMata commented 3 years ago

Feature

Add new field to L2 transaction data which allows a transaction to have a timeout measured in batch numbers. Hence, the transaction could not be processed if maxNumBatch is greater than the current batch number. New input must be added to the circuit, forced by the smart contract, which would be the currentNumBatch.

hashGlobalInputs

New input currentNumBatch must be added to the hashGlobalInputs:

**Buffer bytes notation**
hashGlobalData: [            MAX_NLEVELS bits          ] oldLastIdx 
                [            MAX_NLEVELS bits          ] newLastIdx
                [                256 bits              ] oldStRoot
                [                256 bits              ] newStRoot
                [                256 bits              ] newExitRoot
                [ MAX_L1_TX*(2*MAX_NLEVELS + 480) bits ] L1TxsData
                [     MAX_TX*(2*NLevels + 24) bits     ] L2TxsData
                [       NLevels * MAX_TOKENS_FEE       ] feeTxsData
                [                 16 bits              ] chainID
                [                 32 bits              ] currentNumBatch

hashGlobalInputs = SHA256(hashGlobalData) % rField

L2 transaction field and signed message

L2 transaction field will add maxNumBatch in order to be signed. Note that this new field is added into the e_1 field element when computing the L2HashSignautre:

**Field element notation**
e_1:[      160 bits    ] toEthAddr
    [      32 bits     ] maxNumBatch  
Total bits e_1: 192  
messageToSign = H(e_0, e_1, e_2, e_3, e_4, e_5)

e_0: [ 241 bits ] txCompressedData
e_1: [ 192 bits ] e_1 
e_2: [ 253 bits ] toBjjAy
e_3: [ 193 bits ] rqTxCompressedDataV2
e_4: [ 160 bits ] rqToEthAddr
e_5: [ 253 bits ] rqToBjjAy

Steps

krlosMata commented 3 years ago

implemented in #20