mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Rename load amount to deposit amount
This commit is contained in:
@@ -455,11 +455,11 @@ func (s *StateDB) processL1Tx(exitTree *merkletree.MerkleTree, tx *common.L1Tx)
|
||||
s.zki.OnChain[s.i] = big.NewInt(1)
|
||||
|
||||
// L1Txs
|
||||
loadAmountF16, err := common.NewFloat16(tx.LoadAmount)
|
||||
depositAmountF16, err := common.NewFloat16(tx.DepositAmount)
|
||||
if err != nil {
|
||||
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)
|
||||
if tx.FromBJJ != nil {
|
||||
s.zki.FromBJJCompressed[s.i] = BJJCompressedTo256BigInts(tx.FromBJJ.Compress())
|
||||
@@ -660,7 +660,7 @@ func (s *StateDB) applyCreateAccount(tx *common.L1Tx) error {
|
||||
account := &common.Account{
|
||||
TokenID: tx.TokenID,
|
||||
Nonce: 0,
|
||||
Balance: tx.EffectiveLoadAmount,
|
||||
Balance: tx.EffectiveDepositAmount,
|
||||
PublicKey: tx.FromBJJ,
|
||||
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.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.Siblings1[s.i] = siblingsToZKInputFormat(p.Siblings)
|
||||
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
|
||||
// Transfer of the L1Tx/DepositTransfer
|
||||
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)
|
||||
if err != nil {
|
||||
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
|
||||
var accReceiver *common.Account
|
||||
@@ -883,7 +883,7 @@ func (s *StateDB) applyCreateAccountDepositTransfer(tx *common.L1Tx) error {
|
||||
accSender := &common.Account{
|
||||
TokenID: tx.TokenID,
|
||||
Nonce: 0,
|
||||
Balance: tx.EffectiveLoadAmount,
|
||||
Balance: tx.EffectiveDepositAmount,
|
||||
PublicKey: tx.FromBJJ,
|
||||
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.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.Siblings1[s.i] = siblingsToZKInputFormat(p.Siblings)
|
||||
if p.IsOld0 {
|
||||
@@ -1039,20 +1039,20 @@ func (s *StateDB) computeEffectiveAmounts(tx *common.L1Tx) {
|
||||
if !tx.UserOrigin {
|
||||
// case where the L1Tx is generated by the Coordinator
|
||||
tx.EffectiveAmount = big.NewInt(0)
|
||||
tx.EffectiveLoadAmount = big.NewInt(0)
|
||||
tx.EffectiveDepositAmount = big.NewInt(0)
|
||||
return
|
||||
}
|
||||
|
||||
tx.EffectiveAmount = tx.Amount
|
||||
tx.EffectiveLoadAmount = tx.LoadAmount
|
||||
tx.EffectiveDepositAmount = tx.DepositAmount
|
||||
if tx.Type == common.TxTypeCreateAccountDeposit {
|
||||
return
|
||||
}
|
||||
|
||||
if tx.ToIdx >= common.UserThreshold && tx.FromIdx == common.Idx(0) {
|
||||
// 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)
|
||||
return
|
||||
}
|
||||
@@ -1061,24 +1061,24 @@ func (s *StateDB) computeEffectiveAmounts(tx *common.L1Tx) {
|
||||
|
||||
accSender, err := s.GetAccount(tx.FromIdx)
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
||||
// check that tx.TokenID corresponds to the Sender account 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)
|
||||
return
|
||||
}
|
||||
|
||||
// check that Sender has enough 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)
|
||||
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
|
||||
// Sender
|
||||
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)
|
||||
return
|
||||
}
|
||||
@@ -1104,14 +1104,14 @@ func (s *StateDB) computeEffectiveAmounts(tx *common.L1Tx) {
|
||||
// check that TokenID is the same for Sender & Receiver account
|
||||
accReceiver, err := s.GetAccount(tx.ToIdx)
|
||||
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)
|
||||
return
|
||||
}
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -58,80 +58,80 @@ func TestCheckL1TxInvalidData(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
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)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveLoadAmount)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveDepositAmount)
|
||||
assert.Equal(t, big.NewInt(10), tx.EffectiveAmount)
|
||||
|
||||
// expect error due not enough funds
|
||||
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)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveLoadAmount)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveDepositAmount)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveAmount)
|
||||
|
||||
// expect no-error due not enough funds in a
|
||||
// CreateAccountDepositTransfer transction
|
||||
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)
|
||||
assert.Equal(t, big.NewInt(10), tx.EffectiveLoadAmount)
|
||||
assert.Equal(t, big.NewInt(10), tx.EffectiveDepositAmount)
|
||||
assert.Equal(t, big.NewInt(10), tx.EffectiveAmount)
|
||||
|
||||
// expect error due not enough funds in a CreateAccountDepositTransfer
|
||||
// transction
|
||||
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)
|
||||
assert.Equal(t, big.NewInt(10), tx.EffectiveLoadAmount)
|
||||
assert.Equal(t, big.NewInt(10), tx.EffectiveDepositAmount)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveAmount)
|
||||
|
||||
// expect error due not same TokenID
|
||||
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)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveLoadAmount)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveDepositAmount)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveAmount)
|
||||
|
||||
// expect error due not same EthAddr
|
||||
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)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveLoadAmount)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveDepositAmount)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveAmount)
|
||||
}
|
||||
|
||||
@@ -555,15 +555,15 @@ func TestProcessTxsRootTestVectors(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
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{
|
||||
@@ -611,15 +611,15 @@ func TestCircomTest(t *testing.T) {
|
||||
|
||||
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{
|
||||
@@ -700,15 +700,15 @@ func TestZKInputsHashTestVector0(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
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{
|
||||
@@ -778,26 +778,26 @@ func TestZKInputsHashTestVector1(t *testing.T) {
|
||||
l1Txs := []common.L1Tx{
|
||||
{
|
||||
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{
|
||||
|
||||
Reference in New Issue
Block a user