Browse Source

Rename load amount to deposit amount

feature/sql-semaphore1
Arnau B 4 years ago
parent
commit
445f26ec9f
26 changed files with 519 additions and 519 deletions
  1. +2
    -2
      api/config.go
  2. +14
    -14
      api/swagger.yml
  3. +12
    -12
      api/txshistory_test.go
  4. +3
    -3
      common/ethrollup.go
  5. +17
    -17
      common/l1tx.go
  6. +32
    -32
      common/l1tx_test.go
  7. +2
    -2
      common/pooll2tx.go
  8. +9
    -9
      common/tx.go
  9. +3
    -3
      common/zk.go
  10. +32
    -32
      db/historydb/historydb.go
  11. +17
    -17
      db/historydb/historydb_test.go
  12. +12
    -12
      db/historydb/views.go
  13. +12
    -12
      db/migrations/0001.sql
  14. +24
    -24
      db/statedb/txprocessors.go
  15. +85
    -85
      db/statedb/txprocessors_test.go
  16. +10
    -10
      eth/rollup.go
  17. +143
    -143
      eth/rollup_test.go
  18. +5
    -5
      synchronizer/synchronizer_test.go
  19. +5
    -5
      test/ethclient.go
  20. +7
    -7
      test/ethclient_test.go
  21. +6
    -6
      test/historydb.go
  22. +15
    -15
      test/til/lang.go
  23. +1
    -1
      test/til/lang_test.go
  24. +29
    -29
      test/til/txs.go
  25. +8
    -8
      test/til/txs_test.go
  26. +14
    -14
      txselector/txselector.go

+ 2
- 2
api/config.go

@ -13,7 +13,7 @@ type rollupConstants struct {
MaxFeeIdxCoordinator int `json:"maxFeeIdxCoordinator"` MaxFeeIdxCoordinator int `json:"maxFeeIdxCoordinator"`
ReservedIdx int `json:"reservedIdx"` ReservedIdx int `json:"reservedIdx"`
ExitIdx int `json:"exitIdx"` ExitIdx int `json:"exitIdx"`
LimitLoadAmount *big.Int `json:"limitLoadAmount"`
LimitDepositAmount *big.Int `json:"limitDepositAmount"`
LimitL2TransferAmount *big.Int `json:"limitL2TransferAmount"` LimitL2TransferAmount *big.Int `json:"limitL2TransferAmount"`
LimitTokens int `json:"limitTokens"` LimitTokens int `json:"limitTokens"`
L1CoordinatorTotalBytes int `json:"l1CoordinatorTotalBytes"` L1CoordinatorTotalBytes int `json:"l1CoordinatorTotalBytes"`
@ -32,7 +32,7 @@ func newRollupConstants(publicConstants common.RollupConstants) *rollupConstants
MaxFeeIdxCoordinator: common.RollupConstMaxFeeIdxCoordinator, MaxFeeIdxCoordinator: common.RollupConstMaxFeeIdxCoordinator,
ReservedIdx: common.RollupConstReservedIDx, ReservedIdx: common.RollupConstReservedIDx,
ExitIdx: common.RollupConstExitIDx, ExitIdx: common.RollupConstExitIDx,
LimitLoadAmount: common.RollupConstLimitLoadAmount,
LimitDepositAmount: common.RollupConstLimitDepositAmount,
LimitL2TransferAmount: common.RollupConstLimitL2TransferAmount, LimitL2TransferAmount: common.RollupConstLimitL2TransferAmount,
LimitTokens: common.RollupConstLimitTokens, LimitTokens: common.RollupConstLimitTokens,
L1CoordinatorTotalBytes: common.RollupConstL1CoordinatorTotalBytes, L1CoordinatorTotalBytes: common.RollupConstL1CoordinatorTotalBytes,

+ 14
- 14
api/swagger.yml

@ -1745,12 +1745,12 @@ components:
userOrigin: userOrigin:
type: boolean type: boolean
description: True if the transaction was sent by a user. False if it was sent by a coordinator. description: True if the transaction was sent by a user. False if it was sent by a coordinator.
loadAmount:
depositAmount:
allOf: allOf:
- $ref: '#/components/schemas/BigInt' - $ref: '#/components/schemas/BigInt'
- description: Tokens transfered from L1 to L2. - description: Tokens transfered from L1 to L2.
- example: "4900000000000000000" - example: "4900000000000000000"
historicLoadAmountUSD:
historicDepositAmountUSD:
type: number type: number
description: Load amount in USD, at the moment the transaction was made. description: Load amount in USD, at the moment the transaction was made.
example: 3.897 example: 3.897
@ -1763,8 +1763,8 @@ components:
required: required:
- toForgeL1TransactionsNum - toForgeL1TransactionsNum
- userOrigin - userOrigin
- loadAmount
- historicLoadAmountUSD
- depositAmount
- historicDepositAmountUSD
- ethereumBlockNum - ethereumBlockNum
additionalProperties: false additionalProperties: false
L2Info: L2Info:
@ -1790,8 +1790,8 @@ components:
example: example:
L1Info: L1Info:
ethereumBlockNum: 1 ethereumBlockNum: 1
historicLoadAmountUSD: 232.47
loadAmount: '261'
historicDepositAmountUSD: 232.47
depositAmount: '261'
toForgeL1TransactionsNum: 10 toForgeL1TransactionsNum: 10
userOrigin: true userOrigin: true
L1orL2: L1 L1orL2: L1
@ -1854,8 +1854,8 @@ components:
transactions: transactions:
- L1Info: - L1Info:
ethereumBlockNum: 3 ethereumBlockNum: 3
historicLoadAmountUSD:
loadAmount: '0'
historicDepositAmountUSD:
depositAmount: '0'
toForgeL1TransactionsNum: 7 toForgeL1TransactionsNum: 7
userOrigin: true userOrigin: true
L1orL2: L1 L1orL2: L1
@ -1946,8 +1946,8 @@ components:
type: Exit type: Exit
- L1Info: - L1Info:
ethereumBlockNum: 3 ethereumBlockNum: 3
historicLoadAmountUSD: 14099.9999859
loadAmount: '33333333300000000000'
historicDepositAmountUSD: 14099.9999859
depositAmount: '33333333300000000000'
toForgeL1TransactionsNum: 2 toForgeL1TransactionsNum: 2
userOrigin: true userOrigin: true
L1orL2: L1 L1orL2: L1
@ -2480,7 +2480,7 @@ components:
example: example:
accounts: accounts:
- accountIndex: hez:ETH:259 - accountIndex: hez:ETH:259
balance: '2590000000'
balance: '2590000000000000000'
bjj: hez:W6x4TZOAZ9mAqdOb3Xm_hKDLspaXfEfMMN4tXOkinS-W bjj: hez:W6x4TZOAZ9mAqdOb3Xm_hKDLspaXfEfMMN4tXOkinS-W
hezEthereumAddress: hez:0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf hezEthereumAddress: hez:0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf
itemId: 4 itemId: 4
@ -2954,7 +2954,7 @@ components:
type: integer type: integer
description: Account index used to indicate that a transaction is an `exit` or `force exit`. description: Account index used to indicate that a transaction is an `exit` or `force exit`.
example: 1 example: 1
limitLoadAmount:
limitDepositAmount:
type: integer type: integer
description: Maximum load amount (L1 to L2) allowed. description: Maximum load amount (L1 to L2) allowed.
example: 321 example: 321
@ -2972,7 +2972,7 @@ components:
example: 101 example: 101
l1UserTotalBytes: l1UserTotalBytes:
type: integer type: integer
description: Number of bytes that a L1 user transaction has ([20 bytes] fromEthAddr + [32 bytes] fromBjj-compressed + [6 bytes] fromIdx + [2 bytes] loadAmountFloat16 + [2 bytes] amountFloat16 + [4 bytes] tokenId + [6 bytes] toIdx).
description: Number of bytes that a L1 user transaction has ([20 bytes] fromEthAddr + [32 bytes] fromBjj-compressed + [6 bytes] fromIdx + [2 bytes] depositAmountFloat16 + [2 bytes] amountFloat16 + [4 bytes] tokenId + [6 bytes] toIdx).
example: 72 example: 72
maxL1UserTx: maxL1UserTx:
type: integer type: integer
@ -3002,7 +3002,7 @@ components:
- publicConstants - publicConstants
- reservedIdx - reservedIdx
- exitIdx - exitIdx
- limitLoadAmount
- limitDepositAmount
- limitL2TransferAmount - limitL2TransferAmount
- limitTokens - limitTokens
- l1CoordinatorTotalBytes - l1CoordinatorTotalBytes

+ 12
- 12
api/txshistory_test.go

@ -18,11 +18,11 @@ import (
) )
type testL1Info struct { type testL1Info struct {
ToForgeL1TxsNum *int64 `json:"toForgeL1TransactionsNum"`
UserOrigin bool `json:"userOrigin"`
LoadAmount string `json:"loadAmount"`
HistoricLoadAmountUSD *float64 `json:"historicLoadAmountUSD"`
EthBlockNum int64 `json:"ethereumBlockNum"`
ToForgeL1TxsNum *int64 `json:"toForgeL1TransactionsNum"`
UserOrigin bool `json:"userOrigin"`
DepositAmount string `json:"depositAmount"`
HistoricDepositAmountUSD *float64 `json:"historicDepositAmountUSD"`
EthBlockNum int64 `json:"ethereumBlockNum"`
} }
type testL2Info struct { type testL2Info struct {
@ -125,7 +125,7 @@ func genTestTxs(
L1Info: &testL1Info{ L1Info: &testL1Info{
ToForgeL1TxsNum: l1.ToForgeL1TxsNum, ToForgeL1TxsNum: l1.ToForgeL1TxsNum,
UserOrigin: l1.UserOrigin, UserOrigin: l1.UserOrigin,
LoadAmount: l1.LoadAmount.String(),
DepositAmount: l1.DepositAmount.String(),
EthBlockNum: l1.EthBlockNum, EthBlockNum: l1.EthBlockNum,
}, },
Token: token, Token: token,
@ -160,11 +160,11 @@ func genTestTxs(
if usd != 0 { if usd != 0 {
tx.HistoricUSD = &usd tx.HistoricUSD = &usd
} }
laf := new(big.Float).SetInt(l1.LoadAmount)
loadAmountFloat, _ := laf.Float64()
loadUSD := *token.USD * loadAmountFloat / math.Pow(10, float64(token.Decimals))
if loadAmountFloat != 0 {
tx.L1Info.HistoricLoadAmountUSD = &loadUSD
laf := new(big.Float).SetInt(l1.DepositAmount)
depositAmountFloat, _ := laf.Float64()
loadUSD := *token.USD * depositAmountFloat / math.Pow(10, float64(token.Decimals))
if depositAmountFloat != 0 {
tx.L1Info.HistoricDepositAmountUSD = &loadUSD
} }
} }
txs = append(txs, tx) txs = append(txs, tx)
@ -474,7 +474,7 @@ func assertTxs(t *testing.T, expected, actual []testTx) {
if expected[i].L2Info != nil { if expected[i].L2Info != nil {
test.AssertUSD(t, expected[i].L2Info.HistoricFeeUSD, actual[i].L2Info.HistoricFeeUSD) test.AssertUSD(t, expected[i].L2Info.HistoricFeeUSD, actual[i].L2Info.HistoricFeeUSD)
} else { } else {
test.AssertUSD(t, expected[i].L1Info.HistoricLoadAmountUSD, actual[i].L1Info.HistoricLoadAmountUSD)
test.AssertUSD(t, expected[i].L1Info.HistoricDepositAmountUSD, actual[i].L1Info.HistoricDepositAmountUSD)
} }
assert.Equal(t, expected[i], actual[i]) assert.Equal(t, expected[i], actual[i])
} }

+ 3
- 3
common/ethrollup.go

@ -66,7 +66,7 @@ const (
// RollupConstL1CoordinatorTotalBytes [4 bytes] token + [32 bytes] babyjub + [65 bytes] compressedSignature // RollupConstL1CoordinatorTotalBytes [4 bytes] token + [32 bytes] babyjub + [65 bytes] compressedSignature
RollupConstL1CoordinatorTotalBytes = 101 RollupConstL1CoordinatorTotalBytes = 101
// RollupConstL1UserTotalBytes [20 bytes] fromEthAddr + [32 bytes] fromBjj-compressed + [6 bytes] fromIdx + // RollupConstL1UserTotalBytes [20 bytes] fromEthAddr + [32 bytes] fromBjj-compressed + [6 bytes] fromIdx +
// [2 bytes] loadAmountFloat16 + [2 bytes] amountFloat16 + [4 bytes] tokenId + [6 bytes] toIdx
// [2 bytes] depositAmountFloat16 + [2 bytes] amountFloat16 + [4 bytes] tokenId + [6 bytes] toIdx
RollupConstL1UserTotalBytes = 72 RollupConstL1UserTotalBytes = 72
// RollupConstMaxL1UserTx Maximum L1-user transactions allowed to be queued in a batch // RollupConstMaxL1UserTx Maximum L1-user transactions allowed to be queued in a batch
RollupConstMaxL1UserTx = 128 RollupConstMaxL1UserTx = 128
@ -87,8 +87,8 @@ const (
) )
var ( var (
// RollupConstLimitLoadAmount Max load amount allowed (loadAmount: L1 --> L2)
RollupConstLimitLoadAmount, _ = new(big.Int).SetString("340282366920938463463374607431768211456", 10)
// RollupConstLimitDepositAmount Max load amount allowed (depositAmount: L1 --> L2)
RollupConstLimitDepositAmount, _ = new(big.Int).SetString("340282366920938463463374607431768211456", 10)
// RollupConstLimitL2TransferAmount Max amount allowed (amount L2 --> L2) // RollupConstLimitL2TransferAmount Max amount allowed (amount L2 --> L2)
RollupConstLimitL2TransferAmount, _ = new(big.Int).SetString("6277101735386680763835789423207666416102355444464034512896", 10) RollupConstLimitL2TransferAmount, _ = new(big.Int).SetString("6277101735386680763835789423207666416102355444464034512896", 10)

+ 17
- 17
common/l1tx.go

@ -32,7 +32,7 @@ type L1Tx struct {
ToForgeL1TxsNum *int64 `meddler:"to_forge_l1_txs_num"` // toForgeL1TxsNum in which the tx was forged / will be forged ToForgeL1TxsNum *int64 `meddler:"to_forge_l1_txs_num"` // toForgeL1TxsNum in which the tx was forged / will be forged
Position int `meddler:"position"` Position int `meddler:"position"`
UserOrigin bool `meddler:"user_origin"` // true if the tx was originated by a user, false if it was aoriginated by a coordinator. Note that this differ from the spec for implementation simplification purpposes UserOrigin bool `meddler:"user_origin"` // true if the tx was originated by a user, false if it was aoriginated by a coordinator. Note that this differ from the spec for implementation simplification purpposes
FromIdx Idx `meddler:"from_idx,zeroisnull"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
FromIdx Idx `meddler:"from_idx,zeroisnull"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.DepositAmount (deposit)
FromEthAddr ethCommon.Address `meddler:"from_eth_addr,zeroisnull"` FromEthAddr ethCommon.Address `meddler:"from_eth_addr,zeroisnull"`
FromBJJ *babyjub.PublicKey `meddler:"from_bjj,zeroisnull"` FromBJJ *babyjub.PublicKey `meddler:"from_bjj,zeroisnull"`
ToIdx Idx `meddler:"to_idx"` // ToIdx is ignored in L1Tx/Deposit, but used in the L1Tx/DepositAndTransfer ToIdx Idx `meddler:"to_idx"` // ToIdx is ignored in L1Tx/Deposit, but used in the L1Tx/DepositAndTransfer
@ -40,12 +40,12 @@ type L1Tx struct {
Amount *big.Int `meddler:"amount,bigint"` Amount *big.Int `meddler:"amount,bigint"`
// EffectiveAmount only applies to L1UserTx. // EffectiveAmount only applies to L1UserTx.
EffectiveAmount *big.Int `meddler:"effective_amount,bigintnull"` EffectiveAmount *big.Int `meddler:"effective_amount,bigintnull"`
LoadAmount *big.Int `meddler:"load_amount,bigint"`
// EffectiveLoadAmount only applies to L1UserTx.
EffectiveLoadAmount *big.Int `meddler:"effective_load_amount,bigintnull"`
EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue
Type TxType `meddler:"type"`
BatchNum *BatchNum `meddler:"batch_num"`
DepositAmount *big.Int `meddler:"deposit_amount,bigint"`
// EffectiveDepositAmount only applies to L1UserTx.
EffectiveDepositAmount *big.Int `meddler:"effective_deposit_amount,bigintnull"`
EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue
Type TxType `meddler:"type"`
BatchNum *BatchNum `meddler:"batch_num"`
} }
// NewL1Tx returns the given L1Tx with the TxId & Type parameters calculated // NewL1Tx returns the given L1Tx with the TxId & Type parameters calculated
@ -67,7 +67,7 @@ func NewL1Tx(l1Tx *L1Tx) (*L1Tx, error) {
} else if l1Tx.ToIdx == Idx(1) { } else if l1Tx.ToIdx == Idx(1) {
txType = TxTypeForceExit txType = TxTypeForceExit
} else if l1Tx.ToIdx >= IdxUserThreshold { } else if l1Tx.ToIdx >= IdxUserThreshold {
if l1Tx.LoadAmount.Int64() == int64(0) {
if l1Tx.DepositAmount.Int64() == int64(0) {
txType = TxTypeForceTransfer txType = TxTypeForceTransfer
} else { } else {
txType = TxTypeDepositTransfer txType = TxTypeDepositTransfer
@ -140,13 +140,13 @@ func (tx L1Tx) Tx() Tx {
UserOrigin: userOrigin, UserOrigin: userOrigin,
FromEthAddr: tx.FromEthAddr, FromEthAddr: tx.FromEthAddr,
FromBJJ: tx.FromBJJ, FromBJJ: tx.FromBJJ,
LoadAmount: tx.EffectiveLoadAmount,
DepositAmount: tx.EffectiveDepositAmount,
EthBlockNum: tx.EthBlockNum, EthBlockNum: tx.EthBlockNum,
} }
if tx.LoadAmount != nil {
lf := new(big.Float).SetInt(tx.LoadAmount)
loadAmountFloat, _ := lf.Float64()
genericTx.LoadAmountFloat = &loadAmountFloat
if tx.DepositAmount != nil {
lf := new(big.Float).SetInt(tx.DepositAmount)
depositAmountFloat, _ := lf.Float64()
genericTx.DepositAmountFloat = &depositAmountFloat
} }
return genericTx return genericTx
} }
@ -257,11 +257,11 @@ func (tx *L1Tx) BytesGeneric() ([]byte, error) {
return nil, tracerr.Wrap(err) return nil, tracerr.Wrap(err)
} }
copy(b[52:58], fromIdxBytes[:]) copy(b[52:58], fromIdxBytes[:])
loadAmountFloat16, err := NewFloat16(tx.LoadAmount)
depositAmountFloat16, err := NewFloat16(tx.DepositAmount)
if err != nil { if err != nil {
return nil, tracerr.Wrap(err) return nil, tracerr.Wrap(err)
} }
copy(b[58:60], loadAmountFloat16.Bytes())
copy(b[58:60], depositAmountFloat16.Bytes())
amountFloat16, err := NewFloat16(tx.Amount) amountFloat16, err := NewFloat16(tx.Amount)
if err != nil { if err != nil {
return nil, tracerr.Wrap(err) return nil, tracerr.Wrap(err)
@ -328,7 +328,7 @@ func L1UserTxFromBytes(b []byte) (*L1Tx, error) {
return nil, tracerr.Wrap(err) return nil, tracerr.Wrap(err)
} }
tx.FromIdx = fromIdx tx.FromIdx = fromIdx
tx.LoadAmount = Float16FromBytes(b[58:60]).BigInt()
tx.DepositAmount = Float16FromBytes(b[58:60]).BigInt()
tx.Amount = Float16FromBytes(b[60:62]).BigInt() tx.Amount = Float16FromBytes(b[60:62]).BigInt()
tx.TokenID, err = TokenIDFromBytes(b[62:66]) tx.TokenID, err = TokenIDFromBytes(b[62:66])
if err != nil { if err != nil {
@ -375,7 +375,7 @@ func L1CoordinatorTxFromBytes(b []byte, chainID *big.Int, hermezAddress ethCommo
return nil, tracerr.Wrap(err) return nil, tracerr.Wrap(err)
} }
tx.Amount = big.NewInt(0) tx.Amount = big.NewInt(0)
tx.LoadAmount = big.NewInt(0)
tx.DepositAmount = big.NewInt(0)
if int(v) > 0 { if int(v) > 0 {
// L1CoordinatorTX ETH // L1CoordinatorTX ETH
// Ethereum adds 27 to v // Ethereum adds 27 to v

+ 32
- 32
common/l1tx_test.go

@ -24,7 +24,7 @@ func TestNewL1UserTx(t *testing.T) {
ToIdx: 301, ToIdx: 301,
TokenID: 5, TokenID: 5,
Amount: big.NewInt(1), Amount: big.NewInt(1),
LoadAmount: big.NewInt(2),
DepositAmount: big.NewInt(2),
FromIdx: Idx(300), FromIdx: Idx(300),
} }
l1Tx, err := NewL1Tx(l1Tx) l1Tx, err := NewL1Tx(l1Tx)
@ -35,14 +35,14 @@ func TestNewL1UserTx(t *testing.T) {
func TestNewL1CoordinatorTx(t *testing.T) { func TestNewL1CoordinatorTx(t *testing.T) {
batchNum := BatchNum(51966) batchNum := BatchNum(51966)
l1Tx := &L1Tx{ l1Tx := &L1Tx{
Position: 88,
UserOrigin: false,
ToIdx: 301,
TokenID: 5,
Amount: big.NewInt(1),
LoadAmount: big.NewInt(2),
FromIdx: Idx(300),
BatchNum: &batchNum,
Position: 88,
UserOrigin: false,
ToIdx: 301,
TokenID: 5,
Amount: big.NewInt(1),
DepositAmount: big.NewInt(2),
FromIdx: Idx(300),
BatchNum: &batchNum,
} }
l1Tx, err := NewL1Tx(l1Tx) l1Tx, err := NewL1Tx(l1Tx)
assert.Nil(t, err) assert.Nil(t, err)
@ -124,14 +124,14 @@ func TestL1userTxByteParsers(t *testing.T) {
require.Nil(t, err) require.Nil(t, err)
l1Tx := &L1Tx{ l1Tx := &L1Tx{
UserOrigin: true,
ToIdx: 3,
TokenID: 5,
Amount: big.NewInt(1),
LoadAmount: big.NewInt(2),
FromIdx: 2,
FromBJJ: pk,
FromEthAddr: ethCommon.HexToAddress("0xc58d29fA6e86E4FAe04DDcEd660d45BCf3Cb2370"),
UserOrigin: true,
ToIdx: 3,
TokenID: 5,
Amount: big.NewInt(1),
DepositAmount: big.NewInt(2),
FromIdx: 2,
FromBJJ: pk,
FromEthAddr: ethCommon.HexToAddress("0xc58d29fA6e86E4FAe04DDcEd660d45BCf3Cb2370"),
} }
encodedData, err := l1Tx.BytesUser() encodedData, err := l1Tx.BytesUser()
@ -164,17 +164,17 @@ func TestL1TxByteParsersCompatibility(t *testing.T) {
pk, err := pkComp.Decompress() pk, err := pkComp.Decompress()
require.Nil(t, err) require.Nil(t, err)
loadAmount := new(big.Int)
loadAmount.SetString("100000000000000000000", 10)
depositAmount := new(big.Int)
depositAmount.SetString("100000000000000000000", 10)
l1Tx := &L1Tx{ l1Tx := &L1Tx{
ToIdx: 87865485,
TokenID: 2098076,
Amount: big.NewInt(2400000000000000000),
LoadAmount: loadAmount,
FromIdx: Idx(29767899),
FromBJJ: pk,
FromEthAddr: ethCommon.HexToAddress("0x85dab5b9e2e361d0c208d77be90efcc0439b0a53"),
UserOrigin: true,
ToIdx: 87865485,
TokenID: 2098076,
Amount: big.NewInt(2400000000000000000),
DepositAmount: depositAmount,
FromIdx: Idx(29767899),
FromBJJ: pk,
FromEthAddr: ethCommon.HexToAddress("0x85dab5b9e2e361d0c208d77be90efcc0439b0a53"),
UserOrigin: true,
} }
expected, err := utils.HexDecode("85dab5b9e2e361d0c208d77be90efcc0439b0a530dd02deb2c81068e7a0f7e327df80b4ab79ee1f41a7def613e73a20c32eece5a000001c638db8be880f00020039c0000053cb88d") expected, err := utils.HexDecode("85dab5b9e2e361d0c208d77be90efcc0439b0a530dd02deb2c81068e7a0f7e327df80b4ab79ee1f41a7def613e73a20c32eece5a000001c638db8be880f00020039c0000053cb88d")
@ -227,11 +227,11 @@ func TestL1CoordinatorTxByteParsers(t *testing.T) {
signature[64] = byte(v + 27) signature[64] = byte(v + 27)
l1Tx := &L1Tx{ l1Tx := &L1Tx{
TokenID: 231,
FromBJJ: pk,
FromEthAddr: fromEthAddr,
Amount: big.NewInt(0),
LoadAmount: big.NewInt(0),
TokenID: 231,
FromBJJ: pk,
FromEthAddr: fromEthAddr,
Amount: big.NewInt(0),
DepositAmount: big.NewInt(0),
} }
bytesCoordinatorL1, err := l1Tx.BytesCoordinatorTx(signature) bytesCoordinatorL1, err := l1Tx.BytesCoordinatorTx(signature)

+ 2
- 2
common/pooll2tx.go

@ -33,8 +33,8 @@ type PoolL2Tx struct {
Signature babyjub.SignatureComp `meddler:"signature"` // tx signature Signature babyjub.SignatureComp `meddler:"signature"` // tx signature
Timestamp time.Time `meddler:"timestamp,utctime"` // time when added to the tx pool Timestamp time.Time `meddler:"timestamp,utctime"` // time when added to the tx pool
// Stored in DB: optional fileds, may be uninitialized // Stored in DB: optional fileds, may be uninitialized
RqFromIdx Idx `meddler:"rq_from_idx,zeroisnull"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
RqToIdx Idx `meddler:"rq_to_idx,zeroisnull"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
RqFromIdx Idx `meddler:"rq_from_idx,zeroisnull"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.DepositAmount (deposit)
RqToIdx Idx `meddler:"rq_to_idx,zeroisnull"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.DepositAmount (deposit)
RqToEthAddr ethCommon.Address `meddler:"rq_to_eth_addr,zeroisnull"` RqToEthAddr ethCommon.Address `meddler:"rq_to_eth_addr,zeroisnull"`
RqToBJJ *babyjub.PublicKey `meddler:"rq_to_bjj"` // TODO: stop using json, use scanner/valuer RqToBJJ *babyjub.PublicKey `meddler:"rq_to_bjj"` // TODO: stop using json, use scanner/valuer
RqTokenID TokenID `meddler:"rq_token_id,zeroisnull"` RqTokenID TokenID `meddler:"rq_token_id,zeroisnull"`

+ 9
- 9
common/tx.go

@ -140,13 +140,13 @@ type Tx struct {
BatchNum *BatchNum `meddler:"batch_num"` // batchNum in which this tx was forged. If the tx is L2, this must be != 0 BatchNum *BatchNum `meddler:"batch_num"` // batchNum in which this tx was forged. If the tx is L2, this must be != 0
EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue
// L1 // L1
ToForgeL1TxsNum *int64 `meddler:"to_forge_l1_txs_num"` // toForgeL1TxsNum in which the tx was forged / will be forged
UserOrigin *bool `meddler:"user_origin"` // true if the tx was originated by a user, false if it was aoriginated by a coordinator. Note that this differ from the spec for implementation simplification purpposes
FromEthAddr ethCommon.Address `meddler:"from_eth_addr"`
FromBJJ *babyjub.PublicKey `meddler:"from_bjj"`
LoadAmount *big.Int `meddler:"load_amount,bigintnull"`
LoadAmountFloat *float64 `meddler:"load_amount_f"`
LoadAmountUSD *float64 `meddler:"load_amount_usd"`
ToForgeL1TxsNum *int64 `meddler:"to_forge_l1_txs_num"` // toForgeL1TxsNum in which the tx was forged / will be forged
UserOrigin *bool `meddler:"user_origin"` // true if the tx was originated by a user, false if it was aoriginated by a coordinator. Note that this differ from the spec for implementation simplification purpposes
FromEthAddr ethCommon.Address `meddler:"from_eth_addr"`
FromBJJ *babyjub.PublicKey `meddler:"from_bjj"`
DepositAmount *big.Int `meddler:"deposit_amount,bigintnull"`
DepositAmountFloat *float64 `meddler:"deposit_amount_f"`
DepositAmountUSD *float64 `meddler:"deposit_amount_usd"`
// L2 // L2
Fee *FeeSelector `meddler:"fee"` Fee *FeeSelector `meddler:"fee"`
FeeUSD *float64 `meddler:"fee_usd"` FeeUSD *float64 `meddler:"fee_usd"`
@ -165,7 +165,7 @@ func (tx *Tx) String() string {
if tx.Type == TxTypeDeposit || if tx.Type == TxTypeDeposit ||
tx.Type == TxTypeDepositTransfer || tx.Type == TxTypeDepositTransfer ||
tx.Type == TxTypeCreateAccountDepositTransfer { tx.Type == TxTypeCreateAccountDepositTransfer {
fmt.Fprintf(buf, "LoadAmount: %d, ", tx.LoadAmount)
fmt.Fprintf(buf, "DepositAmount: %d, ", tx.DepositAmount)
} }
if tx.Type != TxTypeDeposit { if tx.Type != TxTypeDeposit {
fmt.Fprintf(buf, "Amount: %s, ", tx.Amount) fmt.Fprintf(buf, "Amount: %s, ", tx.Amount)
@ -193,7 +193,7 @@ func (tx *Tx) L1Tx() (*L1Tx, error) {
ToIdx: tx.ToIdx, ToIdx: tx.ToIdx,
TokenID: tx.TokenID, TokenID: tx.TokenID,
Amount: tx.Amount, Amount: tx.Amount,
LoadAmount: tx.LoadAmount,
DepositAmount: tx.DepositAmount,
EthBlockNum: tx.EthBlockNum, EthBlockNum: tx.EthBlockNum,
Type: tx.Type, Type: tx.Type,
BatchNum: tx.BatchNum, BatchNum: tx.BatchNum,

+ 3
- 3
common/zk.go

@ -106,8 +106,8 @@ type ZKInputs struct {
// //
// NewAccount boolean (0/1) flag set 'true' when L1 tx creates a new account (fromIdx==0) // NewAccount boolean (0/1) flag set 'true' when L1 tx creates a new account (fromIdx==0)
NewAccount []*big.Int `json:"newAccount"` // bool, len: [nTx] NewAccount []*big.Int `json:"newAccount"` // bool, len: [nTx]
// LoadAmountF encoded as float16
LoadAmountF []*big.Int `json:"loadAmountF"` // uint16, len: [nTx]
// DepositAmountF encoded as float16
DepositAmountF []*big.Int `json:"loadAmountF"` // uint16, len: [nTx]
// FromEthAddr // FromEthAddr
FromEthAddr []*big.Int `json:"fromEthAddr"` // ethCommon.Address, len: [nTx] FromEthAddr []*big.Int `json:"fromEthAddr"` // ethCommon.Address, len: [nTx]
// FromBJJCompressed boolean encoded where each value is a *big.Int // FromBJJCompressed boolean encoded where each value is a *big.Int
@ -310,7 +310,7 @@ func NewZKInputs(nTx, maxL1Tx, maxTx, maxFeeIdxs, nLevels uint32, currentNumBatc
zki.NewAccount = newSlice(nTx) zki.NewAccount = newSlice(nTx)
// L1 // L1
zki.LoadAmountF = newSlice(nTx)
zki.DepositAmountF = newSlice(nTx)
zki.FromEthAddr = newSlice(nTx) zki.FromEthAddr = newSlice(nTx)
zki.FromBJJCompressed = make([][256]*big.Int, nTx) zki.FromBJJCompressed = make([][256]*big.Int, nTx)
for i := 0; i < len(zki.FromBJJCompressed); i++ { for i := 0; i < len(zki.FromBJJCompressed); i++ {

+ 32
- 32
db/historydb/historydb.go

@ -767,23 +767,23 @@ func (hdb *HistoryDB) GetAllAccounts() ([]common.Account, error) {
return db.SlicePtrsToSlice(accs).([]common.Account), tracerr.Wrap(err) return db.SlicePtrsToSlice(accs).([]common.Account), tracerr.Wrap(err)
} }
// AddL1Txs inserts L1 txs to the DB. USD and LoadAmountUSD will be set automatically before storing the tx.
// AddL1Txs inserts L1 txs to the DB. USD and DepositAmountUSD will be set automatically before storing the tx.
// If the tx is originated by a coordinator, BatchNum must be provided. If it's originated by a user, // If the tx is originated by a coordinator, BatchNum must be provided. If it's originated by a user,
// BatchNum should be null, and the value will be setted by a trigger when a batch forges the tx. // BatchNum should be null, and the value will be setted by a trigger when a batch forges the tx.
// EffectiveAmount and EffectiveLoadAmount are seted with default values by the DB.
// EffectiveAmount and EffectiveDepositAmount are seted with default values by the DB.
func (hdb *HistoryDB) AddL1Txs(l1txs []common.L1Tx) error { return hdb.addL1Txs(hdb.db, l1txs) } func (hdb *HistoryDB) AddL1Txs(l1txs []common.L1Tx) error { return hdb.addL1Txs(hdb.db, l1txs) }
// addL1Txs inserts L1 txs to the DB. USD and LoadAmountUSD will be set automatically before storing the tx.
// addL1Txs inserts L1 txs to the DB. USD and DepositAmountUSD will be set automatically before storing the tx.
// If the tx is originated by a coordinator, BatchNum must be provided. If it's originated by a user, // If the tx is originated by a coordinator, BatchNum must be provided. If it's originated by a user,
// BatchNum should be null, and the value will be setted by a trigger when a batch forges the tx. // BatchNum should be null, and the value will be setted by a trigger when a batch forges the tx.
// EffectiveAmount and EffectiveLoadAmount are seted with default values by the DB.
// EffectiveAmount and EffectiveDepositAmount are seted with default values by the DB.
func (hdb *HistoryDB) addL1Txs(d meddler.DB, l1txs []common.L1Tx) error { func (hdb *HistoryDB) addL1Txs(d meddler.DB, l1txs []common.L1Tx) error {
txs := []txWrite{} txs := []txWrite{}
for i := 0; i < len(l1txs); i++ { for i := 0; i < len(l1txs); i++ {
af := new(big.Float).SetInt(l1txs[i].Amount) af := new(big.Float).SetInt(l1txs[i].Amount)
amountFloat, _ := af.Float64() amountFloat, _ := af.Float64()
laf := new(big.Float).SetInt(l1txs[i].LoadAmount)
loadAmountFloat, _ := laf.Float64()
laf := new(big.Float).SetInt(l1txs[i].DepositAmount)
depositAmountFloat, _ := laf.Float64()
txs = append(txs, txWrite{ txs = append(txs, txWrite{
// Generic // Generic
IsL1: true, IsL1: true,
@ -798,12 +798,12 @@ func (hdb *HistoryDB) addL1Txs(d meddler.DB, l1txs []common.L1Tx) error {
BatchNum: l1txs[i].BatchNum, BatchNum: l1txs[i].BatchNum,
EthBlockNum: l1txs[i].EthBlockNum, EthBlockNum: l1txs[i].EthBlockNum,
// L1 // L1
ToForgeL1TxsNum: l1txs[i].ToForgeL1TxsNum,
UserOrigin: &l1txs[i].UserOrigin,
FromEthAddr: &l1txs[i].FromEthAddr,
FromBJJ: l1txs[i].FromBJJ,
LoadAmount: l1txs[i].LoadAmount,
LoadAmountFloat: &loadAmountFloat,
ToForgeL1TxsNum: l1txs[i].ToForgeL1TxsNum,
UserOrigin: &l1txs[i].UserOrigin,
FromEthAddr: &l1txs[i].FromEthAddr,
FromBJJ: l1txs[i].FromBJJ,
DepositAmount: l1txs[i].DepositAmount,
DepositAmountFloat: &depositAmountFloat,
}) })
} }
return hdb.addTxs(d, txs) return hdb.addTxs(d, txs)
@ -857,8 +857,8 @@ func (hdb *HistoryDB) addTxs(d meddler.DB, txs []txWrite) error {
user_origin, user_origin,
from_eth_addr, from_eth_addr,
from_bjj, from_bjj,
load_amount,
load_amount_f,
deposit_amount,
deposit_amount_f,
fee, fee,
nonce nonce
) VALUES %s;`, ) VALUES %s;`,
@ -887,7 +887,7 @@ func (hdb *HistoryDB) GetHistoryTx(txID common.TxID) (*TxAPI, error) {
hez_idx(tx.to_idx, token.symbol) AS to_idx, tx.to_eth_addr, tx.to_bjj, hez_idx(tx.to_idx, token.symbol) AS to_idx, tx.to_eth_addr, tx.to_bjj,
tx.amount, tx.token_id, tx.amount_usd, tx.amount, tx.token_id, tx.amount_usd,
tx.batch_num, tx.eth_block_num, tx.to_forge_l1_txs_num, tx.user_origin, tx.batch_num, tx.eth_block_num, tx.to_forge_l1_txs_num, tx.user_origin,
tx.load_amount, tx.load_amount_usd, tx.fee, tx.fee_usd, tx.nonce,
tx.deposit_amount, tx.deposit_amount_usd, tx.fee, tx.fee_usd, tx.nonce,
token.token_id, token.item_id AS token_item_id, token.eth_block_num AS token_block, token.token_id, token.item_id AS token_item_id, token.eth_block_num AS token_block,
token.eth_addr, token.name, token.symbol, token.decimals, token.usd, token.eth_addr, token.name, token.symbol, token.decimals, token.usd,
token.usd_update, block.timestamp token.usd_update, block.timestamp
@ -916,7 +916,7 @@ func (hdb *HistoryDB) GetHistoryTxs(
hez_idx(tx.to_idx, token.symbol) AS to_idx, tx.to_eth_addr, tx.to_bjj, hez_idx(tx.to_idx, token.symbol) AS to_idx, tx.to_eth_addr, tx.to_bjj,
tx.amount, tx.token_id, tx.amount_usd, tx.amount, tx.token_id, tx.amount_usd,
tx.batch_num, tx.eth_block_num, tx.to_forge_l1_txs_num, tx.user_origin, tx.batch_num, tx.eth_block_num, tx.to_forge_l1_txs_num, tx.user_origin,
tx.load_amount, tx.load_amount_usd, tx.fee, tx.fee_usd, tx.nonce,
tx.deposit_amount, tx.deposit_amount_usd, tx.fee, tx.fee_usd, tx.nonce,
token.token_id, token.item_id AS token_item_id, token.eth_block_num AS token_block, token.token_id, token.item_id AS token_item_id, token.eth_block_num AS token_block,
token.eth_addr, token.name, token.symbol, token.decimals, token.usd, token.eth_addr, token.name, token.symbol, token.decimals, token.usd,
token.usd_update, block.timestamp, count(*) OVER() AS total_items token.usd_update, block.timestamp, count(*) OVER() AS total_items
@ -1169,7 +1169,7 @@ func (hdb *HistoryDB) GetAllL1UserTxs() ([]common.L1Tx, error) {
`SELECT tx.id, tx.to_forge_l1_txs_num, tx.position, tx.user_origin, `SELECT tx.id, tx.to_forge_l1_txs_num, tx.position, tx.user_origin,
tx.from_idx, tx.from_eth_addr, tx.from_bjj, tx.to_idx, tx.token_id, tx.from_idx, tx.from_eth_addr, tx.from_bjj, tx.to_idx, tx.token_id,
tx.amount, (CASE WHEN tx.batch_num IS NULL THEN NULL WHEN tx.amount_success THEN tx.amount ELSE '\x' END) AS effective_amount, tx.amount, (CASE WHEN tx.batch_num IS NULL THEN NULL WHEN tx.amount_success THEN tx.amount ELSE '\x' END) AS effective_amount,
tx.load_amount, (CASE WHEN tx.batch_num IS NULL THEN NULL WHEN tx.load_amount_success THEN tx.load_amount ELSE '\x' END) AS effective_load_amount,
tx.deposit_amount, (CASE WHEN tx.batch_num IS NULL THEN NULL WHEN tx.deposit_amount_success THEN tx.deposit_amount ELSE '\x' END) AS effective_deposit_amount,
tx.eth_block_num, tx.type, tx.batch_num tx.eth_block_num, tx.type, tx.batch_num
FROM tx WHERE is_l1 = TRUE AND user_origin = TRUE;`, FROM tx WHERE is_l1 = TRUE AND user_origin = TRUE;`,
) )
@ -1186,7 +1186,7 @@ func (hdb *HistoryDB) GetAllL1CoordinatorTxs() ([]common.L1Tx, error) {
`SELECT tx.id, tx.to_forge_l1_txs_num, tx.position, tx.user_origin, `SELECT tx.id, tx.to_forge_l1_txs_num, tx.position, tx.user_origin,
tx.from_idx, tx.from_eth_addr, tx.from_bjj, tx.to_idx, tx.token_id, tx.from_idx, tx.from_eth_addr, tx.from_bjj, tx.to_idx, tx.token_id,
tx.amount, tx.amount AS effective_amount, tx.amount, tx.amount AS effective_amount,
tx.load_amount, tx.load_amount AS effective_load_amount,
tx.deposit_amount, tx.deposit_amount AS effective_deposit_amount,
tx.eth_block_num, tx.type, tx.batch_num tx.eth_block_num, tx.type, tx.batch_num
FROM tx WHERE is_l1 = TRUE AND user_origin = FALSE;`, FROM tx WHERE is_l1 = TRUE AND user_origin = FALSE;`,
) )
@ -1214,7 +1214,7 @@ func (hdb *HistoryDB) GetUnforgedL1UserTxs(toForgeL1TxsNum int64) ([]common.L1Tx
`SELECT tx.id, tx.to_forge_l1_txs_num, tx.position, tx.user_origin, `SELECT tx.id, tx.to_forge_l1_txs_num, tx.position, tx.user_origin,
tx.from_idx, tx.from_eth_addr, tx.from_bjj, tx.to_idx, tx.token_id, tx.from_idx, tx.from_eth_addr, tx.from_bjj, tx.to_idx, tx.token_id,
tx.amount, NULL AS effective_amount, tx.amount, NULL AS effective_amount,
tx.load_amount, NULL AS effective_load_amount,
tx.deposit_amount, NULL AS effective_deposit_amount,
tx.eth_block_num, tx.type, tx.batch_num tx.eth_block_num, tx.type, tx.batch_num
FROM tx WHERE batch_num IS NULL AND to_forge_l1_txs_num = $1;`, FROM tx WHERE batch_num IS NULL AND to_forge_l1_txs_num = $1;`,
toForgeL1TxsNum, toForgeL1TxsNum,
@ -1298,16 +1298,16 @@ func (hdb *HistoryDB) SetInitialSCVars(rollup *common.RollupVariables,
return tracerr.Wrap(txn.Commit()) return tracerr.Wrap(txn.Commit())
} }
// setL1UserTxEffectiveAmounts sets the EffectiveAmount and EffectiveLoadAmount
// setL1UserTxEffectiveAmounts sets the EffectiveAmount and EffectiveDepositAmount
// of the given l1UserTxs (with an UPDATE) // of the given l1UserTxs (with an UPDATE)
func (hdb *HistoryDB) setL1UserTxEffectiveAmounts(d sqlx.Ext, txs []common.L1Tx) error { func (hdb *HistoryDB) setL1UserTxEffectiveAmounts(d sqlx.Ext, txs []common.L1Tx) error {
// Effective amounts are stored as success flags in the DB, with true value by default // Effective amounts are stored as success flags in the DB, with true value by default
// to reduce the amount of updates. Therefore, only amounts that became uneffective should be // to reduce the amount of updates. Therefore, only amounts that became uneffective should be
// updated to become false // updated to become false
type txUpdate struct { type txUpdate struct {
ID common.TxID `db:"id"`
AmountSuccess bool `db:"amount_success"`
LoadAmountSuccess bool `db:"load_amount_success"`
ID common.TxID `db:"id"`
AmountSuccess bool `db:"amount_success"`
DepositAmountSuccess bool `db:"deposit_amount_success"`
} }
txUpdates := []txUpdate{} txUpdates := []txUpdate{}
equal := func(a *big.Int, b *big.Int) bool { equal := func(a *big.Int, b *big.Int) bool {
@ -1315,23 +1315,23 @@ func (hdb *HistoryDB) setL1UserTxEffectiveAmounts(d sqlx.Ext, txs []common.L1Tx)
} }
for i := range txs { for i := range txs {
amountSuccess := equal(txs[i].Amount, txs[i].EffectiveAmount) amountSuccess := equal(txs[i].Amount, txs[i].EffectiveAmount)
loadAmountSuccess := equal(txs[i].LoadAmount, txs[i].EffectiveLoadAmount)
if !amountSuccess || !loadAmountSuccess {
depositAmountSuccess := equal(txs[i].DepositAmount, txs[i].EffectiveDepositAmount)
if !amountSuccess || !depositAmountSuccess {
txUpdates = append(txUpdates, txUpdate{ txUpdates = append(txUpdates, txUpdate{
ID: txs[i].TxID,
AmountSuccess: amountSuccess,
LoadAmountSuccess: loadAmountSuccess,
ID: txs[i].TxID,
AmountSuccess: amountSuccess,
DepositAmountSuccess: depositAmountSuccess,
}) })
} }
} }
const query string = ` const query string = `
UPDATE tx SET UPDATE tx SET
amount_success = tx_update.amount_success, amount_success = tx_update.amount_success,
load_amount_success = tx_update.load_amount_success
deposit_amount_success = tx_update.deposit_amount_success
FROM (VALUES FROM (VALUES
(NULL::::BYTEA, NULL::::BOOL, NULL::::BOOL), (NULL::::BYTEA, NULL::::BOOL, NULL::::BOOL),
(:id, :amount_success, :load_amount_success)
) as tx_update (id, amount_success, load_amount_success)
(:id, :amount_success, :deposit_amount_success)
) as tx_update (id, amount_success, deposit_amount_success)
WHERE tx.id = tx_update.id WHERE tx.id = tx_update.id
` `
if len(txUpdates) > 0 { if len(txUpdates) > 0 {
@ -1414,7 +1414,7 @@ func (hdb *HistoryDB) AddBlockSCData(blockData *common.BlockData) (err error) {
for i := range blockData.Rollup.Batches { for i := range blockData.Rollup.Batches {
batch := &blockData.Rollup.Batches[i] batch := &blockData.Rollup.Batches[i]
// Set the EffectiveAmount and EffectiveLoadAmount of all the
// Set the EffectiveAmount and EffectiveDepositAmount of all the
// L1UserTxs that have been forged in this batch // L1UserTxs that have been forged in this batch
if len(batch.L1UserTxs) > 0 { if len(batch.L1UserTxs) > 0 {
if err = hdb.setL1UserTxEffectiveAmounts(txn, batch.L1UserTxs); err != nil { if err = hdb.setL1UserTxEffectiveAmounts(txn, batch.L1UserTxs); err != nil {

+ 17
- 17
db/historydb/historydb_test.go

@ -517,16 +517,16 @@ func TestTxs(t *testing.T) {
assert.Equal(t, true, dbL1Txs[9].UserOrigin) assert.Equal(t, true, dbL1Txs[9].UserOrigin)
// Load Amount // Load Amount
assert.Equal(t, big.NewInt(10), dbL1Txs[0].LoadAmount)
assert.Equal(t, big.NewInt(10), dbL1Txs[1].LoadAmount)
assert.Equal(t, big.NewInt(20), dbL1Txs[2].LoadAmount)
assert.Equal(t, big.NewInt(10), dbL1Txs[3].LoadAmount)
assert.Equal(t, big.NewInt(10), dbL1Txs[4].LoadAmount)
assert.Equal(t, big.NewInt(10), dbL1Txs[5].LoadAmount)
assert.Equal(t, big.NewInt(0), dbL1Txs[6].LoadAmount)
assert.Equal(t, big.NewInt(0), dbL1Txs[7].LoadAmount)
assert.Equal(t, big.NewInt(10), dbL1Txs[8].LoadAmount)
assert.Equal(t, big.NewInt(10), dbL1Txs[9].LoadAmount)
assert.Equal(t, big.NewInt(10), dbL1Txs[0].DepositAmount)
assert.Equal(t, big.NewInt(10), dbL1Txs[1].DepositAmount)
assert.Equal(t, big.NewInt(20), dbL1Txs[2].DepositAmount)
assert.Equal(t, big.NewInt(10), dbL1Txs[3].DepositAmount)
assert.Equal(t, big.NewInt(10), dbL1Txs[4].DepositAmount)
assert.Equal(t, big.NewInt(10), dbL1Txs[5].DepositAmount)
assert.Equal(t, big.NewInt(0), dbL1Txs[6].DepositAmount)
assert.Equal(t, big.NewInt(0), dbL1Txs[7].DepositAmount)
assert.Equal(t, big.NewInt(10), dbL1Txs[8].DepositAmount)
assert.Equal(t, big.NewInt(10), dbL1Txs[9].DepositAmount)
// Check saved txID's batch_num is not nil // Check saved txID's batch_num is not nil
assert.Equal(t, txID, dbL1Txs[len(dbL1Txs)-2].TxID) assert.Equal(t, txID, dbL1Txs[len(dbL1Txs)-2].TxID)
@ -736,12 +736,12 @@ func TestSetL1UserTxEffectiveAmounts(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
require.Nil(t, err) require.Nil(t, err)
// Set the Effective{Amount,LoadAmount} of the L1UserTxs that are forged in the second block
// Set the Effective{Amount,DepositAmount} of the L1UserTxs that are forged in the second block
l1Txs := blocks[1].Rollup.Batches[0].L1UserTxs l1Txs := blocks[1].Rollup.Batches[0].L1UserTxs
require.Equal(t, 3, len(l1Txs)) require.Equal(t, 3, len(l1Txs))
// Change some values to test all cases // Change some values to test all cases
l1Txs[1].EffectiveAmount = big.NewInt(0) l1Txs[1].EffectiveAmount = big.NewInt(0)
l1Txs[2].EffectiveLoadAmount = big.NewInt(0)
l1Txs[2].EffectiveDepositAmount = big.NewInt(0)
l1Txs[2].EffectiveAmount = big.NewInt(0) l1Txs[2].EffectiveAmount = big.NewInt(0)
err = historyDB.setL1UserTxEffectiveAmounts(historyDB.db, l1Txs) err = historyDB.setL1UserTxEffectiveAmounts(historyDB.db, l1Txs)
require.NoError(t, err) require.NoError(t, err)
@ -749,18 +749,18 @@ func TestSetL1UserTxEffectiveAmounts(t *testing.T) {
dbL1Txs, err := historyDB.GetAllL1UserTxs() dbL1Txs, err := historyDB.GetAllL1UserTxs()
require.NoError(t, err) require.NoError(t, err)
for i, tx := range dbL1Txs { for i, tx := range dbL1Txs {
log.Infof("%d %v %v", i, tx.EffectiveAmount, tx.EffectiveLoadAmount)
log.Infof("%d %v %v", i, tx.EffectiveAmount, tx.EffectiveDepositAmount)
assert.NotNil(t, tx.EffectiveAmount) assert.NotNil(t, tx.EffectiveAmount)
assert.NotNil(t, tx.EffectiveLoadAmount)
assert.NotNil(t, tx.EffectiveDepositAmount)
switch tx.TxID { switch tx.TxID {
case l1Txs[0].TxID: case l1Txs[0].TxID:
assert.Equal(t, l1Txs[0].LoadAmount, tx.EffectiveLoadAmount)
assert.Equal(t, l1Txs[0].DepositAmount, tx.EffectiveDepositAmount)
assert.Equal(t, l1Txs[0].Amount, tx.EffectiveAmount) assert.Equal(t, l1Txs[0].Amount, tx.EffectiveAmount)
case l1Txs[1].TxID: case l1Txs[1].TxID:
assert.Equal(t, l1Txs[1].LoadAmount, tx.EffectiveLoadAmount)
assert.Equal(t, l1Txs[1].DepositAmount, tx.EffectiveDepositAmount)
assert.Equal(t, big.NewInt(0), tx.EffectiveAmount) assert.Equal(t, big.NewInt(0), tx.EffectiveAmount)
case l1Txs[2].TxID: case l1Txs[2].TxID:
assert.Equal(t, big.NewInt(0), tx.EffectiveLoadAmount)
assert.Equal(t, big.NewInt(0), tx.EffectiveDepositAmount)
assert.Equal(t, big.NewInt(0), tx.EffectiveAmount) assert.Equal(t, big.NewInt(0), tx.EffectiveAmount)
} }
} }

+ 12
- 12
db/historydb/views.go

@ -32,10 +32,10 @@ type TxAPI struct {
BatchNum *common.BatchNum `meddler:"batch_num"` // batchNum in which this tx was forged. If the tx is L2, this must be != 0 BatchNum *common.BatchNum `meddler:"batch_num"` // batchNum in which this tx was forged. If the tx is L2, this must be != 0
EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue
// L1 // L1
ToForgeL1TxsNum *int64 `meddler:"to_forge_l1_txs_num"` // toForgeL1TxsNum in which the tx was forged / will be forged
UserOrigin *bool `meddler:"user_origin"` // true if the tx was originated by a user, false if it was aoriginated by a coordinator. Note that this differ from the spec for implementation simplification purpposes
LoadAmount *apitypes.BigIntStr `meddler:"load_amount"`
HistoricLoadAmountUSD *float64 `meddler:"load_amount_usd"`
ToForgeL1TxsNum *int64 `meddler:"to_forge_l1_txs_num"` // toForgeL1TxsNum in which the tx was forged / will be forged
UserOrigin *bool `meddler:"user_origin"` // true if the tx was originated by a user, false if it was aoriginated by a coordinator. Note that this differ from the spec for implementation simplification purpposes
DepositAmount *apitypes.BigIntStr `meddler:"deposit_amount"`
HistoricDepositAmountUSD *float64 `meddler:"deposit_amount_usd"`
// L2 // L2
Fee *common.FeeSelector `meddler:"fee"` Fee *common.FeeSelector `meddler:"fee"`
HistoricFeeUSD *float64 `meddler:"fee_usd"` HistoricFeeUSD *float64 `meddler:"fee_usd"`
@ -93,8 +93,8 @@ func (tx TxAPI) MarshalJSON() ([]byte, error) {
jsonTx["L1Info"] = map[string]interface{}{ jsonTx["L1Info"] = map[string]interface{}{
"toForgeL1TransactionsNum": tx.ToForgeL1TxsNum, "toForgeL1TransactionsNum": tx.ToForgeL1TxsNum,
"userOrigin": tx.UserOrigin, "userOrigin": tx.UserOrigin,
"loadAmount": tx.LoadAmount,
"historicLoadAmountUSD": tx.HistoricLoadAmountUSD,
"depositAmount": tx.DepositAmount,
"historicDepositAmountUSD": tx.HistoricDepositAmountUSD,
"ethereumBlockNum": tx.EthBlockNum, "ethereumBlockNum": tx.EthBlockNum,
} }
} else { } else {
@ -125,12 +125,12 @@ type txWrite struct {
BatchNum *common.BatchNum `meddler:"batch_num"` // batchNum in which this tx was forged. If the tx is L2, this must be != 0 BatchNum *common.BatchNum `meddler:"batch_num"` // batchNum in which this tx was forged. If the tx is L2, this must be != 0
EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue
// L1 // L1
ToForgeL1TxsNum *int64 `meddler:"to_forge_l1_txs_num"` // toForgeL1TxsNum in which the tx was forged / will be forged
UserOrigin *bool `meddler:"user_origin"` // true if the tx was originated by a user, false if it was aoriginated by a coordinator. Note that this differ from the spec for implementation simplification purpposes
FromEthAddr *ethCommon.Address `meddler:"from_eth_addr"`
FromBJJ *babyjub.PublicKey `meddler:"from_bjj"`
LoadAmount *big.Int `meddler:"load_amount,bigintnull"`
LoadAmountFloat *float64 `meddler:"load_amount_f"`
ToForgeL1TxsNum *int64 `meddler:"to_forge_l1_txs_num"` // toForgeL1TxsNum in which the tx was forged / will be forged
UserOrigin *bool `meddler:"user_origin"` // true if the tx was originated by a user, false if it was aoriginated by a coordinator. Note that this differ from the spec for implementation simplification purpposes
FromEthAddr *ethCommon.Address `meddler:"from_eth_addr"`
FromBJJ *babyjub.PublicKey `meddler:"from_bjj"`
DepositAmount *big.Int `meddler:"deposit_amount,bigintnull"`
DepositAmountFloat *float64 `meddler:"deposit_amount_f"`
// L2 // L2
Fee *common.FeeSelector `meddler:"fee"` Fee *common.FeeSelector `meddler:"fee"`
Nonce *common.Nonce `meddler:"nonce"` Nonce *common.Nonce `meddler:"nonce"`

+ 12
- 12
db/migrations/0001.sql

@ -135,14 +135,14 @@ FOR EACH ROW EXECUTE PROCEDURE set_token_usd_update();
CREATE SEQUENCE tx_item_id; CREATE SEQUENCE tx_item_id;
-- important note about "amount_success" and "load_amount_success" (only relevant to L1 user txs):
-- important note about "amount_success" and "deposit_amount_success" (only relevant to L1 user txs):
-- The behaviour should be: -- The behaviour should be:
-- When tx is not forged: amount_success = false, load_amount_success = false
-- When tx is not forged: amount_success = false, deposit_amount_success = false
-- When tx is forged: -- When tx is forged:
-- amount_success = false if the "effective amount" is 0, else true -- amount_success = false if the "effective amount" is 0, else true
-- load_amount_success = false if the "effective load amount" is 0, else true
-- deposit_amount_success = false if the "effective load amount" is 0, else true
-- --
-- However, in order to reduce the amount of updates, by default amount_success and load_amount_success will be set to true (when tx is unforged)
-- However, in order to reduce the amount of updates, by default amount_success and deposit_amount_success will be set to true (when tx is unforged)
-- whne they should be false. This can be worked around at a query level by checking if "batch_num IS NULL" (which indicates that the tx is unforged). -- whne they should be false. This can be worked around at a query level by checking if "batch_num IS NULL" (which indicates that the tx is unforged).
CREATE TABLE tx ( CREATE TABLE tx (
-- Generic TX -- Generic TX
@ -167,10 +167,10 @@ CREATE TABLE tx (
-- L1 -- L1
to_forge_l1_txs_num BIGINT, to_forge_l1_txs_num BIGINT,
user_origin BOOLEAN, user_origin BOOLEAN,
load_amount BYTEA,
load_amount_success BOOLEAN NOT NULL DEFAULT true,
load_amount_f NUMERIC,
load_amount_usd NUMERIC,
deposit_amount BYTEA,
deposit_amount_success BOOLEAN NOT NULL DEFAULT true,
deposit_amount_f NUMERIC,
deposit_amount_usd NUMERIC,
-- L2 -- L2
fee INT, fee INT,
fee_usd NUMERIC, fee_usd NUMERIC,
@ -463,8 +463,8 @@ BEGIN
IF NEW.user_origin IS NULL OR IF NEW.user_origin IS NULL OR
NEW.from_eth_addr IS NULL OR NEW.from_eth_addr IS NULL OR
NEW.from_bjj IS NULL OR NEW.from_bjj IS NULL OR
NEW.load_amount IS NULL OR
NEW.load_amount_f IS NULL OR
NEW.deposit_amount IS NULL OR
NEW.deposit_amount_f IS NULL OR
(NOT NEW.user_origin AND NEW.batch_num IS NULL) THEN -- If is Coordinator L1, must include batch_num (NOT NEW.user_origin AND NEW.batch_num IS NULL) THEN -- If is Coordinator L1, must include batch_num
RAISE EXCEPTION 'Invalid L1 tx: %', NEW; RAISE EXCEPTION 'Invalid L1 tx: %', NEW;
END IF; END IF;
@ -493,8 +493,8 @@ BEGIN
NEW."fee_usd" = (SELECT NEW."amount_usd" * fee_percentage(NEW.fee::NUMERIC)); NEW."fee_usd" = (SELECT NEW."amount_usd" * fee_percentage(NEW.fee::NUMERIC));
END IF; END IF;
END IF; END IF;
IF NEW."is_l1" AND NEW."load_amount_f" > 0.0 THEN
NEW."load_amount_usd" = (SELECT _value * NEW.load_amount_f);
IF NEW."is_l1" AND NEW."deposit_amount_f" > 0.0 THEN
NEW."deposit_amount_usd" = (SELECT _value * NEW.deposit_amount_f);
END IF; END IF;
END IF; END IF;
END IF; END IF;

+ 24
- 24
db/statedb/txprocessors.go

@ -455,11 +455,11 @@ func (s *StateDB) processL1Tx(exitTree *merkletree.MerkleTree, tx *common.L1Tx)
s.zki.OnChain[s.i] = big.NewInt(1) s.zki.OnChain[s.i] = big.NewInt(1)
// L1Txs // L1Txs
loadAmountF16, err := common.NewFloat16(tx.LoadAmount)
depositAmountF16, err := common.NewFloat16(tx.DepositAmount)
if err != nil { if err != nil {
return nil, nil, false, nil, tracerr.Wrap(err) return nil, nil, false, nil, tracerr.Wrap(err)
} }
s.zki.LoadAmountF[s.i] = big.NewInt(int64(loadAmountF16))
s.zki.DepositAmountF[s.i] = big.NewInt(int64(depositAmountF16))
s.zki.FromEthAddr[s.i] = common.EthAddrToBigInt(tx.FromEthAddr) s.zki.FromEthAddr[s.i] = common.EthAddrToBigInt(tx.FromEthAddr)
if tx.FromBJJ != nil { if tx.FromBJJ != nil {
s.zki.FromBJJCompressed[s.i] = BJJCompressedTo256BigInts(tx.FromBJJ.Compress()) s.zki.FromBJJCompressed[s.i] = BJJCompressedTo256BigInts(tx.FromBJJ.Compress())
@ -660,7 +660,7 @@ func (s *StateDB) applyCreateAccount(tx *common.L1Tx) error {
account := &common.Account{ account := &common.Account{
TokenID: tx.TokenID, TokenID: tx.TokenID,
Nonce: 0, Nonce: 0,
Balance: tx.EffectiveLoadAmount,
Balance: tx.EffectiveDepositAmount,
PublicKey: tx.FromBJJ, PublicKey: tx.FromBJJ,
EthAddr: tx.FromEthAddr, EthAddr: tx.FromEthAddr,
} }
@ -676,7 +676,7 @@ func (s *StateDB) applyCreateAccount(tx *common.L1Tx) error {
s.zki.Sign1[s.i] = big.NewInt(1) s.zki.Sign1[s.i] = big.NewInt(1)
} }
s.zki.Ay1[s.i] = tx.FromBJJ.Y s.zki.Ay1[s.i] = tx.FromBJJ.Y
s.zki.Balance1[s.i] = tx.EffectiveLoadAmount
s.zki.Balance1[s.i] = tx.EffectiveDepositAmount
s.zki.EthAddr1[s.i] = common.EthAddrToBigInt(tx.FromEthAddr) s.zki.EthAddr1[s.i] = common.EthAddrToBigInt(tx.FromEthAddr)
s.zki.Siblings1[s.i] = siblingsToZKInputFormat(p.Siblings) s.zki.Siblings1[s.i] = siblingsToZKInputFormat(p.Siblings)
if p.IsOld0 { if p.IsOld0 {
@ -704,12 +704,12 @@ func (s *StateDB) applyCreateAccount(tx *common.L1Tx) error {
// andTransfer parameter is set to true, the method will also apply the // andTransfer parameter is set to true, the method will also apply the
// Transfer of the L1Tx/DepositTransfer // Transfer of the L1Tx/DepositTransfer
func (s *StateDB) applyDeposit(tx *common.L1Tx, transfer bool) error { func (s *StateDB) applyDeposit(tx *common.L1Tx, transfer bool) error {
// deposit the tx.EffectiveLoadAmount into the sender account
// deposit the tx.EffectiveDepositAmount into the sender account
accSender, err := s.GetAccount(tx.FromIdx) accSender, err := s.GetAccount(tx.FromIdx)
if err != nil { if err != nil {
return tracerr.Wrap(err) return tracerr.Wrap(err)
} }
accSender.Balance = new(big.Int).Add(accSender.Balance, tx.EffectiveLoadAmount)
accSender.Balance = new(big.Int).Add(accSender.Balance, tx.EffectiveDepositAmount)
// in case that the tx is a L1Tx>DepositTransfer // in case that the tx is a L1Tx>DepositTransfer
var accReceiver *common.Account var accReceiver *common.Account
@ -883,7 +883,7 @@ func (s *StateDB) applyCreateAccountDepositTransfer(tx *common.L1Tx) error {
accSender := &common.Account{ accSender := &common.Account{
TokenID: tx.TokenID, TokenID: tx.TokenID,
Nonce: 0, Nonce: 0,
Balance: tx.EffectiveLoadAmount,
Balance: tx.EffectiveDepositAmount,
PublicKey: tx.FromBJJ, PublicKey: tx.FromBJJ,
EthAddr: tx.FromEthAddr, EthAddr: tx.FromEthAddr,
} }
@ -908,7 +908,7 @@ func (s *StateDB) applyCreateAccountDepositTransfer(tx *common.L1Tx) error {
s.zki.Sign1[s.i] = big.NewInt(1) s.zki.Sign1[s.i] = big.NewInt(1)
} }
s.zki.Ay1[s.i] = tx.FromBJJ.Y s.zki.Ay1[s.i] = tx.FromBJJ.Y
s.zki.Balance1[s.i] = tx.EffectiveLoadAmount
s.zki.Balance1[s.i] = tx.EffectiveDepositAmount
s.zki.EthAddr1[s.i] = common.EthAddrToBigInt(tx.FromEthAddr) s.zki.EthAddr1[s.i] = common.EthAddrToBigInt(tx.FromEthAddr)
s.zki.Siblings1[s.i] = siblingsToZKInputFormat(p.Siblings) s.zki.Siblings1[s.i] = siblingsToZKInputFormat(p.Siblings)
if p.IsOld0 { if p.IsOld0 {
@ -1039,20 +1039,20 @@ func (s *StateDB) computeEffectiveAmounts(tx *common.L1Tx) {
if !tx.UserOrigin { if !tx.UserOrigin {
// case where the L1Tx is generated by the Coordinator // case where the L1Tx is generated by the Coordinator
tx.EffectiveAmount = big.NewInt(0) tx.EffectiveAmount = big.NewInt(0)
tx.EffectiveLoadAmount = big.NewInt(0)
tx.EffectiveDepositAmount = big.NewInt(0)
return return
} }
tx.EffectiveAmount = tx.Amount tx.EffectiveAmount = tx.Amount
tx.EffectiveLoadAmount = tx.LoadAmount
tx.EffectiveDepositAmount = tx.DepositAmount
if tx.Type == common.TxTypeCreateAccountDeposit { if tx.Type == common.TxTypeCreateAccountDeposit {
return return
} }
if tx.ToIdx >= common.UserThreshold && tx.FromIdx == common.Idx(0) { if tx.ToIdx >= common.UserThreshold && tx.FromIdx == common.Idx(0) {
// CreateAccountDepositTransfer case // CreateAccountDepositTransfer case
cmp := tx.LoadAmount.Cmp(tx.Amount)
if cmp == -1 { // LoadAmount<Amount
cmp := tx.DepositAmount.Cmp(tx.Amount)
if cmp == -1 { // DepositAmount<Amount
tx.EffectiveAmount = big.NewInt(0) tx.EffectiveAmount = big.NewInt(0)
return return
} }
@ -1061,24 +1061,24 @@ func (s *StateDB) computeEffectiveAmounts(tx *common.L1Tx) {
accSender, err := s.GetAccount(tx.FromIdx) accSender, err := s.GetAccount(tx.FromIdx)
if err != nil { if err != nil {
log.Debugf("EffectiveAmount & EffectiveLoadAmount = 0: can not get account for tx.FromIdx: %d", tx.FromIdx)
tx.EffectiveLoadAmount = big.NewInt(0)
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: can not get account for tx.FromIdx: %d", tx.FromIdx)
tx.EffectiveDepositAmount = big.NewInt(0)
tx.EffectiveAmount = big.NewInt(0) tx.EffectiveAmount = big.NewInt(0)
return return
} }
// check that tx.TokenID corresponds to the Sender account TokenID // check that tx.TokenID corresponds to the Sender account TokenID
if tx.TokenID != accSender.TokenID { if tx.TokenID != accSender.TokenID {
log.Debugf("EffectiveAmount & EffectiveLoadAmount = 0: tx.TokenID (%d) !=sender account TokenID (%d)", tx.TokenID, accSender.TokenID)
tx.EffectiveLoadAmount = big.NewInt(0)
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: tx.TokenID (%d) !=sender account TokenID (%d)", tx.TokenID, accSender.TokenID)
tx.EffectiveDepositAmount = big.NewInt(0)
tx.EffectiveAmount = big.NewInt(0) tx.EffectiveAmount = big.NewInt(0)
return return
} }
// check that Sender has enough balance // check that Sender has enough balance
bal := accSender.Balance bal := accSender.Balance
if tx.LoadAmount != nil {
bal = new(big.Int).Add(bal, tx.EffectiveLoadAmount)
if tx.DepositAmount != nil {
bal = new(big.Int).Add(bal, tx.EffectiveDepositAmount)
} }
cmp := bal.Cmp(tx.Amount) cmp := bal.Cmp(tx.Amount)
if cmp == -1 { if cmp == -1 {
@ -1090,8 +1090,8 @@ func (s *StateDB) computeEffectiveAmounts(tx *common.L1Tx) {
// check that the tx.FromEthAddr is the same than the EthAddress of the // check that the tx.FromEthAddr is the same than the EthAddress of the
// Sender // Sender
if !bytes.Equal(tx.FromEthAddr.Bytes(), accSender.EthAddr.Bytes()) { if !bytes.Equal(tx.FromEthAddr.Bytes(), accSender.EthAddr.Bytes()) {
log.Debugf("EffectiveAmount & EffectiveLoadAmount = 0: tx.FromEthAddr (%s) must be the same EthAddr of the sender account by the Idx (%s)", tx.FromEthAddr.Hex(), accSender.EthAddr.Hex())
tx.EffectiveLoadAmount = big.NewInt(0)
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: tx.FromEthAddr (%s) must be the same EthAddr of the sender account by the Idx (%s)", tx.FromEthAddr.Hex(), accSender.EthAddr.Hex())
tx.EffectiveDepositAmount = big.NewInt(0)
tx.EffectiveAmount = big.NewInt(0) tx.EffectiveAmount = big.NewInt(0)
return return
} }
@ -1104,14 +1104,14 @@ func (s *StateDB) computeEffectiveAmounts(tx *common.L1Tx) {
// check that TokenID is the same for Sender & Receiver account // check that TokenID is the same for Sender & Receiver account
accReceiver, err := s.GetAccount(tx.ToIdx) accReceiver, err := s.GetAccount(tx.ToIdx)
if err != nil { if err != nil {
log.Debugf("EffectiveAmount & EffectiveLoadAmount = 0: can not get account for tx.ToIdx: %d", tx.ToIdx)
tx.EffectiveLoadAmount = big.NewInt(0)
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: can not get account for tx.ToIdx: %d", tx.ToIdx)
tx.EffectiveDepositAmount = big.NewInt(0)
tx.EffectiveAmount = big.NewInt(0) tx.EffectiveAmount = big.NewInt(0)
return return
} }
if accSender.TokenID != accReceiver.TokenID { if accSender.TokenID != accReceiver.TokenID {
log.Debugf("EffectiveAmount & EffectiveLoadAmount = 0: sender account TokenID (%d) != receiver account TokenID (%d)", tx.TokenID, accSender.TokenID)
tx.EffectiveLoadAmount = big.NewInt(0)
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: sender account TokenID (%d) != receiver account TokenID (%d)", tx.TokenID, accSender.TokenID)
tx.EffectiveDepositAmount = big.NewInt(0)
tx.EffectiveAmount = big.NewInt(0) tx.EffectiveAmount = big.NewInt(0)
return return
} }

+ 85
- 85
db/statedb/txprocessors_test.go

@ -58,80 +58,80 @@ func TestCheckL1TxInvalidData(t *testing.T) {
require.Nil(t, err) require.Nil(t, err)
tx := common.L1Tx{ tx := common.L1Tx{
FromIdx: 256,
ToIdx: 257,
Amount: big.NewInt(10),
LoadAmount: big.NewInt(0),
FromEthAddr: tc.Users["A"].Addr,
UserOrigin: true,
FromIdx: 256,
ToIdx: 257,
Amount: big.NewInt(10),
DepositAmount: big.NewInt(0),
FromEthAddr: tc.Users["A"].Addr,
UserOrigin: true,
} }
sdb.computeEffectiveAmounts(&tx) sdb.computeEffectiveAmounts(&tx)
assert.Equal(t, big.NewInt(0), tx.EffectiveLoadAmount)
assert.Equal(t, big.NewInt(0), tx.EffectiveDepositAmount)
assert.Equal(t, big.NewInt(10), tx.EffectiveAmount) assert.Equal(t, big.NewInt(10), tx.EffectiveAmount)
// expect error due not enough funds // expect error due not enough funds
tx = common.L1Tx{ tx = common.L1Tx{
FromIdx: 256,
ToIdx: 257,
Amount: big.NewInt(11),
LoadAmount: big.NewInt(0),
FromEthAddr: tc.Users["A"].Addr,
UserOrigin: true,
FromIdx: 256,
ToIdx: 257,
Amount: big.NewInt(11),
DepositAmount: big.NewInt(0),
FromEthAddr: tc.Users["A"].Addr,
UserOrigin: true,
} }
sdb.computeEffectiveAmounts(&tx) sdb.computeEffectiveAmounts(&tx)
assert.Equal(t, big.NewInt(0), tx.EffectiveLoadAmount)
assert.Equal(t, big.NewInt(0), tx.EffectiveDepositAmount)
assert.Equal(t, big.NewInt(0), tx.EffectiveAmount) assert.Equal(t, big.NewInt(0), tx.EffectiveAmount)
// expect no-error due not enough funds in a // expect no-error due not enough funds in a
// CreateAccountDepositTransfer transction // CreateAccountDepositTransfer transction
tx = common.L1Tx{ tx = common.L1Tx{
FromIdx: 0,
ToIdx: 257,
Amount: big.NewInt(10),
LoadAmount: big.NewInt(10),
UserOrigin: true,
FromIdx: 0,
ToIdx: 257,
Amount: big.NewInt(10),
DepositAmount: big.NewInt(10),
UserOrigin: true,
} }
sdb.computeEffectiveAmounts(&tx) sdb.computeEffectiveAmounts(&tx)
assert.Equal(t, big.NewInt(10), tx.EffectiveLoadAmount)
assert.Equal(t, big.NewInt(10), tx.EffectiveDepositAmount)
assert.Equal(t, big.NewInt(10), tx.EffectiveAmount) assert.Equal(t, big.NewInt(10), tx.EffectiveAmount)
// expect error due not enough funds in a CreateAccountDepositTransfer // expect error due not enough funds in a CreateAccountDepositTransfer
// transction // transction
tx = common.L1Tx{ tx = common.L1Tx{
FromIdx: 0,
ToIdx: 257,
Amount: big.NewInt(11),
LoadAmount: big.NewInt(10),
UserOrigin: true,
FromIdx: 0,
ToIdx: 257,
Amount: big.NewInt(11),
DepositAmount: big.NewInt(10),
UserOrigin: true,
} }
sdb.computeEffectiveAmounts(&tx) sdb.computeEffectiveAmounts(&tx)
assert.Equal(t, big.NewInt(10), tx.EffectiveLoadAmount)
assert.Equal(t, big.NewInt(10), tx.EffectiveDepositAmount)
assert.Equal(t, big.NewInt(0), tx.EffectiveAmount) assert.Equal(t, big.NewInt(0), tx.EffectiveAmount)
// expect error due not same TokenID // expect error due not same TokenID
tx = common.L1Tx{ tx = common.L1Tx{
FromIdx: 256,
ToIdx: 258,
Amount: big.NewInt(5),
LoadAmount: big.NewInt(0),
FromEthAddr: tc.Users["A"].Addr,
UserOrigin: true,
FromIdx: 256,
ToIdx: 258,
Amount: big.NewInt(5),
DepositAmount: big.NewInt(0),
FromEthAddr: tc.Users["A"].Addr,
UserOrigin: true,
} }
sdb.computeEffectiveAmounts(&tx) sdb.computeEffectiveAmounts(&tx)
assert.Equal(t, big.NewInt(0), tx.EffectiveLoadAmount)
assert.Equal(t, big.NewInt(0), tx.EffectiveDepositAmount)
assert.Equal(t, big.NewInt(0), tx.EffectiveAmount) assert.Equal(t, big.NewInt(0), tx.EffectiveAmount)
// expect error due not same EthAddr // expect error due not same EthAddr
tx = common.L1Tx{ tx = common.L1Tx{
FromIdx: 256,
ToIdx: 257,
Amount: big.NewInt(8),
LoadAmount: big.NewInt(0),
FromEthAddr: tc.Users["B"].Addr,
UserOrigin: true,
FromIdx: 256,
ToIdx: 257,
Amount: big.NewInt(8),
DepositAmount: big.NewInt(0),
FromEthAddr: tc.Users["B"].Addr,
UserOrigin: true,
} }
sdb.computeEffectiveAmounts(&tx) sdb.computeEffectiveAmounts(&tx)
assert.Equal(t, big.NewInt(0), tx.EffectiveLoadAmount)
assert.Equal(t, big.NewInt(0), tx.EffectiveDepositAmount)
assert.Equal(t, big.NewInt(0), tx.EffectiveAmount) assert.Equal(t, big.NewInt(0), tx.EffectiveAmount)
} }
@ -555,15 +555,15 @@ func TestProcessTxsRootTestVectors(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
l1Txs := []common.L1Tx{ l1Txs := []common.L1Tx{
{ {
FromIdx: 0,
LoadAmount: big.NewInt(16000000),
Amount: big.NewInt(0),
TokenID: 1,
FromBJJ: bjj0,
FromEthAddr: ethCommon.HexToAddress("0x7e5f4552091a69125d5dfcb7b8c2659029395bdf"),
ToIdx: 0,
Type: common.TxTypeCreateAccountDeposit,
UserOrigin: true,
FromIdx: 0,
DepositAmount: big.NewInt(16000000),
Amount: big.NewInt(0),
TokenID: 1,
FromBJJ: bjj0,
FromEthAddr: ethCommon.HexToAddress("0x7e5f4552091a69125d5dfcb7b8c2659029395bdf"),
ToIdx: 0,
Type: common.TxTypeCreateAccountDeposit,
UserOrigin: true,
}, },
} }
l2Txs := []common.PoolL2Tx{ l2Txs := []common.PoolL2Tx{
@ -611,15 +611,15 @@ func TestCircomTest(t *testing.T) {
l1Txs := []common.L1Tx{ l1Txs := []common.L1Tx{
{ {
FromIdx: 0,
LoadAmount: big.NewInt(16000000),
Amount: big.NewInt(0),
TokenID: 1,
FromBJJ: bjj0,
FromEthAddr: ethCommon.HexToAddress("0x7e5f4552091a69125d5dfcb7b8c2659029395bdf"),
ToIdx: 0,
Type: common.TxTypeCreateAccountDeposit,
UserOrigin: true,
FromIdx: 0,
DepositAmount: big.NewInt(16000000),
Amount: big.NewInt(0),
TokenID: 1,
FromBJJ: bjj0,
FromEthAddr: ethCommon.HexToAddress("0x7e5f4552091a69125d5dfcb7b8c2659029395bdf"),
ToIdx: 0,
Type: common.TxTypeCreateAccountDeposit,
UserOrigin: true,
}, },
} }
l2Txs := []common.PoolL2Tx{ l2Txs := []common.PoolL2Tx{
@ -700,15 +700,15 @@ func TestZKInputsHashTestVector0(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
l1Txs := []common.L1Tx{ l1Txs := []common.L1Tx{
{ {
FromIdx: 0,
LoadAmount: big.NewInt(16000000),
Amount: big.NewInt(0),
TokenID: 1,
FromBJJ: bjj0,
FromEthAddr: ethCommon.HexToAddress("0x7e5f4552091a69125d5dfcb7b8c2659029395bdf"),
ToIdx: 0,
Type: common.TxTypeCreateAccountDeposit,
UserOrigin: true,
FromIdx: 0,
DepositAmount: big.NewInt(16000000),
Amount: big.NewInt(0),
TokenID: 1,
FromBJJ: bjj0,
FromEthAddr: ethCommon.HexToAddress("0x7e5f4552091a69125d5dfcb7b8c2659029395bdf"),
ToIdx: 0,
Type: common.TxTypeCreateAccountDeposit,
UserOrigin: true,
}, },
} }
l2Txs := []common.PoolL2Tx{ l2Txs := []common.PoolL2Tx{
@ -778,26 +778,26 @@ func TestZKInputsHashTestVector1(t *testing.T) {
l1Txs := []common.L1Tx{ l1Txs := []common.L1Tx{
{ {
FromIdx: 0, FromIdx: 0,
// LoadAmount: big.NewInt(10400),
LoadAmount: big.NewInt(16000000),
Amount: big.NewInt(0),
TokenID: 1,
FromBJJ: bjj0,
FromEthAddr: ethCommon.HexToAddress("0x7e5f4552091a69125d5dfcb7b8c2659029395bdf"),
ToIdx: 0,
Type: common.TxTypeCreateAccountDeposit,
UserOrigin: true,
// DepositAmount: big.NewInt(10400),
DepositAmount: big.NewInt(16000000),
Amount: big.NewInt(0),
TokenID: 1,
FromBJJ: bjj0,
FromEthAddr: ethCommon.HexToAddress("0x7e5f4552091a69125d5dfcb7b8c2659029395bdf"),
ToIdx: 0,
Type: common.TxTypeCreateAccountDeposit,
UserOrigin: true,
}, },
{ {
FromIdx: 0,
LoadAmount: big.NewInt(16000000),
Amount: big.NewInt(0),
TokenID: 1,
FromBJJ: bjj1,
FromEthAddr: ethCommon.HexToAddress("0x2b5ad5c4795c026514f8317c7a215e218dccd6cf"),
ToIdx: 0,
Type: common.TxTypeCreateAccountDeposit,
UserOrigin: true,
FromIdx: 0,
DepositAmount: big.NewInt(16000000),
Amount: big.NewInt(0),
TokenID: 1,
FromBJJ: bjj1,
FromEthAddr: ethCommon.HexToAddress("0x2b5ad5c4795c026514f8317c7a215e218dccd6cf"),
ToIdx: 0,
Type: common.TxTypeCreateAccountDeposit,
UserOrigin: true,
}, },
} }
l2Txs := []common.PoolL2Tx{ l2Txs := []common.PoolL2Tx{

+ 10
- 10
eth/rollup.go

@ -218,8 +218,8 @@ type RollupInterface interface {
RollupWithdrawMerkleProof(babyPubKey *babyjub.PublicKey, tokenID uint32, numExitRoot, idx int64, amount *big.Int, siblings []*big.Int, instantWithdraw bool) (*types.Transaction, error) RollupWithdrawMerkleProof(babyPubKey *babyjub.PublicKey, tokenID uint32, numExitRoot, idx int64, amount *big.Int, siblings []*big.Int, instantWithdraw bool) (*types.Transaction, error)
RollupWithdrawCircuit(proofA, proofC [2]*big.Int, proofB [2][2]*big.Int, tokenID uint32, numExitRoot, idx int64, amount *big.Int, instantWithdraw bool) (*types.Transaction, error) RollupWithdrawCircuit(proofA, proofC [2]*big.Int, proofB [2][2]*big.Int, tokenID uint32, numExitRoot, idx int64, amount *big.Int, instantWithdraw bool) (*types.Transaction, error)
RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error)
RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error)
RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromIdx int64, depositAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error)
RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx int64, depositAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error)
// Governance Public Functions // Governance Public Functions
RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeout int64) (*types.Transaction, error) RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeout int64) (*types.Transaction, error)
@ -409,7 +409,7 @@ func (c *RollupClient) RollupWithdrawCircuit(proofA, proofC [2]*big.Int, proofB
} }
// RollupL1UserTxERC20ETH is the interface to call the smart contract function // RollupL1UserTxERC20ETH is the interface to call the smart contract function
func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (tx *types.Transaction, err error) {
func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromIdx int64, depositAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth( if tx, err = c.client.CallAuth(
0, 0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) { func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
@ -423,7 +423,7 @@ func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromId
} }
fromIdxBig := big.NewInt(fromIdx) fromIdxBig := big.NewInt(fromIdx)
toIdxBig := big.NewInt(toIdx) toIdxBig := big.NewInt(toIdx)
loadAmountF, err := common.NewFloat16(loadAmount)
depositAmountF, err := common.NewFloat16(depositAmount)
if err != nil { if err != nil {
return nil, tracerr.Wrap(err) return nil, tracerr.Wrap(err)
} }
@ -432,10 +432,10 @@ func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromId
return nil, tracerr.Wrap(err) return nil, tracerr.Wrap(err)
} }
if tokenID == 0 { if tokenID == 0 {
auth.Value = loadAmount
auth.Value = depositAmount
} }
var permit []byte var permit []byte
return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, uint16(loadAmountF),
return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, uint16(depositAmountF),
uint16(amountF), tokenID, toIdxBig, permit) uint16(amountF), tokenID, toIdxBig, permit)
}, },
); err != nil { ); err != nil {
@ -445,7 +445,7 @@ func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromId
} }
// RollupL1UserTxERC20Permit is the interface to call the smart contract function // RollupL1UserTxERC20Permit is the interface to call the smart contract function
func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error) {
func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx int64, depositAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth( if tx, err = c.client.CallAuth(
0, 0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) { func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
@ -459,7 +459,7 @@ func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fro
} }
fromIdxBig := big.NewInt(fromIdx) fromIdxBig := big.NewInt(fromIdx)
toIdxBig := big.NewInt(toIdx) toIdxBig := big.NewInt(toIdx)
loadAmountF, err := common.NewFloat16(loadAmount)
depositAmountF, err := common.NewFloat16(depositAmount)
if err != nil { if err != nil {
return nil, tracerr.Wrap(err) return nil, tracerr.Wrap(err)
} }
@ -468,7 +468,7 @@ func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fro
return nil, tracerr.Wrap(err) return nil, tracerr.Wrap(err)
} }
if tokenID == 0 { if tokenID == 0 {
auth.Value = loadAmount
auth.Value = depositAmount
} }
owner := c.client.account.Address owner := c.client.account.Address
spender := c.address spender := c.address
@ -481,7 +481,7 @@ func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fro
digest, _ := createPermitDigest(tokenAddr, owner, spender, c.chainID, amount, nonce, deadline, tokenName) digest, _ := createPermitDigest(tokenAddr, owner, spender, c.chainID, amount, nonce, deadline, tokenName)
signature, _ := c.client.ks.SignHash(*c.client.account, digest) signature, _ := c.client.ks.SignHash(*c.client.account, digest)
permit := createPermit(owner, spender, amount, deadline, digest, signature) permit := createPermit(owner, spender, amount, deadline, digest, signature)
return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, uint16(loadAmountF),
return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, uint16(depositAmountF),
uint16(amountF), tokenID, toIdxBig, permit) uint16(amountF), tokenID, toIdxBig, permit)
}, },
); err != nil { ); err != nil {

+ 143
- 143
eth/rollup_test.go

@ -267,18 +267,18 @@ func TestRollupL1UserTxETHCreateAccountDeposit(t *testing.T) {
fromIdxInt64 := int64(0) fromIdxInt64 := int64(0)
toIdxInt64 := int64(0) toIdxInt64 := int64(0)
tokenIDUint32 := uint32(0) tokenIDUint32 := uint32(0)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
l1Tx := common.L1Tx{ l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenIDUint32),
Amount: big.NewInt(0),
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
DepositAmount: depositAmount,
TokenID: common.TokenID(tokenIDUint32),
Amount: big.NewInt(0),
} }
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.NoError(t, err) require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
@ -287,7 +287,7 @@ func TestRollupL1UserTxETHCreateAccountDeposit(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ) assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount) assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr) assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
@ -299,18 +299,18 @@ func TestRollupL1UserTxERC20CreateAccountDeposit(t *testing.T) {
key := genKeysBjj(1) key := genKeysBjj(1)
fromIdxInt64 := int64(0) fromIdxInt64 := int64(0)
toIdxInt64 := int64(0) toIdxInt64 := int64(0)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
l1Tx := common.L1Tx{ l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenHEZID),
Amount: big.NewInt(0),
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
DepositAmount: depositAmount,
TokenID: common.TokenID(tokenHEZID),
Amount: big.NewInt(0),
} }
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.NoError(t, err) require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
@ -319,7 +319,7 @@ func TestRollupL1UserTxERC20CreateAccountDeposit(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ) assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount) assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr) assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
@ -331,18 +331,18 @@ func TestRollupL1UserTxERC20PermitCreateAccountDeposit(t *testing.T) {
key := genKeysBjj(3) key := genKeysBjj(3)
fromIdxInt64 := int64(0) fromIdxInt64 := int64(0)
toIdxInt64 := int64(0) toIdxInt64 := int64(0)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
l1Tx := common.L1Tx{ l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenIDERC777),
Amount: big.NewInt(0),
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
DepositAmount: depositAmount,
TokenID: common.TokenID(tokenIDERC777),
Amount: big.NewInt(0),
} }
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.NoError(t, err) require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
@ -351,7 +351,7 @@ func TestRollupL1UserTxERC20PermitCreateAccountDeposit(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ) assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount) assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr) assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
@ -363,18 +363,18 @@ func TestRollupL1UserTxETHDeposit(t *testing.T) {
fromIdxInt64 := int64(256) fromIdxInt64 := int64(256)
toIdxInt64 := int64(0) toIdxInt64 := int64(0)
tokenIDUint32 := uint32(0) tokenIDUint32 := uint32(0)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
l1Tx := common.L1Tx{ l1Tx := common.L1Tx{
FromBJJ: nil,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenIDUint32),
Amount: big.NewInt(0),
FromBJJ: nil,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
DepositAmount: depositAmount,
TokenID: common.TokenID(tokenIDUint32),
Amount: big.NewInt(0),
} }
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.NoError(t, err) require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
@ -382,7 +382,7 @@ func TestRollupL1UserTxETHDeposit(t *testing.T) {
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount) assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr) assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
@ -393,18 +393,18 @@ func TestRollupL1UserTxERC20Deposit(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
fromIdxInt64 := int64(257) fromIdxInt64 := int64(257)
toIdxInt64 := int64(0) toIdxInt64 := int64(0)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
l1Tx := common.L1Tx{ l1Tx := common.L1Tx{
FromBJJ: nil,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenHEZID),
Amount: big.NewInt(0),
FromBJJ: nil,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
DepositAmount: depositAmount,
TokenID: common.TokenID(tokenHEZID),
Amount: big.NewInt(0),
} }
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.NoError(t, err) require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
@ -412,7 +412,7 @@ func TestRollupL1UserTxERC20Deposit(t *testing.T) {
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount) assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr) assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
@ -423,17 +423,17 @@ func TestRollupL1UserTxERC20PermitDeposit(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
fromIdxInt64 := int64(258) fromIdxInt64 := int64(258)
toIdxInt64 := int64(0) toIdxInt64 := int64(0)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
l1Tx := common.L1Tx{ l1Tx := common.L1Tx{
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenIDERC777),
Amount: big.NewInt(0),
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
DepositAmount: depositAmount,
TokenID: common.TokenID(tokenIDERC777),
Amount: big.NewInt(0),
} }
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.NoError(t, err) require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
@ -441,7 +441,7 @@ func TestRollupL1UserTxERC20PermitDeposit(t *testing.T) {
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount) assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr) assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
@ -453,18 +453,18 @@ func TestRollupL1UserTxETHDepositTransfer(t *testing.T) {
fromIdxInt64 := int64(256) fromIdxInt64 := int64(256)
toIdxInt64 := int64(257) toIdxInt64 := int64(257)
tokenIDUint32 := uint32(0) tokenIDUint32 := uint32(0)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
amount, _ := new(big.Int).SetString("100000000000000000000", 10) amount, _ := new(big.Int).SetString("100000000000000000000", 10)
l1Tx := common.L1Tx{ l1Tx := common.L1Tx{
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenIDUint32),
Amount: amount,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
DepositAmount: depositAmount,
TokenID: common.TokenID(tokenIDUint32),
Amount: amount,
} }
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.NoError(t, err) require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
@ -472,7 +472,7 @@ func TestRollupL1UserTxETHDepositTransfer(t *testing.T) {
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount) assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr) assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
@ -483,18 +483,18 @@ func TestRollupL1UserTxERC20DepositTransfer(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
fromIdxInt64 := int64(257) fromIdxInt64 := int64(257)
toIdxInt64 := int64(258) toIdxInt64 := int64(258)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
amount, _ := new(big.Int).SetString("100000000000000000000", 10) amount, _ := new(big.Int).SetString("100000000000000000000", 10)
l1Tx := common.L1Tx{ l1Tx := common.L1Tx{
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenHEZID),
Amount: amount,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
DepositAmount: depositAmount,
TokenID: common.TokenID(tokenHEZID),
Amount: amount,
} }
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.NoError(t, err) require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
@ -502,7 +502,7 @@ func TestRollupL1UserTxERC20DepositTransfer(t *testing.T) {
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount) assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr) assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
@ -513,18 +513,18 @@ func TestRollupL1UserTxERC20PermitDepositTransfer(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
fromIdxInt64 := int64(258) fromIdxInt64 := int64(258)
toIdxInt64 := int64(259) toIdxInt64 := int64(259)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
amount, _ := new(big.Int).SetString("100000000000000000000", 10) amount, _ := new(big.Int).SetString("100000000000000000000", 10)
l1Tx := common.L1Tx{ l1Tx := common.L1Tx{
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenIDERC777),
Amount: amount,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
DepositAmount: depositAmount,
TokenID: common.TokenID(tokenIDERC777),
Amount: amount,
} }
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.NoError(t, err) require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
@ -532,7 +532,7 @@ func TestRollupL1UserTxERC20PermitDepositTransfer(t *testing.T) {
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount) assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr) assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
@ -544,18 +544,18 @@ func TestRollupL1UserTxETHCreateAccountDepositTransfer(t *testing.T) {
fromIdxInt64 := int64(256) fromIdxInt64 := int64(256)
toIdxInt64 := int64(257) toIdxInt64 := int64(257)
tokenIDUint32 := uint32(0) tokenIDUint32 := uint32(0)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
amount, _ := new(big.Int).SetString("20000000000000000000", 10) amount, _ := new(big.Int).SetString("20000000000000000000", 10)
l1Tx := common.L1Tx{ l1Tx := common.L1Tx{
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenIDUint32),
Amount: amount,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
DepositAmount: depositAmount,
TokenID: common.TokenID(tokenIDUint32),
Amount: amount,
} }
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.NoError(t, err) require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
@ -563,7 +563,7 @@ func TestRollupL1UserTxETHCreateAccountDepositTransfer(t *testing.T) {
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount) assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr) assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
@ -574,18 +574,18 @@ func TestRollupL1UserTxERC20CreateAccountDepositTransfer(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
fromIdxInt64 := int64(257) fromIdxInt64 := int64(257)
toIdxInt64 := int64(258) toIdxInt64 := int64(258)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
amount, _ := new(big.Int).SetString("30000000000000000000", 10) amount, _ := new(big.Int).SetString("30000000000000000000", 10)
l1Tx := common.L1Tx{ l1Tx := common.L1Tx{
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenHEZID),
Amount: amount,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
DepositAmount: depositAmount,
TokenID: common.TokenID(tokenHEZID),
Amount: amount,
} }
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.NoError(t, err) require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
@ -593,7 +593,7 @@ func TestRollupL1UserTxERC20CreateAccountDepositTransfer(t *testing.T) {
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount) assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr) assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
@ -604,18 +604,18 @@ func TestRollupL1UserTxERC20PermitCreateAccountDepositTransfer(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
fromIdxInt64 := int64(258) fromIdxInt64 := int64(258)
toIdxInt64 := int64(259) toIdxInt64 := int64(259)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
amount, _ := new(big.Int).SetString("40000000000000000000", 10) amount, _ := new(big.Int).SetString("40000000000000000000", 10)
l1Tx := common.L1Tx{ l1Tx := common.L1Tx{
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenIDERC777),
Amount: amount,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
DepositAmount: depositAmount,
TokenID: common.TokenID(tokenIDERC777),
Amount: amount,
} }
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.NoError(t, err) require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
@ -623,7 +623,7 @@ func TestRollupL1UserTxERC20PermitCreateAccountDepositTransfer(t *testing.T) {
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount) assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr) assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
@ -637,15 +637,15 @@ func TestRollupL1UserTxETHForceTransfer(t *testing.T) {
tokenIDUint32 := uint32(0) tokenIDUint32 := uint32(0)
amount, _ := new(big.Int).SetString("20000000000000000000", 10) amount, _ := new(big.Int).SetString("20000000000000000000", 10)
l1Tx := common.L1Tx{ l1Tx := common.L1Tx{
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(0),
TokenID: common.TokenID(tokenIDUint32),
Amount: amount,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
DepositAmount: big.NewInt(0),
TokenID: common.TokenID(tokenIDUint32),
Amount: amount,
} }
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.NoError(t, err) require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
@ -653,7 +653,7 @@ func TestRollupL1UserTxETHForceTransfer(t *testing.T) {
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount) assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr) assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
@ -666,15 +666,15 @@ func TestRollupL1UserTxERC20ForceTransfer(t *testing.T) {
toIdxInt64 := int64(258) toIdxInt64 := int64(258)
amount, _ := new(big.Int).SetString("10000000000000000000", 10) amount, _ := new(big.Int).SetString("10000000000000000000", 10)
l1Tx := common.L1Tx{ l1Tx := common.L1Tx{
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(0),
TokenID: common.TokenID(tokenHEZID),
Amount: amount,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
DepositAmount: big.NewInt(0),
TokenID: common.TokenID(tokenHEZID),
Amount: amount,
} }
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.NoError(t, err) require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
@ -682,7 +682,7 @@ func TestRollupL1UserTxERC20ForceTransfer(t *testing.T) {
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount) assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr) assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
@ -695,15 +695,15 @@ func TestRollupL1UserTxERC20PermitForceTransfer(t *testing.T) {
toIdxInt64 := int64(260) toIdxInt64 := int64(260)
amount, _ := new(big.Int).SetString("30000000000000000000", 10) amount, _ := new(big.Int).SetString("30000000000000000000", 10)
l1Tx := common.L1Tx{ l1Tx := common.L1Tx{
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(0),
TokenID: common.TokenID(tokenIDERC777),
Amount: amount,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
DepositAmount: big.NewInt(0),
TokenID: common.TokenID(tokenIDERC777),
Amount: amount,
} }
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.NoError(t, err) require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
@ -711,7 +711,7 @@ func TestRollupL1UserTxERC20PermitForceTransfer(t *testing.T) {
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount) assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr) assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
@ -725,15 +725,15 @@ func TestRollupL1UserTxETHForceExit(t *testing.T) {
tokenIDUint32 := uint32(0) tokenIDUint32 := uint32(0)
amount, _ := new(big.Int).SetString("10000000000000000000", 10) amount, _ := new(big.Int).SetString("10000000000000000000", 10)
l1Tx := common.L1Tx{ l1Tx := common.L1Tx{
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(0),
TokenID: common.TokenID(tokenIDUint32),
Amount: amount,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
DepositAmount: big.NewInt(0),
TokenID: common.TokenID(tokenIDUint32),
Amount: amount,
} }
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.NoError(t, err) require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
@ -741,7 +741,7 @@ func TestRollupL1UserTxETHForceExit(t *testing.T) {
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount) assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr) assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
@ -754,15 +754,15 @@ func TestRollupL1UserTxERC20ForceExit(t *testing.T) {
toIdxInt64 := int64(1) toIdxInt64 := int64(1)
amount, _ := new(big.Int).SetString("20000000000000000000", 10) amount, _ := new(big.Int).SetString("20000000000000000000", 10)
l1Tx := common.L1Tx{ l1Tx := common.L1Tx{
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(0),
TokenID: common.TokenID(tokenHEZID),
Amount: amount,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
DepositAmount: big.NewInt(0),
TokenID: common.TokenID(tokenHEZID),
Amount: amount,
} }
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.NoError(t, err) require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
@ -770,7 +770,7 @@ func TestRollupL1UserTxERC20ForceExit(t *testing.T) {
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount) assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr) assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
@ -785,15 +785,15 @@ func TestRollupL1UserTxERC20PermitForceExit(t *testing.T) {
*fromIdx = 0 *fromIdx = 0
amount, _ := new(big.Int).SetString("30000000000000000000", 10) amount, _ := new(big.Int).SetString("30000000000000000000", 10)
l1Tx := common.L1Tx{ l1Tx := common.L1Tx{
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(0),
TokenID: common.TokenID(tokenIDERC777),
Amount: amount,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
DepositAmount: big.NewInt(0),
TokenID: common.TokenID(tokenIDERC777),
Amount: amount,
} }
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.NoError(t, err) require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
@ -801,7 +801,7 @@ func TestRollupL1UserTxERC20PermitForceExit(t *testing.T) {
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount) assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr) assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)

+ 5
- 5
synchronizer/synchronizer_test.go

@ -81,13 +81,13 @@ func checkSyncBlock(t *testing.T, s *Synchronizer, blockNum int, block, syncBloc
dbL1UserTxs, err := s.historyDB.GetAllL1UserTxs() dbL1UserTxs, err := s.historyDB.GetAllL1UserTxs()
require.Nil(t, err) require.Nil(t, err)
// Ignore BatchNum in syncBlock.L1UserTxs because this value is set by // Ignore BatchNum in syncBlock.L1UserTxs because this value is set by
// the HistoryDB. Also ignore EffectiveAmount & EffectiveLoadAmount
// the HistoryDB. Also ignore EffectiveAmount & EffectiveDepositAmount
// because this value is set by StateDB.ProcessTxs. // because this value is set by StateDB.ProcessTxs.
for i := range syncBlock.Rollup.L1UserTxs { for i := range syncBlock.Rollup.L1UserTxs {
syncBlock.Rollup.L1UserTxs[i].BatchNum = block.Rollup.L1UserTxs[i].BatchNum syncBlock.Rollup.L1UserTxs[i].BatchNum = block.Rollup.L1UserTxs[i].BatchNum
syncBlock.Rollup.L1UserTxs[i].EffectiveAmount = block.Rollup.L1UserTxs[i].EffectiveAmount syncBlock.Rollup.L1UserTxs[i].EffectiveAmount = block.Rollup.L1UserTxs[i].EffectiveAmount
syncBlock.Rollup.L1UserTxs[i].EffectiveLoadAmount =
block.Rollup.L1UserTxs[i].EffectiveLoadAmount
syncBlock.Rollup.L1UserTxs[i].EffectiveDepositAmount =
block.Rollup.L1UserTxs[i].EffectiveDepositAmount
} }
assert.Equal(t, block.Rollup.L1UserTxs, syncBlock.Rollup.L1UserTxs) assert.Equal(t, block.Rollup.L1UserTxs, syncBlock.Rollup.L1UserTxs)
for _, tx := range block.Rollup.L1UserTxs { for _, tx := range block.Rollup.L1UserTxs {
@ -102,7 +102,7 @@ func checkSyncBlock(t *testing.T, s *Synchronizer, blockNum int, block, syncBloc
} }
} }
tx.EffectiveAmount = tx.Amount tx.EffectiveAmount = tx.Amount
tx.EffectiveLoadAmount = tx.LoadAmount
tx.EffectiveDepositAmount = tx.DepositAmount
assert.Equal(t, &tx, dbTx) //nolint:gosec assert.Equal(t, &tx, dbTx) //nolint:gosec
} }
@ -255,7 +255,7 @@ func ethAddBlocks(t *testing.T, blocks []common.BlockData,
} }
for _, tx := range block.Rollup.L1UserTxs { for _, tx := range block.Rollup.L1UserTxs {
client.CtlSetAddr(tx.FromEthAddr) client.CtlSetAddr(tx.FromEthAddr)
_, err := client.RollupL1UserTxERC20ETH(tx.FromBJJ, int64(tx.FromIdx), tx.LoadAmount, tx.Amount,
_, err := client.RollupL1UserTxERC20ETH(tx.FromBJJ, int64(tx.FromIdx), tx.DepositAmount, tx.Amount,
uint32(tx.TokenID), int64(tx.ToIdx)) uint32(tx.TokenID), int64(tx.ToIdx))
require.Nil(t, err) require.Nil(t, err)
} }

+ 5
- 5
test/ethclient.go

@ -716,7 +716,7 @@ var errTODO = fmt.Errorf("TODO: Not implemented yet")
// } // }
// RollupL1UserTxERC20Permit is the interface to call the smart contract function // RollupL1UserTxERC20Permit is the interface to call the smart contract function
func (c *Client) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error) {
func (c *Client) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx int64, depositAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error) {
log.Error("TODO") log.Error("TODO")
return nil, tracerr.Wrap(errTODO) return nil, tracerr.Wrap(errTODO)
} }
@ -725,7 +725,7 @@ func (c *Client) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx i
func (c *Client) RollupL1UserTxERC20ETH( func (c *Client) RollupL1UserTxERC20ETH(
fromBJJ *babyjub.PublicKey, fromBJJ *babyjub.PublicKey,
fromIdx int64, fromIdx int64,
loadAmount *big.Int,
depositAmount *big.Int,
amount *big.Int, amount *big.Int,
tokenID uint32, tokenID uint32,
toIdx int64, toIdx int64,
@ -739,7 +739,7 @@ func (c *Client) RollupL1UserTxERC20ETH(
if err != nil { if err != nil {
return nil, tracerr.Wrap(err) return nil, tracerr.Wrap(err)
} }
_, err = common.NewFloat16(loadAmount)
_, err = common.NewFloat16(depositAmount)
if err != nil { if err != nil {
return nil, tracerr.Wrap(err) return nil, tracerr.Wrap(err)
} }
@ -764,7 +764,7 @@ func (c *Client) RollupL1UserTxERC20ETH(
FromEthAddr: *c.addr, FromEthAddr: *c.addr,
FromBJJ: fromBJJ, FromBJJ: fromBJJ,
Amount: amount, Amount: amount,
LoadAmount: loadAmount,
DepositAmount: depositAmount,
TokenID: common.TokenID(tokenID), TokenID: common.TokenID(tokenID),
ToIdx: common.Idx(toIdx), ToIdx: common.Idx(toIdx),
ToForgeL1TxsNum: &toForgeL1TxsNum, ToForgeL1TxsNum: &toForgeL1TxsNum,
@ -783,7 +783,7 @@ func (c *Client) RollupL1UserTxERC20ETH(
} }
// RollupL1UserTxERC777 is the interface to call the smart contract function // RollupL1UserTxERC777 is the interface to call the smart contract function
// func (c *Client) RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error) {
// func (c *Client) RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, depositAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error) {
// log.Error("TODO") // log.Error("TODO")
// return nil, errTODO // return nil, errTODO
// } // }

+ 7
- 7
test/ethclient_test.go

@ -156,14 +156,14 @@ func TestClientRollup(t *testing.T) {
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
keys[i] = genKeys(int64(i)) keys[i] = genKeys(int64(i))
tx := common.L1Tx{ tx := common.L1Tx{
FromIdx: 0,
FromEthAddr: keys[i].Addr,
FromBJJ: keys[i].BJJPublicKey,
TokenID: common.TokenID(0),
Amount: big.NewInt(0),
LoadAmount: big.NewInt(10 + int64(i)),
FromIdx: 0,
FromEthAddr: keys[i].Addr,
FromBJJ: keys[i].BJJPublicKey,
TokenID: common.TokenID(0),
Amount: big.NewInt(0),
DepositAmount: big.NewInt(10 + int64(i)),
} }
_, err := c.RollupL1UserTxERC20ETH(tx.FromBJJ, int64(tx.FromIdx), tx.LoadAmount,
_, err := c.RollupL1UserTxERC20ETH(tx.FromBJJ, int64(tx.FromIdx), tx.DepositAmount,
tx.Amount, uint32(tx.TokenID), int64(tx.ToIdx)) tx.Amount, uint32(tx.TokenID), int64(tx.ToIdx))
require.Nil(t, err) require.Nil(t, err)
} }

+ 6
- 6
test/historydb.go

@ -157,12 +157,12 @@ func GenL1Txs(
token := tokens[i%len(tokens)] token := tokens[i%len(tokens)]
amount := big.NewInt(int64(i + 1)) amount := big.NewInt(int64(i + 1))
tx := common.L1Tx{ tx := common.L1Tx{
Position: i - fromIdx,
UserOrigin: i%2 == 0,
TokenID: token.TokenID,
Amount: amount,
LoadAmount: amount,
EthBlockNum: blocks[i%len(blocks)].Num,
Position: i - fromIdx,
UserOrigin: i%2 == 0,
TokenID: token.TokenID,
Amount: amount,
DepositAmount: amount,
EthBlockNum: blocks[i%len(blocks)].Num,
} }
if tx.UserOrigin { if tx.UserOrigin {
n := nextTxsNum n := nextTxsNum

+ 15
- 15
test/til/lang.go

@ -63,15 +63,15 @@ const (
// Instruction is the data structure that represents one line of code // Instruction is the data structure that represents one line of code
type Instruction struct { type Instruction struct {
LineNum int
Literal string
From string
To string
Amount *big.Int
LoadAmount *big.Int
Fee uint8
TokenID common.TokenID
Typ common.TxType // D: Deposit, T: Transfer, E: ForceExit
LineNum int
Literal string
From string
To string
Amount *big.Int
DepositAmount *big.Int
Fee uint8
TokenID common.TokenID
Typ common.TxType // D: Deposit, T: Transfer, E: ForceExit
} }
// parsedSet contains the full Set of Instructions representing a full code // parsedSet contains the full Set of Instructions representing a full code
@ -94,7 +94,7 @@ func (i Instruction) String() string {
if i.Typ == common.TxTypeDeposit || if i.Typ == common.TxTypeDeposit ||
i.Typ == common.TxTypeDepositTransfer || i.Typ == common.TxTypeDepositTransfer ||
i.Typ == common.TxTypeCreateAccountDepositTransfer { i.Typ == common.TxTypeCreateAccountDepositTransfer {
fmt.Fprintf(buf, "LoadAmount: %d, ", i.LoadAmount)
fmt.Fprintf(buf, "DepositAmount: %d, ", i.DepositAmount)
} }
if i.Typ != common.TxTypeDeposit { if i.Typ != common.TxTypeDeposit {
fmt.Fprintf(buf, "Amount: %d, ", i.Amount) fmt.Fprintf(buf, "Amount: %d, ", i.Amount)
@ -123,7 +123,7 @@ func (i Instruction) raw() string {
if i.Typ == common.TxTypeDeposit || if i.Typ == common.TxTypeDeposit ||
i.Typ == common.TxTypeDepositTransfer || i.Typ == common.TxTypeDepositTransfer ||
i.Typ == common.TxTypeCreateAccountDepositTransfer { i.Typ == common.TxTypeCreateAccountDepositTransfer {
fmt.Fprintf(buf, "%d", i.LoadAmount)
fmt.Fprintf(buf, "%d", i.DepositAmount)
} }
if i.Typ != common.TxTypeDeposit { if i.Typ != common.TxTypeDeposit {
fmt.Fprintf(buf, "%d", i.Amount) fmt.Fprintf(buf, "%d", i.Amount)
@ -439,13 +439,13 @@ func (p *parser) parseLine(setType setType) (*Instruction, error) {
// deposit case // deposit case
_, lit = p.scanIgnoreWhitespace() _, lit = p.scanIgnoreWhitespace()
c.Literal += lit c.Literal += lit
loadAmount, ok := new(big.Int).SetString(lit, 10)
depositAmount, ok := new(big.Int).SetString(lit, 10)
if !ok { if !ok {
line, _ := p.s.r.ReadString('\n') line, _ := p.s.r.ReadString('\n')
c.Literal += line c.Literal += line
return c, tracerr.Wrap(fmt.Errorf("Can not parse number for LoadAmount"))
return c, tracerr.Wrap(fmt.Errorf("Can not parse number for DepositAmount"))
} }
c.LoadAmount = loadAmount
c.DepositAmount = depositAmount
if err := p.expectChar(c, ","); err != nil { if err := p.expectChar(c, ","); err != nil {
return c, tracerr.Wrap(err) return c, tracerr.Wrap(err)
} }
@ -460,7 +460,7 @@ func (p *parser) parseLine(setType setType) (*Instruction, error) {
} }
if c.Typ == common.TxTypeDeposit || if c.Typ == common.TxTypeDeposit ||
c.Typ == common.TxTypeCreateAccountDeposit { c.Typ == common.TxTypeCreateAccountDeposit {
c.LoadAmount = amount
c.DepositAmount = amount
} else { } else {
c.Amount = amount c.Amount = amount
} }

+ 1
- 1
test/til/lang_test.go

@ -72,7 +72,7 @@ func TestParseBlockchainTxs(t *testing.T) {
assert.Equal(t, TxTypeCreateAccountDepositCoordinator, instructions.instructions[7].Typ) assert.Equal(t, TxTypeCreateAccountDepositCoordinator, instructions.instructions[7].Typ)
assert.Equal(t, TypeNewBatch, instructions.instructions[11].Typ) assert.Equal(t, TypeNewBatch, instructions.instructions[11].Typ)
assert.Equal(t, "Deposit(1)User0:20", instructions.instructions[16].raw()) assert.Equal(t, "Deposit(1)User0:20", instructions.instructions[16].raw())
assert.Equal(t, "Type: DepositTransfer, From: A, To: B, LoadAmount: 15, Amount: 10, Fee: 0, TokenID: 1\n", instructions.instructions[13].String())
assert.Equal(t, "Type: DepositTransfer, From: A, To: B, DepositAmount: 15, Amount: 10, Fee: 0, TokenID: 1\n", instructions.instructions[13].String())
assert.Equal(t, "Type: Transfer, From: User1, To: User0, Amount: 15, Fee: 1, TokenID: 3\n", instructions.instructions[19].String()) assert.Equal(t, "Type: Transfer, From: User1, To: User0, Amount: 15, Fee: 1, TokenID: 3\n", instructions.instructions[19].String())
assert.Equal(t, "Transfer(2)A-B:15(1)", instructions.instructions[15].raw()) assert.Equal(t, "Transfer(2)A-B:15(1)", instructions.instructions[15].raw())
assert.Equal(t, "Type: Transfer, From: A, To: B, Amount: 15, Fee: 1, TokenID: 2\n", instructions.instructions[15].String()) assert.Equal(t, "Type: Transfer, From: A, To: B, Amount: 15, Fee: 1, TokenID: 2\n", instructions.instructions[15].String())

+ 29
- 29
test/til/txs.go

@ -199,12 +199,12 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error())) return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error()))
} }
tx := common.L1Tx{ tx := common.L1Tx{
FromEthAddr: tc.Users[inst.From].Addr,
FromBJJ: tc.Users[inst.From].BJJ.Public(),
TokenID: inst.TokenID,
Amount: big.NewInt(0),
LoadAmount: big.NewInt(0),
Type: common.TxTypeCreateAccountDeposit, // as TxTypeCreateAccountDepositCoordinator is not valid oustide Til package
FromEthAddr: tc.Users[inst.From].Addr,
FromBJJ: tc.Users[inst.From].BJJ.Public(),
TokenID: inst.TokenID,
Amount: big.NewInt(0),
DepositAmount: big.NewInt(0),
Type: common.TxTypeCreateAccountDeposit, // as TxTypeCreateAccountDepositCoordinator is not valid oustide Til package
} }
testTx := L1Tx{ testTx := L1Tx{
lineNum: inst.LineNum, lineNum: inst.LineNum,
@ -219,12 +219,12 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error())) return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error()))
} }
tx := common.L1Tx{ tx := common.L1Tx{
FromEthAddr: tc.Users[inst.From].Addr,
FromBJJ: tc.Users[inst.From].BJJ.Public(),
TokenID: inst.TokenID,
Amount: big.NewInt(0),
LoadAmount: inst.LoadAmount,
Type: inst.Typ,
FromEthAddr: tc.Users[inst.From].Addr,
FromBJJ: tc.Users[inst.From].BJJ.Public(),
TokenID: inst.TokenID,
Amount: big.NewInt(0),
DepositAmount: inst.DepositAmount,
Type: inst.Typ,
} }
if inst.Typ == common.TxTypeCreateAccountDepositTransfer { if inst.Typ == common.TxTypeCreateAccountDepositTransfer {
tx.Amount = inst.Amount tx.Amount = inst.Amount
@ -248,10 +248,10 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error())) return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error()))
} }
tx := common.L1Tx{ tx := common.L1Tx{
TokenID: inst.TokenID,
Amount: big.NewInt(0),
LoadAmount: inst.LoadAmount,
Type: inst.Typ,
TokenID: inst.TokenID,
Amount: big.NewInt(0),
DepositAmount: inst.DepositAmount,
Type: inst.Typ,
} }
if inst.Typ == common.TxTypeDepositTransfer { if inst.Typ == common.TxTypeDepositTransfer {
tx.Amount = inst.Amount tx.Amount = inst.Amount
@ -291,10 +291,10 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error())) return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error()))
} }
tx := common.L1Tx{ tx := common.L1Tx{
TokenID: inst.TokenID,
Amount: inst.Amount,
LoadAmount: big.NewInt(0),
Type: common.TxTypeForceTransfer,
TokenID: inst.TokenID,
Amount: inst.Amount,
DepositAmount: big.NewInt(0),
Type: common.TxTypeForceTransfer,
} }
testTx := L1Tx{ testTx := L1Tx{
lineNum: inst.LineNum, lineNum: inst.LineNum,
@ -332,11 +332,11 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error())) return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error()))
} }
tx := common.L1Tx{ tx := common.L1Tx{
ToIdx: common.Idx(1), // as is an Exit
TokenID: inst.TokenID,
Amount: inst.Amount,
LoadAmount: big.NewInt(0),
Type: common.TxTypeForceExit,
ToIdx: common.Idx(1), // as is an Exit
TokenID: inst.TokenID,
Amount: inst.Amount,
DepositAmount: big.NewInt(0),
Type: common.TxTypeForceExit,
} }
testTx := L1Tx{ testTx := L1Tx{
lineNum: inst.LineNum, lineNum: inst.LineNum,
@ -747,7 +747,7 @@ func (tc *Context) FillBlocksL1UserTxsBatchNum(blocks []common.BlockData) {
// FillBlocksForgedL1UserTxs fills the L1UserTxs of a batch with the L1UserTxs // FillBlocksForgedL1UserTxs fills the L1UserTxs of a batch with the L1UserTxs
// that are forged in that batch. It always sets `EffectiveAmount` = `Amount` // that are forged in that batch. It always sets `EffectiveAmount` = `Amount`
// and `EffectiveLoadAmount` = `LoadAmount`.
// and `EffectiveDepositAmount` = `DepositAmount`.
func (tc *Context) FillBlocksForgedL1UserTxs(blocks []common.BlockData) error { func (tc *Context) FillBlocksForgedL1UserTxs(blocks []common.BlockData) error {
for i := range blocks { for i := range blocks {
block := &blocks[i] block := &blocks[i]
@ -761,7 +761,7 @@ func (tc *Context) FillBlocksForgedL1UserTxs(blocks []common.BlockData) error {
tx := &batch.L1UserTxs[k] tx := &batch.L1UserTxs[k]
*tx = queue[k].L1Tx *tx = queue[k].L1Tx
tx.EffectiveAmount = tx.Amount tx.EffectiveAmount = tx.Amount
tx.EffectiveLoadAmount = tx.LoadAmount
tx.EffectiveDepositAmount = tx.DepositAmount
tx.BatchNum = &batchNum tx.BatchNum = &batchNum
_tx, err := common.NewL1Tx(tx) _tx, err := common.NewL1Tx(tx)
if err != nil { if err != nil {
@ -786,7 +786,7 @@ func (tc *Context) FillBlocksForgedL1UserTxs(blocks []common.BlockData) error {
// - blocks[].Rollup.Batch.L1CoordinatorTxs[].EthBlockNum // - blocks[].Rollup.Batch.L1CoordinatorTxs[].EthBlockNum
// - blocks[].Rollup.Batch.L1CoordinatorTxs[].Position // - blocks[].Rollup.Batch.L1CoordinatorTxs[].Position
// - blocks[].Rollup.Batch.L1CoordinatorTxs[].EffectiveAmount // - blocks[].Rollup.Batch.L1CoordinatorTxs[].EffectiveAmount
// - blocks[].Rollup.Batch.L1CoordinatorTxs[].EffectiveLoadAmount
// - blocks[].Rollup.Batch.L1CoordinatorTxs[].EffectiveDepositAmount
// - blocks[].Rollup.Batch.L2Txs[].TxID // - blocks[].Rollup.Batch.L2Txs[].TxID
// - blocks[].Rollup.Batch.L2Txs[].Position // - blocks[].Rollup.Batch.L2Txs[].Position
// - blocks[].Rollup.Batch.L2Txs[].Nonce // - blocks[].Rollup.Batch.L2Txs[].Nonce
@ -869,7 +869,7 @@ func (tc *Context) FillBlocksExtra(blocks []common.BlockData, cfg *ConfigExtra)
tx.Position = position tx.Position = position
position++ position++
tx.EffectiveAmount = big.NewInt(0) tx.EffectiveAmount = big.NewInt(0)
tx.EffectiveLoadAmount = big.NewInt(0)
tx.EffectiveDepositAmount = big.NewInt(0)
nTx, err := common.NewL1Tx(tx) nTx, err := common.NewL1Tx(tx)
if err != nil { if err != nil {
return tracerr.Wrap(err) return tracerr.Wrap(err)

+ 8
- 8
test/til/txs_test.go

@ -141,7 +141,7 @@ func TestGenerateBlocks(t *testing.T) {
tc.checkL2TxParams(t, blocks[1].Rollup.Batches[0].L2Txs[1], common.TxTypeTransfer, 1, "A", "B", big.NewInt(1), common.BatchNum(6)) tc.checkL2TxParams(t, blocks[1].Rollup.Batches[0].L2Txs[1], common.TxTypeTransfer, 1, "A", "B", big.NewInt(1), common.BatchNum(6))
} }
func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxType, tokenID common.TokenID, from, to string, loadAmount, amount *big.Int) {
func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxType, tokenID common.TokenID, from, to string, depositAmount, amount *big.Int) {
assert.Equal(t, typ, tx.Type) assert.Equal(t, typ, tx.Type)
if tx.FromIdx != common.Idx(0) { if tx.FromIdx != common.Idx(0) {
assert.Equal(t, tc.Users[from].Accounts[tokenID].Idx, tx.FromIdx) assert.Equal(t, tc.Users[from].Accounts[tokenID].Idx, tx.FromIdx)
@ -151,8 +151,8 @@ func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxTy
if tx.ToIdx != common.Idx(0) { if tx.ToIdx != common.Idx(0) {
assert.Equal(t, tc.Users[to].Accounts[tokenID].Idx, tx.ToIdx) assert.Equal(t, tc.Users[to].Accounts[tokenID].Idx, tx.ToIdx)
} }
if loadAmount != nil {
assert.Equal(t, loadAmount, tx.LoadAmount)
if depositAmount != nil {
assert.Equal(t, depositAmount, tx.DepositAmount)
} }
if amount != nil { if amount != nil {
assert.Equal(t, amount, tx.Amount) assert.Equal(t, amount, tx.Amount)
@ -432,14 +432,14 @@ func TestGenerateFromInstructions(t *testing.T) {
TokenID: 1, TokenID: 1,
}) })
i++ i++
la := big.NewInt(10)
da := big.NewInt(10)
setInst = append(setInst, Instruction{ setInst = append(setInst, Instruction{
LineNum: i, LineNum: i,
// Literal: "CreateAccountDeposit(1) A: 10", // Literal: "CreateAccountDeposit(1) A: 10",
Typ: common.TxTypeCreateAccountDeposit,
From: "A",
TokenID: 1,
LoadAmount: la,
Typ: common.TxTypeCreateAccountDeposit,
From: "A",
TokenID: 1,
DepositAmount: da,
}) })
i++ i++
setInst = append(setInst, Instruction{ setInst = append(setInst, Instruction{

+ 14
- 14
txselector/txselector.go

@ -160,13 +160,13 @@ func (txsel *TxSelector) GetL1L2TxSelection(coordIdxs []common.Idx, batchNum com
} }
// create L1CoordinatorTx for the accountCreation // create L1CoordinatorTx for the accountCreation
l1CoordinatorTx := common.L1Tx{ l1CoordinatorTx := common.L1Tx{
Position: positionL1,
UserOrigin: false,
FromEthAddr: accAuth.EthAddr,
FromBJJ: accAuth.BJJ,
TokenID: l2TxsRaw[i].TokenID,
LoadAmount: big.NewInt(0),
Type: common.TxTypeCreateAccountDeposit,
Position: positionL1,
UserOrigin: false,
FromEthAddr: accAuth.EthAddr,
FromBJJ: accAuth.BJJ,
TokenID: l2TxsRaw[i].TokenID,
DepositAmount: big.NewInt(0),
Type: common.TxTypeCreateAccountDeposit,
} }
positionL1++ positionL1++
l1CoordinatorTxs = append(l1CoordinatorTxs, l1CoordinatorTx) l1CoordinatorTxs = append(l1CoordinatorTxs, l1CoordinatorTx)
@ -185,13 +185,13 @@ func (txsel *TxSelector) GetL1L2TxSelection(coordIdxs []common.Idx, batchNum com
// L1Authorization, as ToEthAddr==0xff // L1Authorization, as ToEthAddr==0xff
// create L1CoordinatorTx for the accountCreation // create L1CoordinatorTx for the accountCreation
l1CoordinatorTx := common.L1Tx{ l1CoordinatorTx := common.L1Tx{
Position: positionL1,
UserOrigin: false,
FromEthAddr: l2TxsRaw[i].ToEthAddr,
FromBJJ: l2TxsRaw[i].ToBJJ,
TokenID: l2TxsRaw[i].TokenID,
LoadAmount: big.NewInt(0),
Type: common.TxTypeCreateAccountDeposit,
Position: positionL1,
UserOrigin: false,
FromEthAddr: l2TxsRaw[i].ToEthAddr,
FromBJJ: l2TxsRaw[i].ToBJJ,
TokenID: l2TxsRaw[i].TokenID,
DepositAmount: big.NewInt(0),
Type: common.TxTypeCreateAccountDeposit,
} }
positionL1++ positionL1++
l1CoordinatorTxs = append(l1CoordinatorTxs, l1CoordinatorTx) l1CoordinatorTxs = append(l1CoordinatorTxs, l1CoordinatorTx)

Loading…
Cancel
Save