Add zki.ISAccFeeOut generation for circuits compat

- add IntermediateStates AccFeeOut correct generation for circuits
compatibility at ZKInputs
- Fix formatAccumulatedFees
- organize ZKInputs tests to check compatibility with Circom circuits
- Add TestZKInputs2
    - which checks ZKInputs for 4 L1 txs + 2 L2Txs with fees
    - tested with Hermez Circom circuits
This commit is contained in:
arnaucube
2020-12-09 12:34:45 +01:00
parent 8de7fe537a
commit c162563376
3 changed files with 220 additions and 68 deletions

View File

@@ -240,8 +240,8 @@ func (s *StateDB) ProcessTxs(ptc ProcessTxsConfig, coordIdxs []common.Idx, l1use
} }
s.zki.Metadata.L2TxsData = append(s.zki.Metadata.L2TxsData, l2TxData) s.zki.Metadata.L2TxsData = append(s.zki.Metadata.L2TxsData, l2TxData)
// Intermediate States
if s.i < nTx-1 { if s.i < nTx-1 {
// Intermediate States
s.zki.ISOutIdx[s.i] = s.idx.BigInt() s.zki.ISOutIdx[s.i] = s.idx.BigInt()
s.zki.ISStateRoot[s.i] = s.mt.Root().BigInt() s.zki.ISStateRoot[s.i] = s.mt.Root().BigInt()
s.zki.ISAccFeeOut[s.i] = formatAccumulatedFees(collectedFees, s.zki.FeePlanTokens) s.zki.ISAccFeeOut[s.i] = formatAccumulatedFees(collectedFees, s.zki.FeePlanTokens)
@@ -268,6 +268,7 @@ func (s *StateDB) ProcessTxs(ptc ProcessTxsConfig, coordIdxs []common.Idx, l1use
if i < int(ptc.MaxTx)-1 { if i < int(ptc.MaxTx)-1 {
s.zki.ISOutIdx[i] = s.idx.BigInt() s.zki.ISOutIdx[i] = s.idx.BigInt()
s.zki.ISStateRoot[i] = s.mt.Root().BigInt() s.zki.ISStateRoot[i] = s.mt.Root().BigInt()
s.zki.ISAccFeeOut[i] = formatAccumulatedFees(collectedFees, s.zki.FeePlanTokens)
} }
if i >= s.i { if i >= s.i {
s.zki.TxCompressedData[i] = new(big.Int).SetBytes(common.SignatureConstantBytes) s.zki.TxCompressedData[i] = new(big.Int).SetBytes(common.SignatureConstantBytes)

View File

@@ -170,7 +170,7 @@ func formatAccumulatedFees(collectedFees map[common.TokenID]*big.Int, orderToken
for i := 0; i < len(orderTokenIDs); i++ { for i := 0; i < len(orderTokenIDs); i++ {
tokenID := common.TokenIDFromBigInt(orderTokenIDs[i]) tokenID := common.TokenIDFromBigInt(orderTokenIDs[i])
if _, ok := collectedFees[tokenID]; ok { if _, ok := collectedFees[tokenID]; ok {
accFeeOut[i] = collectedFees[tokenID] accFeeOut[i] = new(big.Int).Set(collectedFees[tokenID])
} else { } else {
accFeeOut[i] = big.NewInt(0) accFeeOut[i] = big.NewInt(0)
} }

File diff suppressed because one or more lines are too long