Update AccountCreationAuth & fix auth.HashToSign

- Fix AccountCreationAuth.HashToSign (was using `[]byte("0x...")`, which
uses the bytes of the string. Now uses the bytearray of the compressed
BJJ public key (compatible with js implementation))
- Update AccountCreationAuth to last specification (add to hash
parameters ChainID & HermezAddress)
- Add missing test to AccountCreationAuth
This commit is contained in:
arnaucube
2020-12-23 18:11:53 +01:00
parent e787651ba3
commit 8615a462ab
11 changed files with 95 additions and 36 deletions

View File

@@ -1,6 +1,7 @@
package test
import (
ethCommon "github.com/ethereum/go-ethereum/common"
ethCrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/hermeznetwork/hermez-node/common"
"github.com/iden3/go-iden3-crypto/babyjub"
@@ -66,7 +67,7 @@ func GenPoolTxs(n int, tokens []common.Token) []*common.PoolL2Tx {
}
// GenAuths generates account creation authorizations
func GenAuths(nAuths int) []*common.AccountCreationAuth {
func GenAuths(nAuths int, chainID uint16, hermezContractAddr ethCommon.Address) []*common.AccountCreationAuth {
auths := []*common.AccountCreationAuth{}
for i := 0; i < nAuths; i++ {
// Generate keys
@@ -81,7 +82,7 @@ func GenAuths(nAuths int) []*common.AccountCreationAuth {
BJJ: bjjPrivK.Public().Compress(),
}
// Sign
h, err := auth.HashToSign()
h, err := auth.HashToSign(chainID, hermezContractAddr)
if err != nil {
panic(err)
}

View File

@@ -3,13 +3,17 @@ package test
import (
"testing"
ethCommon "github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert"
)
func TestGenAuths(t *testing.T) {
chainID := uint16(0)
hermezContractAddr := ethCommon.HexToAddress("0xc344E203a046Da13b0B4467EB7B3629D0C99F6E6")
const nAuths = 5
auths := GenAuths(nAuths)
auths := GenAuths(nAuths, chainID, hermezContractAddr)
for _, auth := range auths {
assert.True(t, auth.VerifySignature())
assert.True(t, auth.VerifySignature(chainID, hermezContractAddr))
}
}