mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
mv of babyjub.PublicKey to babyjub.PublicKeyComp
Update usage of `*babyjub.PublicKey` to `babyjub.PublicKeyComp` - when the key is not defined, internally is used `babyjub.EmptyBJJComp`, which is a `[32]byte` of zeroes of type `babyjub.PublicKeyComp` - the API continues returning `nil` when the key is not defined
This commit is contained in:
@@ -35,7 +35,7 @@ func newAccount(t *testing.T, i int) *common.Account {
|
||||
TokenID: common.TokenID(i),
|
||||
Nonce: common.Nonce(i),
|
||||
Balance: big.NewInt(1000),
|
||||
PublicKey: pk,
|
||||
PublicKey: pk.Compress(),
|
||||
EthAddr: address,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -731,14 +731,14 @@ var errTODO = fmt.Errorf("TODO: Not implemented yet")
|
||||
// }
|
||||
|
||||
// RollupL1UserTxERC20Permit is the interface to call the smart contract function
|
||||
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) {
|
||||
func (c *Client) RollupL1UserTxERC20Permit(fromBJJ babyjub.PublicKeyComp, fromIdx int64, depositAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error) {
|
||||
log.Error("TODO")
|
||||
return nil, tracerr.Wrap(errTODO)
|
||||
}
|
||||
|
||||
// RollupL1UserTxERC20ETH sends an L1UserTx to the Rollup.
|
||||
func (c *Client) RollupL1UserTxERC20ETH(
|
||||
fromBJJ *babyjub.PublicKey,
|
||||
fromBJJ babyjub.PublicKeyComp,
|
||||
fromIdx int64,
|
||||
depositAmount *big.Int,
|
||||
amount *big.Int,
|
||||
@@ -826,7 +826,7 @@ func (c *Client) RollupWithdrawCircuit(proofA, proofC [2]*big.Int, proofB [2][2]
|
||||
}
|
||||
|
||||
// RollupWithdrawMerkleProof is the interface to call the smart contract function
|
||||
func (c *Client) RollupWithdrawMerkleProof(babyPubKey *babyjub.PublicKey, tokenID uint32, numExitRoot, idx int64, amount *big.Int, siblings []*big.Int, instantWithdraw bool) (tx *types.Transaction, err error) {
|
||||
func (c *Client) RollupWithdrawMerkleProof(babyPubKey babyjub.PublicKeyComp, tokenID uint32, numExitRoot, idx int64, amount *big.Int, siblings []*big.Int, instantWithdraw bool) (tx *types.Transaction, err error) {
|
||||
c.rw.Lock()
|
||||
defer c.rw.Unlock()
|
||||
cpy := c.nextBlock().copy()
|
||||
@@ -843,6 +843,11 @@ func (c *Client) RollupWithdrawMerkleProof(babyPubKey *babyjub.PublicKey, tokenI
|
||||
}
|
||||
r.State.ExitNullifierMap[numExitRoot][idx] = true
|
||||
|
||||
babyPubKeyDecomp, err := babyPubKey.Decompress()
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
|
||||
type data struct {
|
||||
BabyPubKey *babyjub.PublicKey
|
||||
TokenID uint32
|
||||
@@ -853,7 +858,7 @@ func (c *Client) RollupWithdrawMerkleProof(babyPubKey *babyjub.PublicKey, tokenI
|
||||
InstantWithdraw bool
|
||||
}
|
||||
tx = r.addTransaction(c.newTransaction("withdrawMerkleProof", data{
|
||||
BabyPubKey: babyPubKey,
|
||||
BabyPubKey: babyPubKeyDecomp,
|
||||
TokenID: tokenID,
|
||||
NumExitRoot: numExitRoot,
|
||||
Idx: idx,
|
||||
|
||||
@@ -158,7 +158,7 @@ func TestClientRollup(t *testing.T) {
|
||||
tx := common.L1Tx{
|
||||
FromIdx: 0,
|
||||
FromEthAddr: keys[i].Addr,
|
||||
FromBJJ: keys[i].BJJPublicKey,
|
||||
FromBJJ: keys[i].BJJPublicKey.Compress(),
|
||||
TokenID: common.TokenID(0),
|
||||
Amount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(10 + int64(i)),
|
||||
|
||||
@@ -130,7 +130,7 @@ func GenAccounts(totalAccounts, userAccounts int, tokens []common.Token, userAdd
|
||||
TokenID: tokens[i%len(tokens)].TokenID,
|
||||
EthAddr: addr,
|
||||
BatchNum: batches[i%len(batches)].BatchNum,
|
||||
PublicKey: pubK,
|
||||
PublicKey: pubK.Compress(),
|
||||
Balance: big.NewInt(int64(i * 10000000)), //nolint:gomnd
|
||||
})
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ func GenAuths(nAuths int) []*common.AccountCreationAuth {
|
||||
// Generate auth
|
||||
auth := &common.AccountCreationAuth{
|
||||
EthAddr: ethCrypto.PubkeyToAddress(ethPrivK.PublicKey),
|
||||
BJJ: bjjPrivK.Public(),
|
||||
BJJ: bjjPrivK.Public().Compress(),
|
||||
}
|
||||
// Sign
|
||||
h, err := auth.HashToSign()
|
||||
|
||||
@@ -58,7 +58,7 @@ func TestParseBlockchainTxs(t *testing.T) {
|
||||
|
||||
parser := newParser(strings.NewReader(s))
|
||||
instructions, err := parser.parse()
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 25, len(instructions.instructions))
|
||||
assert.Equal(t, 7, len(instructions.users))
|
||||
|
||||
@@ -92,7 +92,7 @@ func TestParsePoolTxs(t *testing.T) {
|
||||
|
||||
parser := newParser(strings.NewReader(s))
|
||||
instructions, err := parser.parse()
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 5, len(instructions.instructions))
|
||||
assert.Equal(t, 4, len(instructions.users))
|
||||
|
||||
@@ -151,7 +151,7 @@ func TestParseErrors(t *testing.T) {
|
||||
`
|
||||
parser = newParser(strings.NewReader(s))
|
||||
_, err = parser.parse()
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
s = `
|
||||
Type: Blockchain
|
||||
Transfer(1) A-B: 10 (256)
|
||||
|
||||
@@ -11,23 +11,23 @@ import (
|
||||
func TestCompileSetsBase(t *testing.T) {
|
||||
parser := newParser(strings.NewReader(SetBlockchain0))
|
||||
_, err := parser.parse()
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
parser = newParser(strings.NewReader(SetPool0))
|
||||
_, err = parser.parse()
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
|
||||
tc := NewContext(common.RollupConstMaxL1UserTx)
|
||||
_, err = tc.GenerateBlocks(SetBlockchain0)
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
_, err = tc.GeneratePoolL2Txs(SetPool0)
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestCompileSetsMinimumFlow(t *testing.T) {
|
||||
// minimum flow
|
||||
tc := NewContext(common.RollupConstMaxL1UserTx)
|
||||
_, err := tc.GenerateBlocks(SetBlockchainMinimumFlow0)
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
_, err = tc.GeneratePoolL2Txs(SetPoolL2MinimumFlow0)
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
|
||||
}
|
||||
tx := common.L1Tx{
|
||||
FromEthAddr: tc.Users[inst.From].Addr,
|
||||
FromBJJ: tc.Users[inst.From].BJJ.Public(),
|
||||
FromBJJ: tc.Users[inst.From].BJJ.Public().Compress(),
|
||||
TokenID: inst.TokenID,
|
||||
Amount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(0),
|
||||
@@ -220,7 +220,7 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
|
||||
}
|
||||
tx := common.L1Tx{
|
||||
FromEthAddr: tc.Users[inst.From].Addr,
|
||||
FromBJJ: tc.Users[inst.From].BJJ.Public(),
|
||||
FromBJJ: tc.Users[inst.From].BJJ.Public().Compress(),
|
||||
TokenID: inst.TokenID,
|
||||
Amount: big.NewInt(0),
|
||||
DepositAmount: inst.DepositAmount,
|
||||
@@ -498,7 +498,7 @@ func (tc *Context) addToL1UserQueue(tx L1Tx) error {
|
||||
tx.L1Tx.FromIdx = tc.Users[tx.fromIdxName].Accounts[tx.L1Tx.TokenID].Idx
|
||||
}
|
||||
tx.L1Tx.FromEthAddr = tc.Users[tx.fromIdxName].Addr
|
||||
tx.L1Tx.FromBJJ = tc.Users[tx.fromIdxName].BJJ.Public()
|
||||
tx.L1Tx.FromBJJ = tc.Users[tx.fromIdxName].BJJ.Public().Compress()
|
||||
if tx.toIdxName == "" {
|
||||
tx.L1Tx.ToIdx = common.Idx(0)
|
||||
} else {
|
||||
@@ -609,20 +609,20 @@ func (tc *Context) generatePoolL2Txs() ([]common.PoolL2Tx, error) {
|
||||
State: common.PoolL2TxStatePending,
|
||||
Timestamp: time.Now(),
|
||||
RqToEthAddr: common.EmptyAddr,
|
||||
RqToBJJ: nil,
|
||||
RqToBJJ: common.EmptyBJJComp,
|
||||
Type: inst.Typ,
|
||||
}
|
||||
if tx.Type == common.TxTypeTransfer {
|
||||
tx.ToIdx = tc.Users[inst.To].Accounts[inst.TokenID].Idx
|
||||
tx.ToEthAddr = tc.Users[inst.To].Addr
|
||||
tx.ToBJJ = tc.Users[inst.To].BJJ.Public()
|
||||
tx.ToBJJ = tc.Users[inst.To].BJJ.Public().Compress()
|
||||
} else if tx.Type == common.TxTypeTransferToEthAddr {
|
||||
tx.ToIdx = common.Idx(0)
|
||||
tx.ToEthAddr = tc.Users[inst.To].Addr
|
||||
} else if tx.Type == common.TxTypeTransferToBJJ {
|
||||
tx.ToIdx = common.Idx(0)
|
||||
tx.ToEthAddr = common.FFAddr
|
||||
tx.ToBJJ = tc.Users[inst.To].BJJ.Public()
|
||||
tx.ToBJJ = tc.Users[inst.To].BJJ.Public().Compress()
|
||||
}
|
||||
nTx, err := common.NewPoolL2Tx(&tx)
|
||||
if err != nil {
|
||||
@@ -844,7 +844,7 @@ func (tc *Context) FillBlocksExtra(blocks []common.BlockData, cfg *ConfigExtra)
|
||||
Idx: common.Idx(tc.extra.idx),
|
||||
TokenID: tx.TokenID,
|
||||
BatchNum: batch.Batch.BatchNum,
|
||||
PublicKey: user.BJJ.Public(),
|
||||
PublicKey: user.BJJ.Public().Compress(),
|
||||
EthAddr: user.Addr,
|
||||
Nonce: 0,
|
||||
Balance: big.NewInt(0),
|
||||
|
||||
@@ -22,7 +22,7 @@ func TestGenerateBlocksNoBatches(t *testing.T) {
|
||||
`
|
||||
tc := NewContext(common.RollupConstMaxL1UserTx)
|
||||
blocks, err := tc.GenerateBlocks(set)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 1, len(blocks))
|
||||
assert.Equal(t, 0, len(blocks[0].Rollup.Batches))
|
||||
assert.Equal(t, 2, len(blocks[0].Rollup.AddedTokens))
|
||||
@@ -89,7 +89,7 @@ func TestGenerateBlocks(t *testing.T) {
|
||||
`
|
||||
tc := NewContext(common.RollupConstMaxL1UserTx)
|
||||
blocks, err := tc.GenerateBlocks(set)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 2, len(blocks))
|
||||
assert.Equal(t, 5, len(blocks[0].Rollup.Batches))
|
||||
assert.Equal(t, 1, len(blocks[1].Rollup.Batches))
|
||||
@@ -147,7 +147,7 @@ func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxTy
|
||||
assert.Equal(t, tc.Users[from].Accounts[tokenID].Idx, tx.FromIdx)
|
||||
}
|
||||
assert.Equal(t, tc.Users[from].Addr.Hex(), tx.FromEthAddr.Hex())
|
||||
assert.Equal(t, tc.Users[from].BJJ.Public(), tx.FromBJJ)
|
||||
assert.Equal(t, tc.Users[from].BJJ.Public().Compress(), tx.FromBJJ)
|
||||
if tx.ToIdx != common.Idx(0) {
|
||||
assert.Equal(t, tc.Users[to].Accounts[tokenID].Idx, tx.ToIdx)
|
||||
}
|
||||
@@ -193,7 +193,7 @@ func TestGeneratePoolL2Txs(t *testing.T) {
|
||||
`
|
||||
tc := NewContext(common.RollupConstMaxL1UserTx)
|
||||
_, err := tc.GenerateBlocks(set)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
set = `
|
||||
Type: PoolL2
|
||||
PoolTransfer(1) A-B: 6 (1)
|
||||
@@ -209,7 +209,7 @@ func TestGeneratePoolL2Txs(t *testing.T) {
|
||||
PoolTransferToBJJ(1) A-B: 1 (1)
|
||||
`
|
||||
poolL2Txs, err := tc.GeneratePoolL2Txs(set)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 11, len(poolL2Txs))
|
||||
assert.Equal(t, common.TxTypeTransfer, poolL2Txs[0].Type)
|
||||
assert.Equal(t, common.TxTypeExit, poolL2Txs[8].Type)
|
||||
@@ -223,7 +223,7 @@ func TestGeneratePoolL2Txs(t *testing.T) {
|
||||
assert.Equal(t, common.Nonce(3), poolL2Txs[8].Nonce)
|
||||
|
||||
assert.Equal(t, tc.Users["B"].Addr.Hex(), poolL2Txs[9].ToEthAddr.Hex())
|
||||
assert.Nil(t, poolL2Txs[9].ToBJJ)
|
||||
assert.Equal(t, common.EmptyBJJComp, poolL2Txs[9].ToBJJ)
|
||||
assert.Equal(t, common.TxTypeTransferToEthAddr, poolL2Txs[9].Type)
|
||||
assert.Equal(t, common.FFAddr, poolL2Txs[10].ToEthAddr)
|
||||
assert.Equal(t, tc.Users["B"].BJJ.Public().String(), poolL2Txs[10].ToBJJ.String())
|
||||
@@ -237,7 +237,7 @@ func TestGeneratePoolL2Txs(t *testing.T) {
|
||||
PoolTransfer(1) A-C: 3 (1)
|
||||
`
|
||||
poolL2Txs, err = tc.GeneratePoolL2Txs(set)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, common.Nonce(6), poolL2Txs[0].Nonce)
|
||||
assert.Equal(t, common.Nonce(2), poolL2Txs[1].Nonce)
|
||||
assert.Equal(t, common.Nonce(7), poolL2Txs[2].Nonce)
|
||||
@@ -253,14 +253,14 @@ func TestGeneratePoolL2Txs(t *testing.T) {
|
||||
`
|
||||
tc = NewContext(common.RollupConstMaxL1UserTx)
|
||||
_, err = tc.GenerateBlocks(set)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
set = `
|
||||
Type: PoolL2
|
||||
PoolTransferToEthAddr(1) A-B: 3 (1)
|
||||
PoolTransferToBJJ(1) A-C: 3 (1)
|
||||
`
|
||||
_, err = tc.GeneratePoolL2Txs(set)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
// expect error, as FromIdx=B is still not created for TokenID=1
|
||||
set = `
|
||||
Type: PoolL2
|
||||
@@ -284,7 +284,7 @@ func TestGeneratePoolL2TxsFromInstructions(t *testing.T) {
|
||||
`
|
||||
tc := NewContext(common.RollupConstMaxL1UserTx)
|
||||
_, err := tc.GenerateBlocks(set)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Generate Pool txs using instructions
|
||||
instructionSet := []Instruction{}
|
||||
@@ -312,18 +312,18 @@ func TestGeneratePoolL2TxsFromInstructions(t *testing.T) {
|
||||
Fee: 1,
|
||||
})
|
||||
txsFromInstructions, err := tc.GeneratePoolL2TxsFromInstructions(instructionSet)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
// Generate Pool txs using string
|
||||
tc = NewContext(common.RollupConstMaxL1UserTx)
|
||||
_, err = tc.GenerateBlocks(set)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
stringSet := `
|
||||
Type: PoolL2
|
||||
PoolTransferToEthAddr(1) B-A: 3 (1)
|
||||
PoolTransferToBJJ(1) B-A: 3 (1)
|
||||
`
|
||||
txsFromString, err := tc.GeneratePoolL2Txs(stringSet)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
// Compare generated txs from instructions and string
|
||||
// timestamps will be different
|
||||
for i := 0; i < len(txsFromString); i++ {
|
||||
@@ -396,7 +396,7 @@ func TestGenerateErrors(t *testing.T) {
|
||||
`
|
||||
tc = NewContext(common.RollupConstMaxL1UserTx)
|
||||
_, err = tc.GenerateBlocks(set)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// check nonces
|
||||
set = `
|
||||
@@ -414,7 +414,7 @@ func TestGenerateErrors(t *testing.T) {
|
||||
`
|
||||
tc = NewContext(common.RollupConstMaxL1UserTx)
|
||||
_, err = tc.GenerateBlocks(set)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, common.Nonce(3), tc.Users["A"].Accounts[common.TokenID(1)].Nonce)
|
||||
assert.Equal(t, common.Idx(256), tc.Users["A"].Accounts[common.TokenID(1)].Idx)
|
||||
assert.Equal(t, common.Nonce(1), tc.Users["B"].Accounts[common.TokenID(1)].Nonce)
|
||||
@@ -520,8 +520,7 @@ func TestGenerateFromInstructions(t *testing.T) {
|
||||
|
||||
tc := NewContext(common.RollupConstMaxL1UserTx)
|
||||
blockFromInstructions, err := tc.GenerateBlocksFromInstructions(setInst)
|
||||
assert.NoError(t, err)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Generate block from string
|
||||
setString := `
|
||||
@@ -540,7 +539,7 @@ func TestGenerateFromInstructions(t *testing.T) {
|
||||
`
|
||||
tc = NewContext(common.RollupConstMaxL1UserTx)
|
||||
blockFromString, err := tc.GenerateBlocks(setString)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Generated data should be equivalent, except for Eth Addrs and BJJs
|
||||
for i, strBatch := range blockFromString[0].Rollup.Batches {
|
||||
|
||||
Reference in New Issue
Block a user