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:
arnaucube
2020-12-18 17:19:07 +01:00
parent b9943182b8
commit 4b10549822
47 changed files with 761 additions and 733 deletions

View File

@@ -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)

View File

@@ -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)
}

View File

@@ -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),

View File

@@ -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 {