Browse Source

Update Account.PublicKey to Account.BJJ

Update account.PublicKey to account.BJJ for naming consistency with the rest of the code
feature/sql-semaphore1
arnaucube 4 years ago
parent
commit
bf5ab12d0e
16 changed files with 168 additions and 168 deletions
  1. +1
    -1
      api/account_test.go
  2. +1
    -1
      api/exits_test.go
  3. +3
    -3
      api/txshistory_test.go
  4. +1
    -1
      api/txspool.go
  5. +2
    -2
      api/txspool_test.go
  6. +14
    -14
      common/account.go
  7. +46
    -46
      common/account_test.go
  8. +1
    -1
      db/statedb/statedb.go
  9. +30
    -30
      db/statedb/statedb_test.go
  10. +1
    -1
      synchronizer/synchronizer_test.go
  11. +6
    -6
      test/debugapi/debugapi_test.go
  12. +8
    -8
      test/historydb.go
  13. +7
    -7
      test/til/txs.go
  14. +25
    -25
      txprocessor/txprocessor.go
  15. +20
    -20
      txprocessor/zkinputsgen_test.go
  16. +2
    -2
      txselector/txselector.go

+ 1
- 1
api/account_test.go

@ -45,7 +45,7 @@ func genTestAccounts(accounts []common.Account, tokens []historydb.TokenWithUSD)
tAccount := testAccount{
ItemID: uint64(x + 1),
Idx: apitypes.HezIdx(idxToHez(account.Idx, token.Symbol)),
PublicKey: apitypes.NewHezBJJ(account.PublicKey),
PublicKey: apitypes.NewHezBJJ(account.BJJ),
EthAddr: apitypes.NewHezEthAddr(account.EthAddr),
Nonce: account.Nonce,
Balance: apitypes.NewBigIntStr(account.Balance),

+ 1
- 1
api/exits_test.go

@ -73,7 +73,7 @@ func genTestExits(
allExits = append(allExits, testExit{
BatchNum: exit.BatchNum,
AccountIdx: idxToHez(exit.AccountIdx, token.Symbol),
BJJ: apitypes.NewHezBJJ(acc.PublicKey),
BJJ: apitypes.NewHezBJJ(acc.BJJ),
EthAddr: apitypes.NewHezEthAddr(acc.EthAddr),
MerkleProof: testCVP{
Root: exit.MerkleProof.Root.String(),

+ 3
- 3
api/txshistory_test.go

@ -153,7 +153,7 @@ func genTestTxs(
if l1.ToIdx == acc.Idx {
toEthAddr := string(apitypes.NewHezEthAddr(acc.EthAddr))
tx.ToEthAddr = &toEthAddr
toBJJ := string(apitypes.NewHezBJJ(acc.PublicKey))
toBJJ := string(apitypes.NewHezBJJ(acc.BJJ))
tx.ToBJJ = &toBJJ
break
}
@ -208,7 +208,7 @@ func genTestTxs(
if l2s[i].FromIdx == acc.Idx {
fromEthAddr := string(apitypes.NewHezEthAddr(acc.EthAddr))
tx.FromEthAddr = &fromEthAddr
fromBJJ := string(apitypes.NewHezBJJ(acc.PublicKey))
fromBJJ := string(apitypes.NewHezBJJ(acc.BJJ))
tx.FromBJJ = &fromBJJ
break
}
@ -220,7 +220,7 @@ func genTestTxs(
if l2s[i].ToIdx == acc.Idx {
toEthAddr := string(apitypes.NewHezEthAddr(acc.EthAddr))
tx.ToEthAddr = &toEthAddr
toBJJ := string(apitypes.NewHezBJJ(acc.PublicKey))
toBJJ := string(apitypes.NewHezBJJ(acc.BJJ))
tx.ToBJJ = &toBJJ
break
}

+ 1
- 1
api/txspool.go

@ -180,7 +180,7 @@ func (a *API) verifyPoolL2TxWrite(txw *l2db.PoolL2TxWrite) error {
return tracerr.Wrap(err)
}
// Check signature
if !poolTx.VerifySignature(a.chainID, account.PublicKey) {
if !poolTx.VerifySignature(a.chainID, account.BJJ) {
return tracerr.Wrap(errors.New("wrong signature"))
}
return nil

+ 2
- 2
api/txspool_test.go

@ -106,7 +106,7 @@ func genTestPoolTxs(
fromAcc := getAccountByIdx(poolTx.FromIdx, accs)
fromAddr := ethAddrToHez(fromAcc.EthAddr)
genReceiveTx.FromEthAddr = &fromAddr
fromBjj := bjjToString(fromAcc.PublicKey)
fromBjj := bjjToString(fromAcc.BJJ)
genReceiveTx.FromBJJ = &fromBjj
if poolTx.ToIdx != 0 {
toIdx := idxToHez(poolTx.ToIdx, token.Symbol)
@ -128,7 +128,7 @@ func genTestPoolTxs(
genReceiveTx.ToBJJ = &toBJJ
} else if poolTx.ToIdx > 255 {
acc := getAccountByIdx(poolTx.ToIdx, accs)
bjj := bjjToString(acc.PublicKey)
bjj := bjjToString(acc.BJJ)
genReceiveTx.ToBJJ = &bjj
}
if poolTx.RqFromIdx != 0 {

+ 14
- 14
common/account.go

@ -115,19 +115,19 @@ func NonceFromBytes(b [5]byte) Nonce {
// Account is a struct that gives information of the holdings of an address and a specific token. Is the data structure that generates the Value stored in the leaf of the MerkleTree
type Account struct {
Idx Idx `meddler:"idx"`
TokenID TokenID `meddler:"token_id"`
BatchNum BatchNum `meddler:"batch_num"`
PublicKey babyjub.PublicKeyComp `meddler:"bjj"`
EthAddr ethCommon.Address `meddler:"eth_addr"`
Nonce Nonce `meddler:"-"` // max of 40 bits used
Balance *big.Int `meddler:"-"` // max of 192 bits used
Idx Idx `meddler:"idx"`
TokenID TokenID `meddler:"token_id"`
BatchNum BatchNum `meddler:"batch_num"`
BJJ babyjub.PublicKeyComp `meddler:"bjj"`
EthAddr ethCommon.Address `meddler:"eth_addr"`
Nonce Nonce `meddler:"-"` // max of 40 bits used
Balance *big.Int `meddler:"-"` // max of 192 bits used
}
func (a *Account) String() string {
buf := bytes.NewBufferString("")
fmt.Fprintf(buf, "Idx: %v, ", a.Idx)
fmt.Fprintf(buf, "PublicKey: %s..., ", a.PublicKey.String()[:10])
fmt.Fprintf(buf, "BJJ: %s..., ", a.BJJ.String()[:10])
fmt.Fprintf(buf, "EthAddr: %s..., ", a.EthAddr.String()[:10])
fmt.Fprintf(buf, "TokenID: %v, ", a.TokenID)
fmt.Fprintf(buf, "Nonce: %d, ", a.Nonce)
@ -158,7 +158,7 @@ func (a *Account) Bytes() ([32 * NLeafElems]byte, error) {
copy(b[28:32], a.TokenID.Bytes())
copy(b[23:28], nonceBytes[:])
pkSign, pkY := babyjub.UnpackSignY(a.PublicKey)
pkSign, pkY := babyjub.UnpackSignY(a.BJJ)
if pkSign {
b[22] = 1
}
@ -243,11 +243,11 @@ func AccountFromBytes(b [32 * NLeafElems]byte) (*Account, error) {
}
a := Account{
TokenID: TokenID(tokenID),
Nonce: nonce,
Balance: balance,
PublicKey: publicKeyComp,
EthAddr: ethAddr,
TokenID: TokenID(tokenID),
Nonce: nonce,
Balance: balance,
BJJ: publicKeyComp,
EthAddr: ethAddr,
}
return &a, nil
}

+ 46
- 46
common/account_test.go

@ -81,11 +81,11 @@ func TestAccount(t *testing.T) {
pk := sk.Public()
account := &Account{
TokenID: TokenID(1),
Nonce: Nonce(1234),
Balance: big.NewInt(1000),
PublicKey: pk.Compress(),
EthAddr: ethCommon.HexToAddress("0xc58d29fA6e86E4FAe04DDcEd660d45BCf3Cb2370"),
TokenID: TokenID(1),
Nonce: Nonce(1234),
Balance: big.NewInt(1000),
BJJ: pk.Compress(),
EthAddr: ethCommon.HexToAddress("0xc58d29fA6e86E4FAe04DDcEd660d45BCf3Cb2370"),
}
b, err := account.Bytes()
assert.NoError(t, err)
@ -124,11 +124,11 @@ func TestAccountLoop(t *testing.T) {
address := ethCrypto.PubkeyToAddress(key.PublicKey)
account := &Account{
TokenID: TokenID(i),
Nonce: Nonce(i),
Balance: big.NewInt(1000),
PublicKey: pk.Compress(),
EthAddr: address,
TokenID: TokenID(i),
Nonce: Nonce(i),
Balance: big.NewInt(1000),
BJJ: pk.Compress(),
EthAddr: address,
}
b, err := account.Bytes()
assert.NoError(t, err)
@ -161,11 +161,11 @@ func TestAccountLoopRandom(t *testing.T) {
address := ethCrypto.PubkeyToAddress(key.PublicKey)
account := &Account{
TokenID: TokenID(i),
Nonce: Nonce(i),
Balance: big.NewInt(1000),
PublicKey: pk.Compress(),
EthAddr: address,
TokenID: TokenID(i),
Nonce: Nonce(i),
Balance: big.NewInt(1000),
BJJ: pk.Compress(),
EthAddr: address,
}
b, err := account.Bytes()
assert.NoError(t, err)
@ -204,11 +204,11 @@ func TestAccountHashValue(t *testing.T) {
pk := sk.Public()
account := &Account{
TokenID: TokenID(1),
Nonce: Nonce(1234),
Balance: big.NewInt(1000),
PublicKey: pk.Compress(),
EthAddr: ethCommon.HexToAddress("0xc58d29fA6e86E4FAe04DDcEd660d45BCf3Cb2370"),
TokenID: TokenID(1),
Nonce: Nonce(1234),
Balance: big.NewInt(1000),
BJJ: pk.Compress(),
EthAddr: ethCommon.HexToAddress("0xc58d29fA6e86E4FAe04DDcEd660d45BCf3Cb2370"),
}
v, err := account.HashValue()
assert.NoError(t, err)
@ -224,12 +224,12 @@ func TestAccountHashValueTestVectors(t *testing.T) {
bjj := babyjub.PublicKey(*bjjPoint)
account := &Account{
Idx: 1,
TokenID: 0xFFFFFFFF,
PublicKey: bjj.Compress(),
EthAddr: ethCommon.HexToAddress("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"),
Nonce: Nonce(0xFFFFFFFFFF),
Balance: bigFromStr("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16),
Idx: 1,
TokenID: 0xFFFFFFFF,
BJJ: bjj.Compress(),
EthAddr: ethCommon.HexToAddress("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"),
Nonce: Nonce(0xFFFFFFFFFF),
Balance: bigFromStr("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16),
}
e, err := account.BigInts()
@ -253,11 +253,11 @@ func TestAccountHashValueTestVectors(t *testing.T) {
require.NoError(t, err)
bjj = babyjub.PublicKey(*bjjPoint)
account = &Account{
TokenID: 0,
PublicKey: bjj.Compress(),
EthAddr: ethCommon.HexToAddress("0x00"),
Nonce: Nonce(0),
Balance: big.NewInt(0),
TokenID: 0,
BJJ: bjj.Compress(),
EthAddr: ethCommon.HexToAddress("0x00"),
Nonce: Nonce(0),
Balance: big.NewInt(0),
}
v, err = account.HashValue()
assert.NoError(t, err)
@ -269,11 +269,11 @@ func TestAccountHashValueTestVectors(t *testing.T) {
require.NoError(t, err)
bjj = babyjub.PublicKey(*bjjPoint)
account = &Account{
TokenID: 3,
PublicKey: bjj.Compress(),
EthAddr: ethCommon.HexToAddress("0xA3C88ac39A76789437AED31B9608da72e1bbfBF9"),
Nonce: Nonce(129),
Balance: bigFromStr("42000000000000000000", 10),
TokenID: 3,
BJJ: bjj.Compress(),
EthAddr: ethCommon.HexToAddress("0xA3C88ac39A76789437AED31B9608da72e1bbfBF9"),
Nonce: Nonce(129),
Balance: bigFromStr("42000000000000000000", 10),
}
e, err = account.BigInts()
assert.NoError(t, err)
@ -318,11 +318,11 @@ func TestAccountErrNumOverflowNonce(t *testing.T) {
// check limit
account := &Account{
TokenID: TokenID(1),
Nonce: Nonce(math.Pow(2, 40) - 1),
Balance: big.NewInt(1000),
PublicKey: pk.Compress(),
EthAddr: ethCommon.HexToAddress("0xc58d29fA6e86E4FAe04DDcEd660d45BCf3Cb2370"),
TokenID: TokenID(1),
Nonce: Nonce(math.Pow(2, 40) - 1),
Balance: big.NewInt(1000),
BJJ: pk.Compress(),
EthAddr: ethCommon.HexToAddress("0xc58d29fA6e86E4FAe04DDcEd660d45BCf3Cb2370"),
}
_, err = account.Bytes()
assert.NoError(t, err)
@ -345,11 +345,11 @@ func TestAccountErrNumOverflowBalance(t *testing.T) {
// check limit
account := &Account{
TokenID: TokenID(1),
Nonce: Nonce(math.Pow(2, 40) - 1),
Balance: new(big.Int).Sub(new(big.Int).Exp(big.NewInt(2), big.NewInt(192), nil), big.NewInt(1)),
PublicKey: pk.Compress(),
EthAddr: ethCommon.HexToAddress("0xc58d29fA6e86E4FAe04DDcEd660d45BCf3Cb2370"),
TokenID: TokenID(1),
Nonce: Nonce(math.Pow(2, 40) - 1),
Balance: new(big.Int).Sub(new(big.Int).Exp(big.NewInt(2), big.NewInt(192), nil), big.NewInt(1)),
BJJ: pk.Compress(),
EthAddr: ethCommon.HexToAddress("0xc58d29fA6e86E4FAe04DDcEd660d45BCf3Cb2370"),
}
assert.Equal(t, "6277101735386680763835789423207666416102355444464034512895", account.Balance.String())

+ 1
- 1
db/statedb/statedb.go

@ -220,7 +220,7 @@ func (s *StateDB) CreateAccount(idx common.Idx, account *common.Account) (*merkl
return cpp, tracerr.Wrap(err)
}
// store idx by EthAddr & BJJ
err = s.setIdxByEthAddrBJJ(idx, account.EthAddr, account.PublicKey, account.TokenID)
err = s.setIdxByEthAddrBJJ(idx, account.EthAddr, account.BJJ, account.TokenID)
return cpp, tracerr.Wrap(err)
}

+ 30
- 30
db/statedb/statedb_test.go

@ -31,12 +31,12 @@ func newAccount(t *testing.T, i int) *common.Account {
address := ethCrypto.PubkeyToAddress(key.PublicKey)
return &common.Account{
Idx: common.Idx(256 + i),
TokenID: common.TokenID(i),
Nonce: common.Nonce(i),
Balance: big.NewInt(1000),
PublicKey: pk.Compress(),
EthAddr: address,
Idx: common.Idx(256 + i),
TokenID: common.TokenID(i),
Nonce: common.Nonce(i),
Balance: big.NewInt(1000),
BJJ: pk.Compress(),
EthAddr: address,
}
}
@ -433,36 +433,36 @@ func TestCheckAccountsTreeTestVectors(t *testing.T) {
bjj3 := babyjub.PublicKeyComp(bjjPoint3Comp)
accounts := []*common.Account{
{
Idx: 1,
TokenID: 0xFFFFFFFF,
PublicKey: bjj0,
EthAddr: ethCommon.HexToAddress("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"),
Nonce: common.Nonce(0xFFFFFFFFFF),
Balance: bigFromStr("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16),
Idx: 1,
TokenID: 0xFFFFFFFF,
BJJ: bjj0,
EthAddr: ethCommon.HexToAddress("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"),
Nonce: common.Nonce(0xFFFFFFFFFF),
Balance: bigFromStr("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16),
},
{
Idx: 100,
TokenID: 0,
PublicKey: bjj1,
EthAddr: ethCommon.HexToAddress("0x00"),
Nonce: common.Nonce(0),
Balance: bigFromStr("0", 10),
Idx: 100,
TokenID: 0,
BJJ: bjj1,
EthAddr: ethCommon.HexToAddress("0x00"),
Nonce: common.Nonce(0),
Balance: bigFromStr("0", 10),
},
{
Idx: 0xFFFFFFFFFFFF,
TokenID: 3,
PublicKey: bjj2,
EthAddr: ethCommon.HexToAddress("0xA3C88ac39A76789437AED31B9608da72e1bbfBF9"),
Nonce: common.Nonce(129),
Balance: bigFromStr("42000000000000000000", 10),
Idx: 0xFFFFFFFFFFFF,
TokenID: 3,
BJJ: bjj2,
EthAddr: ethCommon.HexToAddress("0xA3C88ac39A76789437AED31B9608da72e1bbfBF9"),
Nonce: common.Nonce(129),
Balance: bigFromStr("42000000000000000000", 10),
},
{
Idx: 10000,
TokenID: 1000,
PublicKey: bjj3,
EthAddr: ethCommon.HexToAddress("0x64"),
Nonce: common.Nonce(1900),
Balance: bigFromStr("14000000000000000000", 10),
Idx: 10000,
TokenID: 1000,
BJJ: bjj3,
EthAddr: ethCommon.HexToAddress("0x64"),
Nonce: common.Nonce(1900),
Balance: bigFromStr("14000000000000000000", 10),
},
}
for i := 0; i < len(accounts); i++ {

+ 1
- 1
synchronizer/synchronizer_test.go

@ -252,7 +252,7 @@ func assertEqualAccountsHistoryDBStateDB(t *testing.T, hdbAccs, sdbAccs []common
assert.Equal(t, hdbAcc.Idx, sdbAcc.Idx)
assert.Equal(t, hdbAcc.TokenID, sdbAcc.TokenID)
assert.Equal(t, hdbAcc.EthAddr, sdbAcc.EthAddr)
assert.Equal(t, hdbAcc.PublicKey, sdbAcc.PublicKey)
assert.Equal(t, hdbAcc.BJJ, sdbAcc.BJJ)
}
}

+ 6
- 6
test/debugapi/debugapi_test.go

@ -31,12 +31,12 @@ func newAccount(t *testing.T, i int) *common.Account {
address := ethCrypto.PubkeyToAddress(key.PublicKey)
return &common.Account{
Idx: common.Idx(256 + i),
TokenID: common.TokenID(i),
Nonce: common.Nonce(i),
Balance: big.NewInt(1000),
PublicKey: pk.Compress(),
EthAddr: address,
Idx: common.Idx(256 + i),
TokenID: common.TokenID(i),
Nonce: common.Nonce(i),
Balance: big.NewInt(1000),
BJJ: pk.Compress(),
EthAddr: address,
}
}

+ 8
- 8
test/historydb.go

@ -126,12 +126,12 @@ func GenAccounts(totalAccounts, userAccounts int, tokens []common.Token, userAdd
pubK = privK.Public()
}
accs = append(accs, common.Account{
Idx: common.Idx(i),
TokenID: tokens[i%len(tokens)].TokenID,
EthAddr: addr,
BatchNum: batches[i%len(batches)].BatchNum,
PublicKey: pubK.Compress(),
Balance: big.NewInt(int64(i * 10000000)), //nolint:gomnd
Idx: common.Idx(i),
TokenID: tokens[i%len(tokens)].TokenID,
EthAddr: addr,
BatchNum: batches[i%len(batches)].BatchNum,
BJJ: pubK.Compress(),
Balance: big.NewInt(int64(i * 10000000)), //nolint:gomnd
})
}
return accs
@ -243,7 +243,7 @@ func setFromToAndAppend(
}
tx.FromIdx = from.Idx
tx.FromEthAddr = from.EthAddr
tx.FromBJJ = from.PublicKey
tx.FromBJJ = from.BJJ
tx.ToIdx = to.Idx
*userTxs = append(*userTxs, tx)
} else {
@ -257,7 +257,7 @@ func setFromToAndAppend(
}
tx.FromIdx = from.Idx
tx.FromEthAddr = from.EthAddr
tx.FromBJJ = from.PublicKey
tx.FromBJJ = from.BJJ
tx.ToIdx = to.Idx
*othersTxs = append(*othersTxs, tx)
}

+ 7
- 7
test/til/txs.go

@ -854,13 +854,13 @@ func (tc *Context) FillBlocksExtra(blocks []common.BlockData, cfg *ConfigExtra)
}
batch.CreatedAccounts = append(batch.CreatedAccounts,
common.Account{
Idx: common.Idx(tc.extra.idx),
TokenID: tx.TokenID,
BatchNum: batch.Batch.BatchNum,
PublicKey: user.BJJ.Public().Compress(),
EthAddr: user.Addr,
Nonce: 0,
Balance: big.NewInt(0),
Idx: common.Idx(tc.extra.idx),
TokenID: tx.TokenID,
BatchNum: batch.Batch.BatchNum,
BJJ: user.BJJ.Public().Compress(),
EthAddr: user.Addr,
Nonce: 0,
Balance: big.NewInt(0),
})
tc.extra.idx++
}

+ 25
- 25
txprocessor/txprocessor.go

@ -329,7 +329,7 @@ func (tp *TxProcessor) ProcessTxs(coordIdxs []common.Idx, l1usertxs, l1coordinat
if tp.zki != nil {
tp.zki.TokenID3[iFee] = accCoord.TokenID.BigInt()
tp.zki.Nonce3[iFee] = accCoord.Nonce.BigInt()
coordBJJSign, coordBJJY := babyjub.UnpackSignY(accCoord.PublicKey)
coordBJJSign, coordBJJY := babyjub.UnpackSignY(accCoord.BJJ)
if coordBJJSign {
tp.zki.Sign3[iFee] = big.NewInt(1)
}
@ -402,7 +402,7 @@ func (tp *TxProcessor) ProcessTxs(coordIdxs []common.Idx, l1usertxs, l1coordinat
}
// compute last ZKInputs parameters
tp.zki.GlobalChainID = big.NewInt(0) // TODO, 0: ethereum, this will be get from config file
tp.zki.GlobalChainID = big.NewInt(int64(tp.config.ChainID))
tp.zki.Metadata.NewStateRootRaw = tp.s.MT.Root()
tp.zki.Metadata.NewExitRootRaw = exitTree.Root()
@ -666,11 +666,11 @@ func (tp *TxProcessor) ProcessL2Tx(coordIdxsMap map[common.TokenID]common.Idx,
// stores the deposit value
func (tp *TxProcessor) applyCreateAccount(tx *common.L1Tx) error {
account := &common.Account{
TokenID: tx.TokenID,
Nonce: 0,
Balance: tx.EffectiveDepositAmount,
PublicKey: tx.FromBJJ,
EthAddr: tx.FromEthAddr,
TokenID: tx.TokenID,
Nonce: 0,
Balance: tx.EffectiveDepositAmount,
BJJ: tx.FromBJJ,
EthAddr: tx.FromEthAddr,
}
p, err := tp.s.CreateAccount(common.Idx(tp.s.CurrentIdx()+1), account)
@ -720,7 +720,7 @@ func (tp *TxProcessor) applyDeposit(tx *common.L1Tx, transfer bool) error {
if tp.zki != nil {
tp.zki.TokenID1[tp.i] = accSender.TokenID.BigInt()
tp.zki.Nonce1[tp.i] = accSender.Nonce.BigInt()
senderBJJSign, senderBJJY := babyjub.UnpackSignY(accSender.PublicKey)
senderBJJSign, senderBJJY := babyjub.UnpackSignY(accSender.BJJ)
if senderBJJSign {
tp.zki.Sign1[tp.i] = big.NewInt(1)
}
@ -759,7 +759,7 @@ func (tp *TxProcessor) applyDeposit(tx *common.L1Tx, transfer bool) error {
if tp.zki != nil {
tp.zki.TokenID2[tp.i] = accReceiver.TokenID.BigInt()
tp.zki.Nonce2[tp.i] = accReceiver.Nonce.BigInt()
receiverBJJSign, receiverBJJY := babyjub.UnpackSignY(accReceiver.PublicKey)
receiverBJJSign, receiverBJJY := babyjub.UnpackSignY(accReceiver.BJJ)
if receiverBJJSign {
tp.zki.Sign2[tp.i] = big.NewInt(1)
}
@ -807,7 +807,7 @@ func (tp *TxProcessor) applyTransfer(coordIdxsMap map[common.TokenID]common.Idx,
// Set the State1 before updating the Sender leaf
tp.zki.TokenID1[tp.i] = accSender.TokenID.BigInt()
tp.zki.Nonce1[tp.i] = accSender.Nonce.BigInt()
senderBJJSign, senderBJJY := babyjub.UnpackSignY(accSender.PublicKey)
senderBJJSign, senderBJJY := babyjub.UnpackSignY(accSender.BJJ)
if senderBJJSign {
tp.zki.Sign1[tp.i] = big.NewInt(1)
}
@ -875,7 +875,7 @@ func (tp *TxProcessor) applyTransfer(coordIdxsMap map[common.TokenID]common.Idx,
// Set the State2 before updating the Receiver leaf
tp.zki.TokenID2[tp.i] = accReceiver.TokenID.BigInt()
tp.zki.Nonce2[tp.i] = accReceiver.Nonce.BigInt()
receiverBJJSign, receiverBJJY := babyjub.UnpackSignY(accReceiver.PublicKey)
receiverBJJSign, receiverBJJY := babyjub.UnpackSignY(accReceiver.BJJ)
if receiverBJJSign {
tp.zki.Sign2[tp.i] = big.NewInt(1)
}
@ -904,11 +904,11 @@ func (tp *TxProcessor) applyTransfer(coordIdxsMap map[common.TokenID]common.Idx,
func (tp *TxProcessor) applyCreateAccountDepositTransfer(tx *common.L1Tx) error {
auxFromIdx := common.Idx(tp.s.CurrentIdx() + 1)
accSender := &common.Account{
TokenID: tx.TokenID,
Nonce: 0,
Balance: tx.EffectiveDepositAmount,
PublicKey: tx.FromBJJ,
EthAddr: tx.FromEthAddr,
TokenID: tx.TokenID,
Nonce: 0,
Balance: tx.EffectiveDepositAmount,
BJJ: tx.FromBJJ,
EthAddr: tx.FromEthAddr,
}
if tp.zki != nil {
@ -963,7 +963,7 @@ func (tp *TxProcessor) applyCreateAccountDepositTransfer(tx *common.L1Tx) error
// Set the State2 before updating the Receiver leaf
tp.zki.TokenID2[tp.i] = accReceiver.TokenID.BigInt()
tp.zki.Nonce2[tp.i] = accReceiver.Nonce.BigInt()
receiverBJJSign, receiverBJJY := babyjub.UnpackSignY(accReceiver.PublicKey)
receiverBJJSign, receiverBJJY := babyjub.UnpackSignY(accReceiver.BJJ)
if receiverBJJSign {
tp.zki.Sign2[tp.i] = big.NewInt(1)
}
@ -1001,7 +1001,7 @@ func (tp *TxProcessor) applyExit(coordIdxsMap map[common.TokenID]common.Idx,
if tp.zki != nil {
tp.zki.TokenID1[tp.i] = acc.TokenID.BigInt()
tp.zki.Nonce1[tp.i] = acc.Nonce.BigInt()
accBJJSign, accBJJY := babyjub.UnpackSignY(acc.PublicKey)
accBJJSign, accBJJY := babyjub.UnpackSignY(acc.BJJ)
if accBJJSign {
tp.zki.Sign1[tp.i] = big.NewInt(1)
}
@ -1063,17 +1063,17 @@ func (tp *TxProcessor) applyExit(coordIdxsMap map[common.TokenID]common.Idx,
// add new leaf 'ExitTreeLeaf', where ExitTreeLeaf.Balance =
// exitAmount (exitAmount=tx.Amount)
exitAccount := &common.Account{
TokenID: acc.TokenID,
Nonce: common.Nonce(0),
Balance: tx.Amount,
PublicKey: acc.PublicKey,
EthAddr: acc.EthAddr,
TokenID: acc.TokenID,
Nonce: common.Nonce(0),
Balance: tx.Amount,
BJJ: acc.BJJ,
EthAddr: acc.EthAddr,
}
if tp.zki != nil {
// Set the State2 before creating the Exit leaf
tp.zki.TokenID2[tp.i] = acc.TokenID.BigInt()
tp.zki.Nonce2[tp.i] = big.NewInt(0)
accBJJSign, accBJJY := babyjub.UnpackSignY(acc.PublicKey)
accBJJSign, accBJJY := babyjub.UnpackSignY(acc.BJJ)
if accBJJSign {
tp.zki.Sign2[tp.i] = big.NewInt(1)
}
@ -1104,7 +1104,7 @@ func (tp *TxProcessor) applyExit(coordIdxsMap map[common.TokenID]common.Idx,
// Set the State2 before updating the Exit leaf
tp.zki.TokenID2[tp.i] = acc.TokenID.BigInt()
tp.zki.Nonce2[tp.i] = big.NewInt(0)
accBJJSign, accBJJY := babyjub.UnpackSignY(acc.PublicKey)
accBJJSign, accBJJY := babyjub.UnpackSignY(acc.BJJ)
if accBJJSign {
tp.zki.Sign2[tp.i] = big.NewInt(1)
}

+ 20
- 20
txprocessor/zkinputsgen_test.go

@ -129,7 +129,7 @@ func TestZKInputsHashTestVector0(t *testing.T) {
// check expected account keys values from tx inputs
acc, err := sdb.GetAccount(common.Idx(256))
require.NoError(t, err)
assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.PublicKey.String())
assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.BJJ.String())
assert.Equal(t, users[0].Addr.Hex(), acc.EthAddr.Hex())
// check that there no exist more accounts
@ -218,11 +218,11 @@ func TestZKInputsHashTestVector1(t *testing.T) {
// check expected account keys values from tx inputs
acc, err := sdb.GetAccount(common.Idx(256))
require.NoError(t, err)
assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.PublicKey.String())
assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.BJJ.String())
assert.Equal(t, users[0].Addr.Hex(), acc.EthAddr.Hex())
acc, err = sdb.GetAccount(common.Idx(257))
require.NoError(t, err)
assert.Equal(t, users[1].BJJ.Public().Compress().String(), acc.PublicKey.String())
assert.Equal(t, users[1].BJJ.Public().Compress().String(), acc.BJJ.String())
assert.Equal(t, users[1].Addr.Hex(), acc.EthAddr.Hex())
// check that there no exist more accounts
@ -464,7 +464,7 @@ func TestZKInputs0(t *testing.T) {
// check expected account keys values from tx inputs
acc, err := sdb.GetAccount(common.Idx(256))
require.NoError(t, err)
assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.PublicKey.String())
assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.BJJ.String())
assert.Equal(t, users[0].Addr.Hex(), acc.EthAddr.Hex())
// check that there no exist more accounts
@ -567,12 +567,12 @@ func TestZKInputs1(t *testing.T) {
// check expected account keys values from tx inputs
acc, err := sdb.GetAccount(common.Idx(256))
require.NoError(t, err)
assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.PublicKey.String())
assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.BJJ.String())
assert.Equal(t, users[0].Addr.Hex(), acc.EthAddr.Hex())
assert.Equal(t, "15999899", acc.Balance.String())
acc, err = sdb.GetAccount(common.Idx(257))
require.NoError(t, err)
assert.Equal(t, users[1].BJJ.Public().Compress().String(), acc.PublicKey.String())
assert.Equal(t, users[1].BJJ.Public().Compress().String(), acc.BJJ.String())
assert.Equal(t, users[1].Addr.Hex(), acc.EthAddr.Hex())
assert.Equal(t, "16000101", acc.Balance.String())
@ -706,22 +706,22 @@ func TestZKInputs2(t *testing.T) {
// check expected account keys values from tx inputs
acc, err := sdb.GetAccount(common.Idx(256))
require.NoError(t, err)
assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.PublicKey.String())
assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.BJJ.String())
assert.Equal(t, users[0].Addr.Hex(), acc.EthAddr.Hex())
assert.Equal(t, "15997798", acc.Balance.String())
acc, err = sdb.GetAccount(common.Idx(257))
require.NoError(t, err)
assert.Equal(t, users[1].BJJ.Public().Compress().String(), acc.PublicKey.String())
assert.Equal(t, users[1].BJJ.Public().Compress().String(), acc.BJJ.String())
assert.Equal(t, users[1].Addr.Hex(), acc.EthAddr.Hex())
assert.Equal(t, "16000202", acc.Balance.String())
acc, err = sdb.GetAccount(common.Idx(258))
require.NoError(t, err)
assert.Equal(t, users[2].BJJ.Public().Compress().String(), acc.PublicKey.String())
assert.Equal(t, users[2].BJJ.Public().Compress().String(), acc.BJJ.String())
assert.Equal(t, users[2].Addr.Hex(), acc.EthAddr.Hex())
assert.Equal(t, "16001000", acc.Balance.String())
acc, err = sdb.GetAccount(common.Idx(259))
require.NoError(t, err)
assert.Equal(t, users[3].BJJ.Public().Compress().String(), acc.PublicKey.String())
assert.Equal(t, users[3].BJJ.Public().Compress().String(), acc.BJJ.String())
assert.Equal(t, users[3].Addr.Hex(), acc.EthAddr.Hex())
assert.Equal(t, "16001000", acc.Balance.String())
@ -853,22 +853,22 @@ func TestZKInputs3(t *testing.T) {
// check expected account keys values from tx inputs
acc, err := sdb.GetAccount(common.Idx(256))
require.NoError(t, err)
assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.PublicKey.String())
assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.BJJ.String())
assert.Equal(t, users[0].Addr.Hex(), acc.EthAddr.Hex())
assert.Equal(t, "15997798", acc.Balance.String())
acc, err = sdb.GetAccount(common.Idx(257))
require.NoError(t, err)
assert.Equal(t, users[1].BJJ.Public().Compress().String(), acc.PublicKey.String())
assert.Equal(t, users[1].BJJ.Public().Compress().String(), acc.BJJ.String())
assert.Equal(t, users[1].Addr.Hex(), acc.EthAddr.Hex())
assert.Equal(t, "16000202", acc.Balance.String())
acc, err = sdb.GetAccount(common.Idx(258))
require.NoError(t, err)
assert.Equal(t, users[2].BJJ.Public().Compress().String(), acc.PublicKey.String())
assert.Equal(t, users[2].BJJ.Public().Compress().String(), acc.BJJ.String())
assert.Equal(t, users[2].Addr.Hex(), acc.EthAddr.Hex())
assert.Equal(t, "16002000", acc.Balance.String())
acc, err = sdb.GetAccount(common.Idx(259))
require.NoError(t, err)
assert.Equal(t, users[3].BJJ.Public().Compress().String(), acc.PublicKey.String())
assert.Equal(t, users[3].BJJ.Public().Compress().String(), acc.BJJ.String())
assert.Equal(t, users[3].Addr.Hex(), acc.EthAddr.Hex())
assert.Equal(t, "16000000", acc.Balance.String())
@ -1010,22 +1010,22 @@ func TestZKInputs4(t *testing.T) {
// check expected account keys values from tx inputs
acc, err := sdb.GetAccount(common.Idx(256))
require.NoError(t, err)
assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.PublicKey.String())
assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.BJJ.String())
assert.Equal(t, users[0].Addr.Hex(), acc.EthAddr.Hex())
assert.Equal(t, "15997798", acc.Balance.String())
acc, err = sdb.GetAccount(common.Idx(257))
require.NoError(t, err)
assert.Equal(t, users[1].BJJ.Public().Compress().String(), acc.PublicKey.String())
assert.Equal(t, users[1].BJJ.Public().Compress().String(), acc.BJJ.String())
assert.Equal(t, users[1].Addr.Hex(), acc.EthAddr.Hex())
assert.Equal(t, "16000202", acc.Balance.String())
acc, err = sdb.GetAccount(common.Idx(258))
require.NoError(t, err)
assert.Equal(t, users[2].BJJ.Public().Compress().String(), acc.PublicKey.String())
assert.Equal(t, users[2].BJJ.Public().Compress().String(), acc.BJJ.String())
assert.Equal(t, users[2].Addr.Hex(), acc.EthAddr.Hex())
assert.Equal(t, "32001000", acc.Balance.String())
acc, err = sdb.GetAccount(common.Idx(259))
require.NoError(t, err)
assert.Equal(t, users[3].BJJ.Public().Compress().String(), acc.PublicKey.String())
assert.Equal(t, users[3].BJJ.Public().Compress().String(), acc.BJJ.String())
assert.Equal(t, users[3].Addr.Hex(), acc.EthAddr.Hex())
assert.Equal(t, "16001000", acc.Balance.String())
@ -1149,12 +1149,12 @@ func TestZKInputs5(t *testing.T) {
// check expected account keys values from tx inputs
acc, err := sdb.GetAccount(common.Idx(256))
require.NoError(t, err)
assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.PublicKey.String())
assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.BJJ.String())
assert.Equal(t, users[0].Addr.Hex(), acc.EthAddr.Hex())
assert.Equal(t, "15997798", acc.Balance.String())
acc, err = sdb.GetAccount(common.Idx(257))
require.NoError(t, err)
assert.Equal(t, users[1].BJJ.Public().Compress().String(), acc.PublicKey.String())
assert.Equal(t, users[1].BJJ.Public().Compress().String(), acc.BJJ.String())
assert.Equal(t, users[1].Addr.Hex(), acc.EthAddr.Hex())
assert.Equal(t, "16000202", acc.Balance.String())

+ 2
- 2
txselector/txselector.go

@ -293,10 +293,10 @@ func (txsel *TxSelector) GetL1L2TxSelection(selectionConfig *SelectionConfig,
}
}
if l2Txs[i].ToBJJ != common.EmptyBJJComp {
if l2Txs[i].ToBJJ != receiverAcc.PublicKey {
if l2Txs[i].ToBJJ != receiverAcc.BJJ {
log.Debugw("invalid L2Tx: ToBJJ does not correspond to the Account.BJJ",
"ToIdx", l2Txs[i].ToIdx, "tx.ToEthAddr", l2Txs[i].ToBJJ,
"account.BJJ", receiverAcc.PublicKey)
"account.BJJ", receiverAcc.BJJ)
continue
}
}

Loading…
Cancel
Save