Rename load amount to deposit amount

This commit is contained in:
Arnau B
2020-12-04 13:20:18 +01:00
parent 2dd6d82dbe
commit 445f26ec9f
26 changed files with 519 additions and 519 deletions

View File

@@ -66,7 +66,7 @@ const (
// RollupConstL1CoordinatorTotalBytes [4 bytes] token + [32 bytes] babyjub + [65 bytes] compressedSignature
RollupConstL1CoordinatorTotalBytes = 101
// 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
// RollupConstMaxL1UserTx Maximum L1-user transactions allowed to be queued in a batch
RollupConstMaxL1UserTx = 128
@@ -87,8 +87,8 @@ const (
)
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, _ = new(big.Int).SetString("6277101735386680763835789423207666416102355444464034512896", 10)

View File

@@ -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
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
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"`
FromBJJ *babyjub.PublicKey `meddler:"from_bjj,zeroisnull"`
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"`
// EffectiveAmount only applies to L1UserTx.
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
@@ -67,7 +67,7 @@ func NewL1Tx(l1Tx *L1Tx) (*L1Tx, error) {
} else if l1Tx.ToIdx == Idx(1) {
txType = TxTypeForceExit
} else if l1Tx.ToIdx >= IdxUserThreshold {
if l1Tx.LoadAmount.Int64() == int64(0) {
if l1Tx.DepositAmount.Int64() == int64(0) {
txType = TxTypeForceTransfer
} else {
txType = TxTypeDepositTransfer
@@ -140,13 +140,13 @@ func (tx L1Tx) Tx() Tx {
UserOrigin: userOrigin,
FromEthAddr: tx.FromEthAddr,
FromBJJ: tx.FromBJJ,
LoadAmount: tx.EffectiveLoadAmount,
DepositAmount: tx.EffectiveDepositAmount,
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
}
@@ -257,11 +257,11 @@ func (tx *L1Tx) BytesGeneric() ([]byte, error) {
return nil, tracerr.Wrap(err)
}
copy(b[52:58], fromIdxBytes[:])
loadAmountFloat16, err := NewFloat16(tx.LoadAmount)
depositAmountFloat16, err := NewFloat16(tx.DepositAmount)
if err != nil {
return nil, tracerr.Wrap(err)
}
copy(b[58:60], loadAmountFloat16.Bytes())
copy(b[58:60], depositAmountFloat16.Bytes())
amountFloat16, err := NewFloat16(tx.Amount)
if err != nil {
return nil, tracerr.Wrap(err)
@@ -328,7 +328,7 @@ func L1UserTxFromBytes(b []byte) (*L1Tx, error) {
return nil, tracerr.Wrap(err)
}
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.TokenID, err = TokenIDFromBytes(b[62:66])
if err != nil {
@@ -375,7 +375,7 @@ func L1CoordinatorTxFromBytes(b []byte, chainID *big.Int, hermezAddress ethCommo
return nil, tracerr.Wrap(err)
}
tx.Amount = big.NewInt(0)
tx.LoadAmount = big.NewInt(0)
tx.DepositAmount = big.NewInt(0)
if int(v) > 0 {
// L1CoordinatorTX ETH
// Ethereum adds 27 to v

View File

@@ -24,7 +24,7 @@ func TestNewL1UserTx(t *testing.T) {
ToIdx: 301,
TokenID: 5,
Amount: big.NewInt(1),
LoadAmount: big.NewInt(2),
DepositAmount: big.NewInt(2),
FromIdx: Idx(300),
}
l1Tx, err := NewL1Tx(l1Tx)
@@ -35,14 +35,14 @@ func TestNewL1UserTx(t *testing.T) {
func TestNewL1CoordinatorTx(t *testing.T) {
batchNum := BatchNum(51966)
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)
assert.Nil(t, err)
@@ -124,14 +124,14 @@ func TestL1userTxByteParsers(t *testing.T) {
require.Nil(t, err)
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()
@@ -164,17 +164,17 @@ func TestL1TxByteParsersCompatibility(t *testing.T) {
pk, err := pkComp.Decompress()
require.Nil(t, err)
loadAmount := new(big.Int)
loadAmount.SetString("100000000000000000000", 10)
depositAmount := new(big.Int)
depositAmount.SetString("100000000000000000000", 10)
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")
@@ -227,11 +227,11 @@ func TestL1CoordinatorTxByteParsers(t *testing.T) {
signature[64] = byte(v + 27)
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)

View File

@@ -33,8 +33,8 @@ type PoolL2Tx struct {
Signature babyjub.SignatureComp `meddler:"signature"` // tx signature
Timestamp time.Time `meddler:"timestamp,utctime"` // time when added to the tx pool
// 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"`
RqToBJJ *babyjub.PublicKey `meddler:"rq_to_bjj"` // TODO: stop using json, use scanner/valuer
RqTokenID TokenID `meddler:"rq_token_id,zeroisnull"`

View File

@@ -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
EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue
// 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
Fee *FeeSelector `meddler:"fee"`
FeeUSD *float64 `meddler:"fee_usd"`
@@ -165,7 +165,7 @@ func (tx *Tx) String() string {
if tx.Type == TxTypeDeposit ||
tx.Type == TxTypeDepositTransfer ||
tx.Type == TxTypeCreateAccountDepositTransfer {
fmt.Fprintf(buf, "LoadAmount: %d, ", tx.LoadAmount)
fmt.Fprintf(buf, "DepositAmount: %d, ", tx.DepositAmount)
}
if tx.Type != TxTypeDeposit {
fmt.Fprintf(buf, "Amount: %s, ", tx.Amount)
@@ -193,7 +193,7 @@ func (tx *Tx) L1Tx() (*L1Tx, error) {
ToIdx: tx.ToIdx,
TokenID: tx.TokenID,
Amount: tx.Amount,
LoadAmount: tx.LoadAmount,
DepositAmount: tx.DepositAmount,
EthBlockNum: tx.EthBlockNum,
Type: tx.Type,
BatchNum: tx.BatchNum,

View File

@@ -106,8 +106,8 @@ type ZKInputs struct {
//
// NewAccount boolean (0/1) flag set 'true' when L1 tx creates a new account (fromIdx==0)
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 []*big.Int `json:"fromEthAddr"` // ethCommon.Address, len: [nTx]
// 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)
// L1
zki.LoadAmountF = newSlice(nTx)
zki.DepositAmountF = newSlice(nTx)
zki.FromEthAddr = newSlice(nTx)
zki.FromBJJCompressed = make([][256]*big.Int, nTx)
for i := 0; i < len(zki.FromBJJCompressed); i++ {