diff --git a/api/account_test.go b/api/account_test.go index 80c325b..9faa25d 100644 --- a/api/account_test.go +++ b/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), diff --git a/api/exits_test.go b/api/exits_test.go index 47fa1c3..6cf3376 100644 --- a/api/exits_test.go +++ b/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(), diff --git a/api/txshistory_test.go b/api/txshistory_test.go index 5f8dfe0..1344ab7 100644 --- a/api/txshistory_test.go +++ b/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 } diff --git a/api/txspool.go b/api/txspool.go index bc163f9..8f86d31 100644 --- a/api/txspool.go +++ b/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 diff --git a/api/txspool_test.go b/api/txspool_test.go index 1c0cf34..4973054 100644 --- a/api/txspool_test.go +++ b/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 { diff --git a/common/account.go b/common/account.go index 6b4186d..737b6da 100644 --- a/common/account.go +++ b/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 } diff --git a/common/account_test.go b/common/account_test.go index 3b041cf..14b5671 100644 --- a/common/account_test.go +++ b/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()) diff --git a/db/statedb/statedb.go b/db/statedb/statedb.go index bbbf0d0..eb12e01 100644 --- a/db/statedb/statedb.go +++ b/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) } diff --git a/db/statedb/statedb_test.go b/db/statedb/statedb_test.go index 5d0b048..22bb45e 100644 --- a/db/statedb/statedb_test.go +++ b/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++ { diff --git a/synchronizer/synchronizer_test.go b/synchronizer/synchronizer_test.go index 81fec78..e64b53b 100644 --- a/synchronizer/synchronizer_test.go +++ b/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) } } diff --git a/test/debugapi/debugapi_test.go b/test/debugapi/debugapi_test.go index cf6b04d..09498d0 100644 --- a/test/debugapi/debugapi_test.go +++ b/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, } } diff --git a/test/historydb.go b/test/historydb.go index 725f71c..861eb3b 100644 --- a/test/historydb.go +++ b/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) } diff --git a/test/til/txs.go b/test/til/txs.go index 67d1c68..b4df3bd 100644 --- a/test/til/txs.go +++ b/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++ } diff --git a/txprocessor/txprocessor.go b/txprocessor/txprocessor.go index 9a37cf0..9dc4944 100644 --- a/txprocessor/txprocessor.go +++ b/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) } diff --git a/txprocessor/zkinputsgen_test.go b/txprocessor/zkinputsgen_test.go index 56c87a6..0c7ab8f 100644 --- a/txprocessor/zkinputsgen_test.go +++ b/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()) diff --git a/txselector/txselector.go b/txselector/txselector.go index 9186eed..87d77e0 100644 --- a/txselector/txselector.go +++ b/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 } }