diff --git a/.docker/wallets/wallet1.json b/.docker/wallets/wallet1.json index 27a48a3ed..1141c9777 100644 --- a/.docker/wallets/wallet1.json +++ b/.docker/wallets/wallet1.json @@ -2,11 +2,11 @@ "version": "3.0", "accounts": [ { - "address": "NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc", - "key": "6PYN7LvaWqBNw7Xb7a52LSbPnP91kyuzYi3HncGvQwQoYAY2W8DncTgpux", + "address": "NTh9TnZTstvAePEYWDGLLxidBikJE24uTo", + "key": "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL", "label": "", "contract": { - "script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcILQZVEDXg=", + "script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcJBdHR2qg==", "parameters": [ { "name": "parameter0", @@ -20,7 +20,7 @@ }, { "address": "NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY", - "key": "6PYN7LvaWqBNw7Xb7a52LSbPnP91kyuzYi3HncGvQwQoYAY2W8DncTgpux", + "key": "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL", "label": "", "contract": { "script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBE43vrw==", diff --git a/.docker/wallets/wallet1_solo.json b/.docker/wallets/wallet1_solo.json index 1612925d6..da7a6d01e 100644 --- a/.docker/wallets/wallet1_solo.json +++ b/.docker/wallets/wallet1_solo.json @@ -2,11 +2,11 @@ "version": "3.0", "accounts": [ { - "address": "NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc", - "key": "6PYN7LvaWqBNw7Xb7a52LSbPnP91kyuzYi3HncGvQwQoYAY2W8DncTgpux", + "address": "NTh9TnZTstvAePEYWDGLLxidBikJE24uTo", + "key": "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL", "label": "", "contract": { - "script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcILQZVEDXg=", + "script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcJBdHR2qg==", "parameters": [ { "name": "parameter0", @@ -20,7 +20,7 @@ }, { "address": "NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY", - "key": "6PYN7LvaWqBNw7Xb7a52LSbPnP91kyuzYi3HncGvQwQoYAY2W8DncTgpux", + "key": "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL", "label": "", "contract": { "script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBE43vrw==", @@ -45,7 +45,7 @@ }, { "address": "NVNvVRW5Q5naSx2k2iZm7xRgtRNGuZppAK", - "key": "6PYN7LvaWqBNw7Xb7a52LSbPnP91kyuzYi3HncGvQwQoYAY2W8DncTgpux", + "key": "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL", "label": "", "contract": { "script": "EQwhArNiK/QBe9/jF8WK7V9MdT8ga324lgRvp9d0u8S/f43CEQtBE43vrw==", diff --git a/.docker/wallets/wallet2.json b/.docker/wallets/wallet2.json index 11b12bf5a..35284cba6 100644 --- a/.docker/wallets/wallet2.json +++ b/.docker/wallets/wallet2.json @@ -2,11 +2,11 @@ "version": "3.0", "accounts": [ { - "address": "NWvKSwutC8D6VKmmPxAEgFKx2NLvFhn8q5", - "key": "6PYKEHagXJ3mDLdga1FoyTGRtPdJgPz6Gb8sjEFwZvRu7ncD9PVZfHtMzL", + "address": "NUREbqw2kfbPgDeEz8Dac2QxntGGqqFMm7", + "key": "6PYXADog3RQCwKRhqQsobwZEFopdcCJuMfPosM9pXPaDWSguKvznLdpADk", "label": "", "contract": { - "script": "DCECEDp/fdAWVYWX95YNJ8UWpDlP2Wi55lFV60sBPkBAQG4LQZVEDXg=", + "script": "DCECEDp/fdAWVYWX95YNJ8UWpDlP2Wi55lFV60sBPkBAQG5BdHR2qg==", "parameters": [ { "name": "parameter0", @@ -20,7 +20,7 @@ }, { "address": "NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY", - "key": "6PYKEHagXJ3mDLdga1FoyTGRtPdJgPz6Gb8sjEFwZvRu7ncD9PVZfHtMzL", + "key": "6PYXADog3RQCwKRhqQsobwZEFopdcCJuMfPosM9pXPaDWSguKvznLdpADk", "label": "", "contract": { "script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBE43vrw==", diff --git a/.docker/wallets/wallet3.json b/.docker/wallets/wallet3.json index e4dd102f7..6369f8030 100644 --- a/.docker/wallets/wallet3.json +++ b/.docker/wallets/wallet3.json @@ -2,11 +2,11 @@ "version": "3.0", "accounts": [ { - "address": "NNB3RsnTABEwoKEudNG92njds91WtiCuxd", - "key": "6PYLjn1Zw3RQmP3CkDxoZvYtMpu7ZUdjHnvu7wPuohUcXWCMh9vY661R8A", + "address": "NQP81vKVRmwZHveX8C9Rbf2qejSpT1W1Eu", + "key": "6PYScv3Vgvdi9EkhDNvHXdvQeuaXK9gRwXDmytCswZMNpTzMLvfgR3U5dK", "label": "", "contract": { - "script": "DCED2QwH32PmkM53kS4Qq1GsyUS2aGAje2CMT4+DCece5pkLQZVEDXg=", + "script": "DCED2QwH32PmkM53kS4Qq1GsyUS2aGAje2CMT4+DCece5plBdHR2qg==", "parameters": [ { "name": "parameter0", @@ -20,7 +20,7 @@ }, { "address": "NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY", - "key": "6PYLjn1Zw3RQmP3CkDxoZvYtMpu7ZUdjHnvu7wPuohUcXWCMh9vY661R8A", + "key": "6PYScv3Vgvdi9EkhDNvHXdvQeuaXK9gRwXDmytCswZMNpTzMLvfgR3U5dK", "label": "", "contract": { "script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBE43vrw==", diff --git a/.docker/wallets/wallet4.json b/.docker/wallets/wallet4.json index 2fe62f899..ab3783401 100644 --- a/.docker/wallets/wallet4.json +++ b/.docker/wallets/wallet4.json @@ -2,11 +2,11 @@ "version": "3.0", "accounts": [ { - "address": "Nfzo95iBXfeAGx5rdjPedZRAqHKh9hwMdR", - "key": "6PYLbYYg9jUgzJQpKhpvNExa2UEgtp4356XPg56pHuCpE7gQmj84ESNjYW", + "address": "NLA34vf8eXGGUhRjVaYe5f8YsyYHTehbDZ", + "key": "6PYVwp1Sdg9DfTzvg42PZxgzMDf5a5FYBgT6ynKKzwmSHuhGkipoNjyW3a", "label": "", "contract": { - "script": "DCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWILQZVEDXg=", + "script": "DCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWJBdHR2qg==", "parameters": [ { "name": "parameter0", @@ -20,7 +20,7 @@ }, { "address": "NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY", - "key": "6PYLbYYg9jUgzJQpKhpvNExa2UEgtp4356XPg56pHuCpE7gQmj84ESNjYW", + "key": "6PYVwp1Sdg9DfTzvg42PZxgzMDf5a5FYBgT6ynKKzwmSHuhGkipoNjyW3a", "label": "", "contract": { "script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBE43vrw==", diff --git a/cli/nep17_test.go b/cli/nep17_test.go index 3994b318a..c81d00ef9 100644 --- a/cli/nep17_test.go +++ b/cli/nep17_test.go @@ -51,7 +51,7 @@ func TestNEP17Balance(t *testing.T) { }) t.Run("all accounts", func(t *testing.T) { e.Run(t, cmdbase...) - addr1, err := address.StringToUint160("NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc") + addr1, err := address.StringToUint160("NTh9TnZTstvAePEYWDGLLxidBikJE24uTo") require.NoError(t, err) e.checkNextLine(t, "^Account "+address.Uint160ToString(addr1)) e.checkNextLine(t, "^\\s*GAS:\\s+GasToken \\("+e.Chain.UtilityTokenHash().StringLE()+"\\)") @@ -136,7 +136,7 @@ func TestNEP17Transfer(t *testing.T) { require.Equal(t, big.NewInt(1), b) t.Run("default address", func(t *testing.T) { - const validatorDefault = "NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc" + const validatorDefault = "NTh9TnZTstvAePEYWDGLLxidBikJE24uTo" e.In.WriteString("one\r") e.Run(t, "neo-go", "wallet", "nep17", "multitransfer", "--rpc-endpoint", "http://"+e.RPC.Addr, diff --git a/cli/testdata/chain50x2.acc b/cli/testdata/chain50x2.acc index 02f46c5e4..f40e752f1 100644 Binary files a/cli/testdata/chain50x2.acc and b/cli/testdata/chain50x2.acc differ diff --git a/cli/testdata/testwallet.json b/cli/testdata/testwallet.json index 97b2e913a..e80c00a1f 100644 --- a/cli/testdata/testwallet.json +++ b/cli/testdata/testwallet.json @@ -1 +1,31 @@ -{"version":"3.0","accounts":[{"address":"NNuJqXDnRqvwgzhSzhH4jnVFWB1DyZ34EM","key":"6PYT6enT6eh4gu4ew3Mx58pFFDQNhuR1qQPuU594Eo5u4sA2ZvE4MqJV12","label":"kek","contract":{"script":"DCECl3UyEIq6T5RRIXS6z4tNdZPTzQ7NvXyx7FwK05d9UyYLQZVEDXg=","parameters":[{"name":"parameter0","type":"Signature"}],"deployed":false},"lock":false,"isdefault":false}],"scrypt":{"n":16384,"r":8,"p":8},"extra":{"Tokens":null}} +{ + "version" : "3.0", + "extra" : { + "Tokens" : null + }, + "accounts" : [ + { + "lock" : false, + "isdefault" : false, + "key" : "6PYRjaxsdSrW8zBzPynkC9uJRHpkhFHiQTuYY33gNL1wTimTbpN8S8eCNc", + "address" : "NUSEsqon6PikQA5mDFaV4njemF9Su8JEmf", + "contract" : { + "parameters" : [ + { + "type" : "Signature", + "name" : "parameter0" + } + ], + "script" : "DCECl3UyEIq6T5RRIXS6z4tNdZPTzQ7NvXyx7FwK05d9UyZBdHR2qg==", + "deployed" : false + }, + "label" : "kek" + } + ], + "scrypt" : { + "r" : 8, + "p" : 8, + "n" : 16384 + } +} + diff --git a/cli/testdata/wallet1_solo.json b/cli/testdata/wallet1_solo.json index 050459eb0..5bad532d4 100644 --- a/cli/testdata/wallet1_solo.json +++ b/cli/testdata/wallet1_solo.json @@ -2,11 +2,11 @@ "version": "3.0", "accounts": [ { - "address": "NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc", - "key": "6PYN7LvaWqBNw7Xb7a52LSbPnP91kyuzYi3HncGvQwQoYAY2W8DncTgpux", + "address": "NTh9TnZTstvAePEYWDGLLxidBikJE24uTo", + "key": "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL", "label": "", "contract": { - "script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcILQZVEDXg=", + "script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcJBdHR2qg==", "parameters": [ { "name": "parameter0", @@ -20,7 +20,7 @@ }, { "address": "NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY", - "key": "6PYN7LvaWqBNw7Xb7a52LSbPnP91kyuzYi3HncGvQwQoYAY2W8DncTgpux", + "key": "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL", "label": "", "contract": { "script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBE43vrw==", @@ -45,7 +45,7 @@ }, { "address": "NVNvVRW5Q5naSx2k2iZm7xRgtRNGuZppAK", - "key": "6PYN7LvaWqBNw7Xb7a52LSbPnP91kyuzYi3HncGvQwQoYAY2W8DncTgpux", + "key": "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL", "label": "", "contract": { "script": "EQwhArNiK/QBe9/jF8WK7V9MdT8ga324lgRvp9d0u8S/f43CEQtBE43vrw==", @@ -62,10 +62,10 @@ }, { "address" : "NWTDxsHVde5qSjRkTRUAg6i8xC3JSWEC9k", - "key" : "6PYXDze5Ak4HahYKygcNzk6n65ACjWdDCYLSuKgA5KG8vyMJSFboUNSiPD", + "key" : "6PYSgdjUPVjo3ZJLg2CsheXnEZzyvUuSm4jCtXP6X7FT82sAQHWt2wpu5A", "label" : "", "contract" : { - "script" : "VwEAEUBXAANA", + "script" : "VwMAQS1RCDAhcAwUVVQtU+0PVUb61E1umZEoZwIvzl7bMHFoE87bKGnbKJdA", "deployed" : true, "parameters" : [] }, diff --git a/cli/testdata/wallets/testwallet_NEO3.json b/cli/testdata/wallets/testwallet_NEO3.json index 27a48a3ed..1141c9777 100644 --- a/cli/testdata/wallets/testwallet_NEO3.json +++ b/cli/testdata/wallets/testwallet_NEO3.json @@ -2,11 +2,11 @@ "version": "3.0", "accounts": [ { - "address": "NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc", - "key": "6PYN7LvaWqBNw7Xb7a52LSbPnP91kyuzYi3HncGvQwQoYAY2W8DncTgpux", + "address": "NTh9TnZTstvAePEYWDGLLxidBikJE24uTo", + "key": "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL", "label": "", "contract": { - "script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcILQZVEDXg=", + "script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcJBdHR2qg==", "parameters": [ { "name": "parameter0", @@ -20,7 +20,7 @@ }, { "address": "NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY", - "key": "6PYN7LvaWqBNw7Xb7a52LSbPnP91kyuzYi3HncGvQwQoYAY2W8DncTgpux", + "key": "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL", "label": "", "contract": { "script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBE43vrw==", diff --git a/cli/wallet_test.go b/cli/wallet_test.go index 4ee7e09f2..10ae7d669 100644 --- a/cli/wallet_test.go +++ b/cli/wallet_test.go @@ -318,7 +318,7 @@ func TestWalletDump(t *testing.T) { w := new(wallet.Wallet) require.NoError(t, json.Unmarshal([]byte(rawStr), w)) require.Equal(t, 1, len(w.Accounts)) - require.Equal(t, "NNuJqXDnRqvwgzhSzhH4jnVFWB1DyZ34EM", w.Accounts[0].Address) + require.Equal(t, "NUSEsqon6PikQA5mDFaV4njemF9Su8JEmf", w.Accounts[0].Address) t.Run("with decrypt", func(t *testing.T) { cmd = append(cmd, "--decrypt") @@ -333,7 +333,7 @@ func TestWalletDump(t *testing.T) { w := new(wallet.Wallet) require.NoError(t, json.Unmarshal([]byte(rawStr), w)) require.Equal(t, 1, len(w.Accounts)) - require.Equal(t, "NNuJqXDnRqvwgzhSzhH4jnVFWB1DyZ34EM", w.Accounts[0].Address) + require.Equal(t, "NUSEsqon6PikQA5mDFaV4njemF9Su8JEmf", w.Accounts[0].Address) }) } @@ -343,7 +343,7 @@ func TestDumpKeys(t *testing.T) { pubRegex := "^0[23][a-hA-H0-9]{64}$" t.Run("all", func(t *testing.T) { e.Run(t, cmd...) - e.checkNextLine(t, "NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc") + e.checkNextLine(t, "NTh9TnZTstvAePEYWDGLLxidBikJE24uTo") e.checkNextLine(t, pubRegex) e.checkNextLine(t, "^\\s*$") e.checkNextLine(t, "NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY") @@ -356,7 +356,7 @@ func TestDumpKeys(t *testing.T) { e.checkEOF(t) }) t.Run("simple signature", func(t *testing.T) { - cmd := append(cmd, "--address", "NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc") + cmd := append(cmd, "--address", "NTh9TnZTstvAePEYWDGLLxidBikJE24uTo") e.Run(t, cmd...) e.checkNextLine(t, "simple signature contract") e.checkNextLine(t, pubRegex) diff --git a/internal/keytestcases/testcases.go b/internal/keytestcases/testcases.go index 62f8dc85d..828379151 100644 --- a/internal/keytestcases/testcases.go +++ b/internal/keytestcases/testcases.go @@ -14,36 +14,36 @@ type Ktype struct { // Arr contains a set of known keys in Ktype format. var Arr = []Ktype{ { - Address: "NNWAo5vdVJz1oyCuNiaTBA3amBHnWCF4Yk", + Address: "NQrEVKgpx2qEg6DpVMT5H8kFa7kc2DFgqS", PrivateKey: "7d128a6d096f0c14c3a25a2b0c41cf79661bfcb4a8cc95aaaea28bde4d732344", PublicKey: "02028a99826edc0c97d18e22b6932373d908d323aa7f92656a77ec26e8861699ef", Wif: "L1QqQJnpBwbsPGAuutuzPTac8piqvbR1HRjrY5qHup48TBCBFe4g", Passphrase: "city of zion", - EncryptedWif: "6PYSeMMbJtfMRD81eHzriwrRKquu2dgLNurYcAbmJa7YqAiThgA2vGQu5o", + EncryptedWif: "6PYWaEBMd9UTVFKi1YahYXY5NMLDg9U6w2gpQYUnx8wvaFgdo8EeVPaD7o", }, { - Address: "NiwvMyWYeNghLG8tDyKkWwuZV3wS8CPrrV", + Address: "NYaVsrMV9GS8aaspRS4odXf1WHZdMmJiPC", PrivateKey: "9ab7e154840daca3a2efadaf0df93cd3a5b51768c632f5433f86909d9b994a69", PublicKey: "031d8e1630ce640966967bc6d95223d21f44304133003140c3b52004dc981349c9", Wif: "L2QTooFoDFyRFTxmtiVHt5CfsXfVnexdbENGDkkrrgTTryiLsPMG", Passphrase: "我的密码", - EncryptedWif: "6PYKWKaq5NMyjt8cjvnJnvmV13inhFuePpWZMkddFAMCgjC3ETt7kX16V9", + EncryptedWif: "6PYUpn5uxTpsoawM3YKEWamk2oiKeafQBBK3Vutsowogy8a86jPu71xhE9", }, { - Address: "NTWHAzB82LRGWNuuqjVyyzpGvF3WxbbPoG", + Address: "NWcpK2143ZjgzDYyQJhoKrodJUymHTxPzR", PrivateKey: "3edee7036b8fd9cef91de47386b191dd76db2888a553e7736bb02808932a915b", PublicKey: "02232ce8d2e2063dce0451131851d47421bfc4fc1da4db116fca5302c0756462fa", Wif: "KyKvWLZsNwBJx5j9nurHYRwhYfdQUu9tTEDsLCUHDbYBL8cHxMiG", Passphrase: "MyL33tP@33w0rd", - EncryptedWif: "6PYSzKoJBQMj9uHUv1Sc2ZhMrydqDF8ZCTeE9FuPiNdEx7Lo9NoEuaXeyk", + EncryptedWif: "6PYRbKt55d4NXxCESqk8n9kURqopvixEY5nhAYe2ZJ4c1oDWAjtFX8hd1M", }, { - Address: "xdf4UGKevVrMR1j3UkPsuoYKSC4ocoAkKx", - PrivateKey: "zzdee7036b8fd9cef91de47386b191dd76db2888a553e7736bb02808932a915b", - PublicKey: "zz232ce8d2e2063dce0451131851d47421bfc4fc1da4db116fca5302c0756462fa", - Wif: "zzKvWLZsNwBJx5j9nurHYRwhYfdQUu9tTEDsLCUHDbYBL8cHxMiG", - Passphrase: "zzL33tP@33w0rd", - EncryptedWif: "6PYSzKoJBQMj9uHUv1Sc2ZhMrydqDF8ZCTeE9FuPiNdEx7Lo9NoEuaXeyk", + Address: "NWcpK2143ZjgzDYyQJhoKrodJUymHTxPzR", + PrivateKey: "3edee7036b8fd9cef91de47386b191dd76db2888a553e7736bb02808932a915", + PublicKey: "02232ce8d2e2063dce0451131851d47421bfc4fc1da4db116fca5302c0756462fa", + Wif: "KyKvWLZsNwBJx5j9nurHYRwhYfdQUu9tTEDsLCUHDbYBL8cHxMiS", + Passphrase: "invalid_pass_but_valid_wif", + EncryptedWif: "6PYRbKt55d4NXxCESqk8n9kURqopvixEY5nhAYe2ZJ4c1oDWAjtFX8hd1M", Invalid: true, }, } diff --git a/internal/testchain/transaction.go b/internal/testchain/transaction.go index 8f8a4aa11..d9a42b43f 100644 --- a/internal/testchain/transaction.go +++ b/internal/testchain/transaction.go @@ -49,44 +49,44 @@ func NewTransferFromOwner(bc blockchainer.Blockchainer, contractHash, to util.Ui } // NewDeployTx returns new deployment tx for contract with name with Go code read from r. -func NewDeployTx(bc blockchainer.Blockchainer, name string, sender util.Uint160, r gio.Reader) (*transaction.Transaction, util.Uint160, error) { +func NewDeployTx(bc blockchainer.Blockchainer, name string, sender util.Uint160, r gio.Reader) (*transaction.Transaction, util.Uint160, []byte, error) { // nef.NewFile() cares about version a lot. config.Version = "0.90.0-test" avm, di, err := compiler.CompileWithDebugInfo(name, r) if err != nil { - return nil, util.Uint160{}, err + return nil, util.Uint160{}, nil, err } ne, err := nef.NewFile(avm) if err != nil { - return nil, util.Uint160{}, err + return nil, util.Uint160{}, nil, err } m, err := di.ConvertToManifest(&compiler.Options{Name: name}) if err != nil { - return nil, util.Uint160{}, err + return nil, util.Uint160{}, nil, err } rawManifest, err := json.Marshal(m) if err != nil { - return nil, util.Uint160{}, err + return nil, util.Uint160{}, nil, err } neb, err := ne.Bytes() if err != nil { - return nil, util.Uint160{}, err + return nil, util.Uint160{}, nil, err } buf := io.NewBufBinWriter() emit.AppCall(buf.BinWriter, bc.ManagementContractHash(), "deploy", callflag.All, neb, rawManifest) if buf.Err != nil { - return nil, util.Uint160{}, buf.Err + return nil, util.Uint160{}, nil, buf.Err } tx := transaction.New(Network(), buf.Bytes(), 100*native.GASFactor) tx.Signers = []transaction.Signer{{Account: sender}} h := state.CreateContractHash(tx.Sender(), ne.Checksum, name) - return tx, h, nil + return tx, h, avm, nil } // SignTx signs provided transactions with validator keys. diff --git a/pkg/compiler/syscall_test.go b/pkg/compiler/syscall_test.go index 648267be1..e9598ae9f 100644 --- a/pkg/compiler/syscall_test.go +++ b/pkg/compiler/syscall_test.go @@ -89,8 +89,6 @@ func TestSyscallExecution(t *testing.T) { "storage.GetReadOnlyContext": {interopnames.SystemStorageGetReadOnlyContext, nil, false}, "storage.Put": {interopnames.SystemStoragePut, []string{sctx, b, b}, true}, "storage.ConvertContextToReadOnly": {interopnames.SystemStorageAsReadOnly, []string{sctx}, false}, - "crypto.ECDsaSecp256r1Verify": {interopnames.NeoCryptoVerifyWithECDsaSecp256r1, []string{b, pub, sig}, false}, - "crypto.ECDsaSecp256k1Verify": {interopnames.NeoCryptoVerifyWithECDsaSecp256k1, []string{b, pub, sig}, false}, "crypto.ECDSASecp256r1CheckMultisig": {interopnames.NeoCryptoCheckMultisigWithECDsaSecp256r1, []string{b, pubs, sigs}, false}, "crypto.ECDSASecp256k1CheckMultisig": {interopnames.NeoCryptoCheckMultisigWithECDsaSecp256k1, []string{b, pubs, sigs}, false}, "crypto.CheckSig": {interopnames.NeoCryptoCheckSig, []string{pub, sig}, false}, diff --git a/pkg/compiler/verify_test.go b/pkg/compiler/verify_test.go index a1793fce8..c945d6bfc 100644 --- a/pkg/compiler/verify_test.go +++ b/pkg/compiler/verify_test.go @@ -16,11 +16,10 @@ import ( func TestVerifyGood(t *testing.T) { msg := []byte("test message") pub, sig := signMessage(t, msg) - src := getVerifyProg(pub, sig, msg) + src := getVerifyProg(pub, sig) v, p := vmAndCompileInterop(t, src) - p.interops[interopnames.ToID([]byte(interopnames.NeoCryptoVerifyWithECDsaSecp256r1))] = func(v *vm.VM) error { - assert.Equal(t, msg, v.Estack().Pop().Bytes()) + p.interops[interopnames.ToID([]byte(interopnames.NeoCryptoCheckSig))] = func(v *vm.VM) error { assert.Equal(t, pub, v.Estack().Pop().Bytes()) assert.Equal(t, sig, v.Estack().Pop().Bytes()) v.Estack().PushVal(true) @@ -40,10 +39,9 @@ func signMessage(t *testing.T, msg []byte) ([]byte, []byte) { return pub, sig } -func getVerifyProg(pub, sig, msg []byte) string { +func getVerifyProg(pub, sig []byte) string { pubS := fmt.Sprintf("%#v", pub) sigS := fmt.Sprintf("%#v", sig) - msgS := fmt.Sprintf("%#v", msg) return ` package hello @@ -53,8 +51,7 @@ func getVerifyProg(pub, sig, msg []byte) string { func Main() bool { pub := ` + pubS + ` sig := ` + sigS + ` - msg := ` + msgS + ` - return crypto.ECDsaSecp256r1Verify(msg, pub, sig) + return crypto.CheckSig(pub, sig) } ` } diff --git a/pkg/consensus/testdata/wallet1.json b/pkg/consensus/testdata/wallet1.json index 1612925d6..1141c9777 100644 --- a/pkg/consensus/testdata/wallet1.json +++ b/pkg/consensus/testdata/wallet1.json @@ -2,11 +2,11 @@ "version": "3.0", "accounts": [ { - "address": "NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc", - "key": "6PYN7LvaWqBNw7Xb7a52LSbPnP91kyuzYi3HncGvQwQoYAY2W8DncTgpux", + "address": "NTh9TnZTstvAePEYWDGLLxidBikJE24uTo", + "key": "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL", "label": "", "contract": { - "script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcILQZVEDXg=", + "script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcJBdHR2qg==", "parameters": [ { "name": "parameter0", @@ -20,7 +20,7 @@ }, { "address": "NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY", - "key": "6PYN7LvaWqBNw7Xb7a52LSbPnP91kyuzYi3HncGvQwQoYAY2W8DncTgpux", + "key": "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL", "label": "", "contract": { "script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBE43vrw==", @@ -42,23 +42,6 @@ }, "lock": false, "isdefault": false - }, - { - "address": "NVNvVRW5Q5naSx2k2iZm7xRgtRNGuZppAK", - "key": "6PYN7LvaWqBNw7Xb7a52LSbPnP91kyuzYi3HncGvQwQoYAY2W8DncTgpux", - "label": "", - "contract": { - "script": "EQwhArNiK/QBe9/jF8WK7V9MdT8ga324lgRvp9d0u8S/f43CEQtBE43vrw==", - "parameters": [ - { - "name": "parameter0", - "type": "Signature" - } - ], - "deployed": false - }, - "lock": false, - "isdefault": false } ], "scrypt": { diff --git a/pkg/consensus/testdata/wallet2.json b/pkg/consensus/testdata/wallet2.json index 11b12bf5a..35284cba6 100644 --- a/pkg/consensus/testdata/wallet2.json +++ b/pkg/consensus/testdata/wallet2.json @@ -2,11 +2,11 @@ "version": "3.0", "accounts": [ { - "address": "NWvKSwutC8D6VKmmPxAEgFKx2NLvFhn8q5", - "key": "6PYKEHagXJ3mDLdga1FoyTGRtPdJgPz6Gb8sjEFwZvRu7ncD9PVZfHtMzL", + "address": "NUREbqw2kfbPgDeEz8Dac2QxntGGqqFMm7", + "key": "6PYXADog3RQCwKRhqQsobwZEFopdcCJuMfPosM9pXPaDWSguKvznLdpADk", "label": "", "contract": { - "script": "DCECEDp/fdAWVYWX95YNJ8UWpDlP2Wi55lFV60sBPkBAQG4LQZVEDXg=", + "script": "DCECEDp/fdAWVYWX95YNJ8UWpDlP2Wi55lFV60sBPkBAQG5BdHR2qg==", "parameters": [ { "name": "parameter0", @@ -20,7 +20,7 @@ }, { "address": "NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY", - "key": "6PYKEHagXJ3mDLdga1FoyTGRtPdJgPz6Gb8sjEFwZvRu7ncD9PVZfHtMzL", + "key": "6PYXADog3RQCwKRhqQsobwZEFopdcCJuMfPosM9pXPaDWSguKvznLdpADk", "label": "", "contract": { "script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBE43vrw==", diff --git a/pkg/consensus/testdata/wallet3.json b/pkg/consensus/testdata/wallet3.json index e4dd102f7..6369f8030 100644 --- a/pkg/consensus/testdata/wallet3.json +++ b/pkg/consensus/testdata/wallet3.json @@ -2,11 +2,11 @@ "version": "3.0", "accounts": [ { - "address": "NNB3RsnTABEwoKEudNG92njds91WtiCuxd", - "key": "6PYLjn1Zw3RQmP3CkDxoZvYtMpu7ZUdjHnvu7wPuohUcXWCMh9vY661R8A", + "address": "NQP81vKVRmwZHveX8C9Rbf2qejSpT1W1Eu", + "key": "6PYScv3Vgvdi9EkhDNvHXdvQeuaXK9gRwXDmytCswZMNpTzMLvfgR3U5dK", "label": "", "contract": { - "script": "DCED2QwH32PmkM53kS4Qq1GsyUS2aGAje2CMT4+DCece5pkLQZVEDXg=", + "script": "DCED2QwH32PmkM53kS4Qq1GsyUS2aGAje2CMT4+DCece5plBdHR2qg==", "parameters": [ { "name": "parameter0", @@ -20,7 +20,7 @@ }, { "address": "NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY", - "key": "6PYLjn1Zw3RQmP3CkDxoZvYtMpu7ZUdjHnvu7wPuohUcXWCMh9vY661R8A", + "key": "6PYScv3Vgvdi9EkhDNvHXdvQeuaXK9gRwXDmytCswZMNpTzMLvfgR3U5dK", "label": "", "contract": { "script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBE43vrw==", diff --git a/pkg/consensus/testdata/wallet4.json b/pkg/consensus/testdata/wallet4.json index 2fe62f899..ab3783401 100644 --- a/pkg/consensus/testdata/wallet4.json +++ b/pkg/consensus/testdata/wallet4.json @@ -2,11 +2,11 @@ "version": "3.0", "accounts": [ { - "address": "Nfzo95iBXfeAGx5rdjPedZRAqHKh9hwMdR", - "key": "6PYLbYYg9jUgzJQpKhpvNExa2UEgtp4356XPg56pHuCpE7gQmj84ESNjYW", + "address": "NLA34vf8eXGGUhRjVaYe5f8YsyYHTehbDZ", + "key": "6PYVwp1Sdg9DfTzvg42PZxgzMDf5a5FYBgT6ynKKzwmSHuhGkipoNjyW3a", "label": "", "contract": { - "script": "DCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWILQZVEDXg=", + "script": "DCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWJBdHR2qg==", "parameters": [ { "name": "parameter0", @@ -20,7 +20,7 @@ }, { "address": "NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY", - "key": "6PYLbYYg9jUgzJQpKhpvNExa2UEgtp4356XPg56pHuCpE7gQmj84ESNjYW", + "key": "6PYVwp1Sdg9DfTzvg42PZxgzMDf5a5FYBgT6ynKKzwmSHuhGkipoNjyW3a", "label": "", "contract": { "script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBE43vrw==", diff --git a/pkg/core/blockchain_test.go b/pkg/core/blockchain_test.go index 05e2a27a3..251497e9c 100644 --- a/pkg/core/blockchain_test.go +++ b/pkg/core/blockchain_test.go @@ -1229,7 +1229,7 @@ func TestIsTxStillRelevant(t *testing.T) { currentHeight := contract.Call(addr, "currentIndex", contract.ReadStates) return currentHeight.(int) < %d }`, bc.BlockHeight()+2) // deploy + next block - txDeploy, h, err := testchain.NewDeployTx(bc, "TestVerify", neoOwner, strings.NewReader(src)) + txDeploy, h, _, err := testchain.NewDeployTx(bc, "TestVerify", neoOwner, strings.NewReader(src)) require.NoError(t, err) txDeploy.ValidUntilBlock = bc.BlockHeight() + 1 addSigners(neoOwner, txDeploy) diff --git a/pkg/core/fee/calculate.go b/pkg/core/fee/calculate.go index 4966ad4f5..24c7c096f 100644 --- a/pkg/core/fee/calculate.go +++ b/pkg/core/fee/calculate.go @@ -18,7 +18,7 @@ func Calculate(base int64, script []byte) (int64, int) { ) if vm.IsSignatureContract(script) { size += 67 + io.GetVarSize(script) - netFee += Opcode(base, opcode.PUSHDATA1, opcode.PUSHNULL, opcode.PUSHDATA1) + base*ECDSAVerifyPrice + netFee += Opcode(base, opcode.PUSHDATA1, opcode.PUSHDATA1) + base*ECDSAVerifyPrice } else if m, pubs, ok := vm.ParseMultiSigContract(script); ok { n := len(pubs) sizeInv := 66 * m diff --git a/pkg/core/helper_test.go b/pkg/core/helper_test.go index 42956b961..7ebfc6b88 100644 --- a/pkg/core/helper_test.go +++ b/pkg/core/helper_test.go @@ -2,6 +2,7 @@ package core import ( "bytes" + "encoding/base64" "encoding/hex" "encoding/json" "fmt" @@ -268,7 +269,7 @@ func TestCreateBasicChain(t *testing.T) { require.NoError(t, acc0.SignTx(txSendRaw)) bw := io.NewBufBinWriter() txSendRaw.EncodeBinary(bw.BinWriter) - t.Logf("sendrawtransaction: %s", hex.EncodeToString(bw.Bytes())) + t.Logf("sendrawtransaction: %s", base64.StdEncoding.EncodeToString(bw.Bytes())) require.False(t, saveChain) } @@ -449,6 +450,9 @@ func initBasicChain(t *testing.T, bc *Blockchain) { require.NoError(t, ntr.Accounts[0].Decrypt("one")) bc.setNodesByRole(t, true, native.RoleP2PNotary, keys.PublicKeys{ntr.Accounts[0].PrivateKey().PublicKey()}) t.Logf("Designated Notary node: %s", hex.EncodeToString(ntr.Accounts[0].PrivateKey().PublicKey().Bytes())) + + // Compile contract to test `invokescript` RPC call + _, _ = newDeployTx(t, bc, priv0ScriptHash, prefix+"invokescript_contract.go", "ContractForInvokescriptTest") } func newNEP17Transfer(sc, from, to util.Uint160, amount int64, additionalArgs ...interface{}) *transaction.Transaction { @@ -466,9 +470,9 @@ func newNEP17Transfer(sc, from, to util.Uint160, amount int64, additionalArgs .. func newDeployTx(t *testing.T, bc *Blockchain, sender util.Uint160, name, ctrName string) (*transaction.Transaction, util.Uint160) { c, err := ioutil.ReadFile(name) require.NoError(t, err) - tx, h, err := testchain.NewDeployTx(bc, ctrName, sender, bytes.NewReader(c)) + tx, h, avm, err := testchain.NewDeployTx(bc, ctrName, sender, bytes.NewReader(c)) require.NoError(t, err) - t.Logf("contractHash (%s): %s", name, h.StringLE()) + t.Logf("contract (%s): \n\tHash: %s\n\tAVM: %s", name, h.StringLE(), base64.StdEncoding.EncodeToString(avm)) return tx, h } diff --git a/pkg/core/interop/crypto/ecdsa.go b/pkg/core/interop/crypto/ecdsa.go index 2c2b6931d..a6dea4311 100644 --- a/pkg/core/interop/crypto/ecdsa.go +++ b/pkg/core/interop/crypto/ecdsa.go @@ -16,34 +16,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" ) -// ECDSASecp256r1Verify checks ECDSA signature using Secp256r1 elliptic curve. -func ECDSASecp256r1Verify(ic *interop.Context) error { - return ecdsaVerify(ic, elliptic.P256()) -} - -// ECDSASecp256k1Verify checks ECDSA signature using Secp256k1 elliptic curve -func ECDSASecp256k1Verify(ic *interop.Context) error { - return ecdsaVerify(ic, btcec.S256()) -} - -// ecdsaVerify is internal representation of ECDSASecp256k1Verify and -// ECDSASecp256r1Verify. -func ecdsaVerify(ic *interop.Context, curve elliptic.Curve) error { - hashToCheck, err := getMessageHash(ic, ic.VM.Estack().Pop().Item()) - if err != nil { - return err - } - keyb := ic.VM.Estack().Pop().Bytes() - signature := ic.VM.Estack().Pop().Bytes() - pkey, err := keys.NewPublicKeyFromBytes(keyb, curve) - if err != nil { - return err - } - res := pkey.Verify(signature, hashToCheck.BytesBE()) - ic.VM.Estack().PushVal(res) - return nil -} - // ECDSASecp256r1CheckMultisig checks multiple ECDSA signatures at once using // Secp256r1 elliptic curve. func ECDSASecp256r1CheckMultisig(ic *interop.Context) error { diff --git a/pkg/core/interop/crypto/ecdsa_test.go b/pkg/core/interop/crypto/ecdsa_test.go index 262f66f2b..097cf593e 100644 --- a/pkg/core/interop/crypto/ecdsa_test.go +++ b/pkg/core/interop/crypto/ecdsa_test.go @@ -20,104 +20,6 @@ import ( "github.com/stretchr/testify/require" ) -func TestECDSASecp256r1Verify(t *testing.T) { - testECDSAVerify(t, true) -} - -func TestECDSASecp256k1Verify(t *testing.T) { - testECDSAVerify(t, false) -} - -func testECDSAVerify(t *testing.T, isR1 bool) { - var priv *keys.PrivateKey - var err error - if isR1 { - priv, err = keys.NewPrivateKey() - } else { - priv, err = keys.NewSecp256k1PrivateKey() - } - require.NoError(t, err) - - verifyFunc := ECDSASecp256r1Verify - if !isR1 { - verifyFunc = ECDSASecp256k1Verify - } - d := dao.NewSimple(storage.NewMemoryStore(), netmode.UnitTestNet, false) - ic := &interop.Context{DAO: dao.NewCached(d)} - runCase := func(t *testing.T, isErr bool, result interface{}, args ...interface{}) { - ic.SpawnVM() - for i := range args { - ic.VM.Estack().PushVal(args[i]) - } - - var err error - func() { - defer func() { - if r := recover(); r != nil { - err = fmt.Errorf("panic: %v", r) - } - }() - err = verifyFunc(ic) - }() - - if isErr { - require.Error(t, err) - return - } - require.NoError(t, err) - require.Equal(t, 1, ic.VM.Estack().Len()) - require.Equal(t, result, ic.VM.Estack().Pop().Value().(bool)) - } - - msg := []byte("test message") - - t.Run("success", func(t *testing.T) { - sign := priv.Sign(msg) - runCase(t, false, true, sign, priv.PublicKey().Bytes(), msg) - }) - - t.Run("signed interop item", func(t *testing.T) { - tx := transaction.New(netmode.UnitTestNet, []byte{0, 1, 2}, 1) - msg := tx.GetSignedPart() - sign := priv.Sign(msg) - runCase(t, false, true, sign, priv.PublicKey().Bytes(), stackitem.NewInterop(tx)) - }) - - t.Run("signed script container", func(t *testing.T) { - tx := transaction.New(netmode.UnitTestNet, []byte{0, 1, 2}, 1) - msg := tx.GetSignedPart() - sign := priv.Sign(msg) - ic.Container = tx - runCase(t, false, true, sign, priv.PublicKey().Bytes(), stackitem.Null{}) - }) - - t.Run("missing arguments", func(t *testing.T) { - runCase(t, true, false) - sign := priv.Sign(msg) - runCase(t, true, false, sign) - runCase(t, true, false, sign, priv.PublicKey().Bytes()) - }) - - t.Run("invalid signature", func(t *testing.T) { - sign := priv.Sign(msg) - sign[0] = ^sign[0] - runCase(t, false, false, sign, priv.PublicKey().Bytes(), msg) - }) - - t.Run("invalid public key", func(t *testing.T) { - sign := priv.Sign(msg) - pub := priv.PublicKey().Bytes() - pub[0] = 0xFF // invalid prefix - runCase(t, true, false, sign, pub, msg) - }) - - t.Run("invalid message", func(t *testing.T) { - sign := priv.Sign(msg) - runCase(t, true, false, sign, priv.PublicKey().Bytes(), - stackitem.NewArray([]stackitem.Item{stackitem.NewByteArray(msg)})) - }) -} - func initCHECKMULTISIG(isR1 bool, msg []byte, n int) ([]stackitem.Item, []stackitem.Item, map[string]*keys.PublicKey, error) { var err error diff --git a/pkg/core/interop/crypto/interop.go b/pkg/core/interop/crypto/interop.go index d754d8411..6c7b465fb 100644 --- a/pkg/core/interop/crypto/interop.go +++ b/pkg/core/interop/crypto/interop.go @@ -6,16 +6,12 @@ import ( ) var ( - ecdsaSecp256r1VerifyID = interopnames.ToID([]byte(interopnames.NeoCryptoVerifyWithECDsaSecp256r1)) - ecdsaSecp256k1VerifyID = interopnames.ToID([]byte(interopnames.NeoCryptoVerifyWithECDsaSecp256k1)) ecdsaSecp256r1CheckMultisigID = interopnames.ToID([]byte(interopnames.NeoCryptoCheckMultisigWithECDsaSecp256r1)) ecdsaSecp256k1CheckMultisigID = interopnames.ToID([]byte(interopnames.NeoCryptoCheckMultisigWithECDsaSecp256k1)) neoCryptoCheckSigID = interopnames.ToID([]byte(interopnames.NeoCryptoCheckSig)) ) var cryptoInterops = []interop.Function{ - {ID: ecdsaSecp256r1VerifyID, Func: ECDSASecp256r1Verify}, - {ID: ecdsaSecp256k1VerifyID, Func: ECDSASecp256k1Verify}, {ID: ecdsaSecp256r1CheckMultisigID, Func: ECDSASecp256r1CheckMultisig}, {ID: ecdsaSecp256k1CheckMultisigID, Func: ECDSASecp256k1CheckMultisig}, {ID: neoCryptoCheckSigID, Func: ECDSASecp256r1CheckSig}, diff --git a/pkg/core/interop/interopnames/names.go b/pkg/core/interop/interopnames/names.go index d81787f55..85ad88278 100644 --- a/pkg/core/interop/interopnames/names.go +++ b/pkg/core/interop/interopnames/names.go @@ -37,8 +37,6 @@ const ( SystemStorageGetReadOnlyContext = "System.Storage.GetReadOnlyContext" SystemStoragePut = "System.Storage.Put" SystemStorageAsReadOnly = "System.Storage.AsReadOnly" - NeoCryptoVerifyWithECDsaSecp256r1 = "Neo.Crypto.VerifyWithECDsaSecp256r1" - NeoCryptoVerifyWithECDsaSecp256k1 = "Neo.Crypto.VerifyWithECDsaSecp256k1" NeoCryptoCheckMultisigWithECDsaSecp256r1 = "Neo.Crypto.CheckMultisigWithECDsaSecp256r1" NeoCryptoCheckMultisigWithECDsaSecp256k1 = "Neo.Crypto.CheckMultisigWithECDsaSecp256k1" NeoCryptoCheckSig = "Neo.Crypto.CheckSig" @@ -80,8 +78,6 @@ var names = []string{ SystemStorageGetReadOnlyContext, SystemStoragePut, SystemStorageAsReadOnly, - NeoCryptoVerifyWithECDsaSecp256r1, - NeoCryptoVerifyWithECDsaSecp256k1, NeoCryptoCheckMultisigWithECDsaSecp256r1, NeoCryptoCheckMultisigWithECDsaSecp256k1, NeoCryptoCheckSig, diff --git a/pkg/core/interops.go b/pkg/core/interops.go index 28a33dc7d..064cdc777 100644 --- a/pkg/core/interops.go +++ b/pkg/core/interops.go @@ -75,10 +75,6 @@ var systemInterops = []interop.Function{ } var neoInterops = []interop.Function{ - {Name: interopnames.NeoCryptoVerifyWithECDsaSecp256r1, Func: crypto.ECDSASecp256r1Verify, - Price: fee.ECDSAVerifyPrice, ParamCount: 3}, - {Name: interopnames.NeoCryptoVerifyWithECDsaSecp256k1, Func: crypto.ECDSASecp256k1Verify, - Price: fee.ECDSAVerifyPrice, ParamCount: 3}, {Name: interopnames.NeoCryptoCheckMultisigWithECDsaSecp256r1, Func: crypto.ECDSASecp256r1CheckMultisig, Price: 0, ParamCount: 3}, {Name: interopnames.NeoCryptoCheckMultisigWithECDsaSecp256k1, Func: crypto.ECDSASecp256k1CheckMultisig, Price: 0, ParamCount: 3}, {Name: interopnames.NeoCryptoCheckSig, Func: crypto.ECDSASecp256r1CheckSig, Price: fee.ECDSAVerifyPrice, ParamCount: 2}, diff --git a/pkg/core/native/crypto_test.go b/pkg/core/native/crypto_test.go index 37f61ef60..6c20854d2 100644 --- a/pkg/core/native/crypto_test.go +++ b/pkg/core/native/crypto_test.go @@ -2,9 +2,12 @@ package native import ( "encoding/hex" + "math" + "math/big" "testing" "github.com/nspcc-dev/neo-go/pkg/core/interop" + "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/stretchr/testify/require" @@ -39,3 +42,81 @@ func TestRIPEMD160(t *testing.T) { require.Equal(t, "213492c0c6fc5d61497cf17249dd31cd9964b8a3", hex.EncodeToString(c.ripemd160(ic, []stackitem.Item{stackitem.NewByteArray([]byte{1, 0})}).Value().([]byte))) }) } + +func TestCryptoLibVerifyWithECDsa(t *testing.T) { + t.Run("R1", func(t *testing.T) { + testECDSAVerify(t, Secp256r1) + }) + t.Run("K1", func(t *testing.T) { + testECDSAVerify(t, Secp256k1) + }) +} + +func testECDSAVerify(t *testing.T, curve NamedCurve) { + var ( + priv *keys.PrivateKey + err error + c = newCrypto() + ic = &interop.Context{VM: vm.New()} + actual stackitem.Item + ) + switch curve { + case Secp256k1: + priv, err = keys.NewSecp256k1PrivateKey() + case Secp256r1: + priv, err = keys.NewPrivateKey() + default: + t.Fatal("unknown curve") + } + require.NoError(t, err) + + runCase := func(t *testing.T, isErr bool, result interface{}, args ...interface{}) { + argsArr := make([]stackitem.Item, len(args)) + for i := range args { + argsArr[i] = stackitem.Make(args[i]) + } + if isErr { + require.Panics(t, func() { + _ = c.verifyWithECDsa(ic, argsArr) + }) + } else { + require.NotPanics(t, func() { + actual = c.verifyWithECDsa(ic, argsArr) + }) + require.Equal(t, stackitem.Make(result), actual) + } + } + + msg := []byte("test message") + sign := priv.Sign(msg) + + t.Run("bad message item", func(t *testing.T) { + runCase(t, true, false, stackitem.NewInterop("cheburek"), priv.PublicKey().Bytes(), sign, int64(curve)) + }) + t.Run("bad pubkey item", func(t *testing.T) { + runCase(t, true, false, msg, stackitem.NewInterop("cheburek"), sign, int64(curve)) + }) + t.Run("bad pubkey bytes", func(t *testing.T) { + runCase(t, true, false, msg, []byte{1, 2, 3}, sign, int64(curve)) + }) + t.Run("bad signature item", func(t *testing.T) { + runCase(t, true, false, msg, priv.PublicKey().Bytes(), stackitem.NewInterop("cheburek"), int64(curve)) + }) + t.Run("bad curve item", func(t *testing.T) { + runCase(t, true, false, msg, priv.PublicKey().Bytes(), sign, stackitem.NewInterop("cheburek")) + }) + t.Run("bad curve value", func(t *testing.T) { + runCase(t, true, false, msg, priv.PublicKey().Bytes(), sign, new(big.Int).Add(big.NewInt(math.MaxInt64), big.NewInt(1))) + }) + t.Run("unknown curve", func(t *testing.T) { + runCase(t, true, false, msg, priv.PublicKey().Bytes(), sign, int64(123)) + }) + t.Run("invalid signature", func(t *testing.T) { + s := priv.Sign(msg) + s[0] = ^s[0] + runCase(t, false, false, s, priv.PublicKey().Bytes(), msg, int64(curve)) + }) + t.Run("success", func(t *testing.T) { + runCase(t, false, true, msg, priv.PublicKey().Bytes(), sign, int64(curve)) + }) +} diff --git a/pkg/crypto/keys/publickey.go b/pkg/crypto/keys/publickey.go index eb941fd88..c5ae4de3f 100644 --- a/pkg/crypto/keys/publickey.go +++ b/pkg/crypto/keys/publickey.go @@ -18,7 +18,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/emit" - "github.com/nspcc-dev/neo-go/pkg/vm/opcode" ) // coordLen is the number of bytes in serialized X or Y coordinate. @@ -317,8 +316,7 @@ func (p *PublicKey) GetVerificationScript() []byte { return buf.Bytes() } emit.Bytes(buf.BinWriter, b) - emit.Opcodes(buf.BinWriter, opcode.PUSHNULL) - emit.Syscall(buf.BinWriter, interopnames.NeoCryptoVerifyWithECDsaSecp256r1) + emit.Syscall(buf.BinWriter, interopnames.NeoCryptoCheckSig) return buf.Bytes() } diff --git a/pkg/crypto/keys/publickey_test.go b/pkg/crypto/keys/publickey_test.go index 06c704232..fc5c32967 100644 --- a/pkg/crypto/keys/publickey_test.go +++ b/pkg/crypto/keys/publickey_test.go @@ -111,7 +111,7 @@ func TestPubkeyToAddress(t *testing.T) { pubKey, err := NewPublicKeyFromString("031ee4e73a17d8f76dc02532e2620bcb12425b33c0c9f9694cc2caa8226b68cad4") require.NoError(t, err) actual := pubKey.Address() - expected := "NcKJdJTEDeCSV9BJAKWWxkBMcHTeVnSzJo" + expected := "NWmVWWvFA6RxvTs4kgY1NnwTXeLYwWxPb1" require.Equal(t, expected, actual) } diff --git a/pkg/interop/crypto/crypto.go b/pkg/interop/crypto/crypto.go index d92bee275..3d605b90a 100644 --- a/pkg/interop/crypto/crypto.go +++ b/pkg/interop/crypto/crypto.go @@ -8,18 +8,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/interop/neogointernal" ) -// ECDsaSecp256r1Verify checks that sig is correct msg's signature for a given pub -// (serialized public key). It uses `Neo.Crypto.VerifyWithECDsaSecp256r1` syscall. -func ECDsaSecp256r1Verify(msg []byte, pub interop.PublicKey, sig interop.Signature) bool { - return neogointernal.Syscall3("Neo.Crypto.VerifyWithECDsaSecp256r1", msg, pub, sig).(bool) -} - -// ECDsaSecp256k1Verify checks that sig is correct msg's signature for a given pub -// (serialized public key). It uses `Neo.Crypto.VerifyWithECDsaSecp256k1` syscall. -func ECDsaSecp256k1Verify(msg []byte, pub interop.PublicKey, sig interop.Signature) bool { - return neogointernal.Syscall3("Neo.Crypto.VerifyWithECDsaSecp256k1", msg, pub, sig).(bool) -} - // ECDSASecp256r1CheckMultisig checks multiple ECDSA signatures at once. It uses // `Neo.Crypto.CheckMultisigWithECDsaSecp256r1` syscall. func ECDSASecp256r1CheckMultisig(msg []byte, pubs []interop.PublicKey, sigs []interop.Signature) bool { diff --git a/pkg/rpc/client/rpc_test.go b/pkg/rpc/client/rpc_test.go index f4142dd2f..9a4243389 100644 --- a/pkg/rpc/client/rpc_test.go +++ b/pkg/rpc/client/rpc_test.go @@ -1113,7 +1113,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ name: "getnep17transfers_invalid_params_error 2", invoke: func(c *Client) (interface{}, error) { var stop uint32 - return c.GetNEP17Transfers("NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc", nil, &stop, nil, nil) + return c.GetNEP17Transfers("NTh9TnZTstvAePEYWDGLLxidBikJE24uTo", nil, &stop, nil, nil) }, }, { @@ -1121,7 +1121,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ invoke: func(c *Client) (interface{}, error) { var start uint32 var limit int - return c.GetNEP17Transfers("NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc", &start, nil, &limit, nil) + return c.GetNEP17Transfers("NTh9TnZTstvAePEYWDGLLxidBikJE24uTo", &start, nil, &limit, nil) }, }, { @@ -1129,7 +1129,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ invoke: func(c *Client) (interface{}, error) { var start, stop uint32 var page int - return c.GetNEP17Transfers("NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc", &start, &stop, nil, &page) + return c.GetNEP17Transfers("NTh9TnZTstvAePEYWDGLLxidBikJE24uTo", &start, &stop, nil, &page) }, }, { diff --git a/pkg/rpc/server/client_test.go b/pkg/rpc/server/client_test.go index db4fd154d..87932f0f6 100644 --- a/pkg/rpc/server/client_test.go +++ b/pkg/rpc/server/client_test.go @@ -2,7 +2,7 @@ package server import ( "context" - "encoding/hex" + "encoding/base64" "testing" "github.com/nspcc-dev/neo-go/internal/testchain" @@ -139,8 +139,10 @@ func TestAddNetworkFee(t *testing.T) { priv := testchain.PrivateKeyByID(0) acc1 := wallet.NewAccountFromPrivateKey(priv) acc1.Contract.Deployed = true - acc1.Contract.Script, _ = hex.DecodeString(verifyContractAVM) - h, _ := util.Uint160DecodeStringLE(verifyContractHash) + acc1.Contract.Script, err = base64.StdEncoding.DecodeString(verifyContractAVM) + require.NoError(t, err) + h, err := util.Uint160DecodeStringLE(verifyContractHash) + require.NoError(t, err) tx.ValidUntilBlock = chain.BlockHeight() + 10 t.Run("Valid", func(t *testing.T) { diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 166d856bd..c817561df 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -59,13 +59,13 @@ type rpcTestCase struct { check func(t *testing.T, e *executor, result interface{}) } -const testContractHash = "500858b96054d3c302078882c30e76915aac1c83" -const deploymentTxHash = "e5503038c2cd602c100690e266b75e2a9d3dda90a63791fd5ab3008ff053eaae" +const testContractHash = "1e1c3024bd955ff3baf7cb92e3b7608c7bb3712b" +const deploymentTxHash = "9b14d575ae0f45a4e2765929a28a118693428edb8143615cc2ae58d5039d1c38" const genesisBlockHash = "9e7cf6fcfc8d0d6831fac75fa895535a5f1960f45a34754b57bff4d4929635c5" -const verifyContractHash = "03ffc0897543b9b709e0f8cab4a7682dae0ba943" -const verifyContractAVM = "570300412d51083021700c14aa8acf859d4fe402b34e673f2156821796a488ebdb30716813cedb2869db289740" -const testVerifyContractAVM = "VwcADBQBDAMOBQYMDQIODw0DDgcJAAAAANswcGgRVUH4J+yMIaonBwAAABFADBQNDwMCCQACAQMHAwQFAgEADgYMCdswcWkRVUH4J+yMIaonBwAAABJAE0A=" +const verifyContractHash = "5bb4bac40e961e334ba7bd36d2496010f67e246e" +const verifyContractAVM = "VwMAQS1RCDAhcAwUVVQtU+0PVUb61E1umZEoZwIvzl7bMHFoE87bKGnbKJdA" +const invokescriptContractAVM = "VwcADBQBDAMOBQYMDQIODw0DDgcJAAAAANswcGhB+CfsjCGqJgQRQAwUDQ8DAgkAAgEDBwMEBQIBAA4GDAnbMHFpQfgn7IwhqiYEEkATQA==" var rpcTestCases = map[string][]rpcTestCase{ "getapplicationlog": { @@ -743,8 +743,8 @@ var rpcTestCases = map[string][]rpcTestCase{ }, { name: "positive, good witness", - // script is base64-encoded `test_verify.avm` representation, hashes are hex-encoded LE bytes of hashes used in the contract with `0x` prefix - params: fmt.Sprintf(`["%s",["0x0000000009070e030d0f0e020d0c06050e030c01","0x090c060e00010205040307030102000902030f0d"]]`, testVerifyContractAVM), + // script is base64-encoded `invokescript_contract.avm` representation, hashes are hex-encoded LE bytes of hashes used in the contract with `0x` prefix + params: fmt.Sprintf(`["%s",["0x0000000009070e030d0f0e020d0c06050e030c01","0x090c060e00010205040307030102000902030f0d"]]`, invokescriptContractAVM), result: func(e *executor) interface{} { return &result.Invoke{} }, check: func(t *testing.T, e *executor, inv interface{}) { res, ok := inv.(*result.Invoke) @@ -756,7 +756,7 @@ var rpcTestCases = map[string][]rpcTestCase{ }, { name: "positive, bad witness of second hash", - params: fmt.Sprintf(`["%s",["0x0000000009070e030d0f0e020d0c06050e030c01"]]`, testVerifyContractAVM), + params: fmt.Sprintf(`["%s",["0x0000000009070e030d0f0e020d0c06050e030c01"]]`, invokescriptContractAVM), result: func(e *executor) interface{} { return &result.Invoke{} }, check: func(t *testing.T, e *executor, inv interface{}) { res, ok := inv.(*result.Invoke) @@ -768,7 +768,7 @@ var rpcTestCases = map[string][]rpcTestCase{ }, { name: "positive, no good hashes", - params: fmt.Sprintf(`["%s"]`, testVerifyContractAVM), + params: fmt.Sprintf(`["%s"]`, invokescriptContractAVM), result: func(e *executor) interface{} { return &result.Invoke{} }, check: func(t *testing.T, e *executor, inv interface{}) { res, ok := inv.(*result.Invoke) @@ -780,7 +780,7 @@ var rpcTestCases = map[string][]rpcTestCase{ }, { name: "positive, bad hashes witness", - params: fmt.Sprintf(`["%s",["0x0000000009070e030d0f0e020d0c06050e030c02"]]`, testVerifyContractAVM), + params: fmt.Sprintf(`["%s",["0x0000000009070e030d0f0e020d0c06050e030c02"]]`, invokescriptContractAVM), result: func(e *executor) interface{} { return &result.Invoke{} }, check: func(t *testing.T, e *executor, inv interface{}) { res, ok := inv.(*result.Invoke) @@ -817,7 +817,7 @@ var rpcTestCases = map[string][]rpcTestCase{ assert.NotNil(t, res.Script) assert.Equal(t, "HALT", res.State) assert.NotEqual(t, 0, res.GasConsumed) - assert.Equal(t, true, res.Stack[0].Value().(bool)) + assert.Equal(t, true, res.Stack[0].Value().(bool), fmt.Sprintf("check address in verification_contract.go: expected %s", testchain.PrivateKeyByID(0).Address())) }, }, { @@ -865,12 +865,12 @@ var rpcTestCases = map[string][]rpcTestCase{ "sendrawtransaction": { { name: "positive", - params: `["AAsAAACAlpgAAAAAACYcEwAAAAAAsAQAAAGqis+FnU/kArNOZz8hVoIXlqSI6wEAXQMA6HZIFwAAAAwUeLpMJACf5RDhNsmZWi4FIV4b5NwMFKqKz4WdT+QCs05nPyFWgheWpIjrE8AMCHRyYW5zZmVyDBQlBZ7LSHjTqHX5HFHO3tMw1Fdf3kFifVtSOAFCDEDqL1as9/ZGKdySLWWmAXbzljr9S3wlnyAXo6UTk0b46lRwRiRZCDKst3lAaaspg93IYrA7ajPUQozUxFy8CUHCKQwhArNiK/QBe9/jF8WK7V9MdT8ga324lgRvp9d0u8S/f43CC0GVRA14"]`, + params: `["ADQSAADA2KcAAAAAABDiEgAAAAAAgBYAAAFVVC1T7Q9VRvrUTW6ZkShnAi/OXgEAYBDAAwDodkgXAAAADBRdSe/t0S4+BgGLRljbEKiXX8gLTgwUVVQtU+0PVUb61E1umZEoZwIvzl4UwB8MCHRyYW5zZmVyDBT1Y+pAvCg9TQ4FxI6jBbPyoHNA70FifVtSOQFCDEAppqgOf7RZvrS+uOVzVNlcQAQnyujtzHzv9/Za+FFkxWFd8mZ6AvWnFXAL0W5NafW4xyP7Kp/qgWCmZrHINaLkKAwhArNiK/QBe9/jF8WK7V9MdT8ga324lgRvp9d0u8S/f43CQXR0dqo="]`, result: func(e *executor) interface{} { return &result.RelayResult{} }, check: func(t *testing.T, e *executor, inv interface{}) { res, ok := inv.(*result.RelayResult) require.True(t, ok) - expectedHash, err := util.Uint256DecodeStringLE("ab5573cfc8d70774f04aa7d5521350cfc1aa1239c44c24e490e139408cd46a57") + expectedHash, err := util.Uint256DecodeStringLE("3b133d0c2912da4f99680ae3a5f0e178bc761f2c360662a1fabbe1a8dbe309ea") require.NoError(t, err) assert.Equal(t, expectedHash, res.Hash) }, @@ -1598,7 +1598,7 @@ func checkNep17Balances(t *testing.T, e *executor, acc interface{}) { }, { Asset: e.chain.UtilityTokenHash(), - Amount: "78994294100", + Amount: "78994302340", LastUpdated: 8, }}, Address: testchain.PrivateKeyByID(0).GetScriptHash().StringLE(), diff --git a/pkg/rpc/server/testdata/test_verify.go b/pkg/rpc/server/testdata/invokescript_contract.go similarity index 100% rename from pkg/rpc/server/testdata/test_verify.go rename to pkg/rpc/server/testdata/invokescript_contract.go diff --git a/pkg/rpc/server/testdata/test_verify.avm b/pkg/rpc/server/testdata/test_verify.avm deleted file mode 100755 index 100b20621..000000000 Binary files a/pkg/rpc/server/testdata/test_verify.avm and /dev/null differ diff --git a/pkg/rpc/server/testdata/testblocks.acc b/pkg/rpc/server/testdata/testblocks.acc index 3bd6b5394..1cb4dcb18 100644 Binary files a/pkg/rpc/server/testdata/testblocks.acc and b/pkg/rpc/server/testdata/testblocks.acc differ diff --git a/pkg/rpc/server/testdata/verification_contract.go b/pkg/rpc/server/testdata/verification_contract.go index 03e9bb480..5d8428ad1 100644 --- a/pkg/rpc/server/testdata/verification_contract.go +++ b/pkg/rpc/server/testdata/verification_contract.go @@ -6,9 +6,9 @@ import ( ) // Verify is a verification contract method. -// It returns true iff it is signed by NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc (id-0 private key from testchain). +// It returns true iff it is signed by NTh9TnZTstvAePEYWDGLLxidBikJE24uTo (id-0 private key from testchain). func Verify() bool { tx := runtime.GetScriptContainer() - addr := util.FromAddress("NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc") + addr := util.FromAddress("NTh9TnZTstvAePEYWDGLLxidBikJE24uTo") return util.Equals(string(tx.Sender), string(addr)) } diff --git a/pkg/services/notary/testdata/notary1.json b/pkg/services/notary/testdata/notary1.json index 0a8d45251..055296144 100644 --- a/pkg/services/notary/testdata/notary1.json +++ b/pkg/services/notary/testdata/notary1.json @@ -1 +1,65 @@ -{"version":"3.0","accounts":[{"address":"NSbjd7dSePTZ6QpADAuM5722QpBmL5124W","key":"6PYVWTfkNCYvyQhyFLHH5dyRyT6jSi8u8Z8kn122PACfsDWi4QgkGm8FyW","label":"NotaryNode1","contract":{"script":"DCEDm5PmbOfVPmYXTSVW903XnOhhNBTsF9oDlVYusIH/ui0LQZVEDXg=","parameters":[{"name":"parameter0","type":"Signature"}],"deployed":false},"lock":false,"isdefault":false},{"address":"NisSvmSd2Lp28tjr8EqCZB5ahHDvBExo2j","key":"6PYLvgnZNwhiiZPiSCw3B3bHSFwbSXgh3MkGt4gL69MD8Sw7LMnuUgM9KQ","label":"three","contract":{"script":"DCEDHRWEIGXHCwUU2Fc7B0qrYPezXR0sfdEduRExyzIKVC8LQZVEDXg=","parameters":[{"name":"parameter0","type":"Signature"}],"deployed":false},"lock":false,"isdefault":false},{"address":"NRCCdGifyUWKnFotZhcgKpmxhhVJSJb94r","key":"6PYKXkuJ7G6bTj62bjy8fsBLF5okYNdAEBhKPCv8nmcALCtk2yPtBo835p","label":"four","contract":{"script":"DCECmUfs/gqKHd3AdJm5+Ev6zkubV8pP8DZzgu8+t5WdphILQZVEDXg=","parameters":[{"name":"parameter0","type":"Signature"}],"deployed":false},"lock":false,"isdefault":false}],"scrypt":{"n":16384,"r":8,"p":8},"extra":{"Tokens":null}} +{ + "scrypt" : { + "n" : 16384, + "r" : 8, + "p" : 8 + }, + "accounts" : [ + { + "contract" : { + "parameters" : [ + { + "type" : "Signature", + "name" : "parameter0" + } + ], + "deployed" : false, + "script" : "DCEDm5PmbOfVPmYXTSVW903XnOhhNBTsF9oDlVYusIH/ui1BdHR2qg==" + }, + "label" : "NotaryNode1", + "address" : "NS6vb4uE8wdQfcQbFcRY7yquSbwbVcMSV3", + "isdefault" : false, + "lock" : false, + "key" : "6PYMGBef95jMZJTQcH9ZP5PuecWa2H86HFbdnfe7VQs8uPZ3S6pu4D5NpP" + }, + { + "contract" : { + "script" : "DCEDHRWEIGXHCwUU2Fc7B0qrYPezXR0sfdEduRExyzIKVC9BdHR2qg==", + "deployed" : false, + "parameters" : [ + { + "name" : "parameter0", + "type" : "Signature" + } + ] + }, + "label" : "three", + "address" : "NakELwR1i6brB7EmYLc6yPbvk78Qi5Qbpi", + "isdefault" : false, + "lock" : false, + "key" : "6PYLm6kse9FVpKoBbhYYSFHhFUUL2bZYePU95x7Ncknu798WEHYmTuUijR" + }, + { + "contract" : { + "parameters" : [ + { + "name" : "parameter0", + "type" : "Signature" + } + ], + "deployed" : false, + "script" : "DCECmUfs/gqKHd3AdJm5+Ev6zkubV8pP8DZzgu8+t5WdphJBdHR2qg==" + }, + "key" : "6PYWBWehojbBn8U2XWcXxuWqPrnp9qwQ5rD3RKQza1iR5ZBCPHXxCQonYm", + "isdefault" : false, + "lock" : false, + "address" : "NLWXE5CMEqJzEVtscF4BoTvSbiBr1FwtBb", + "label" : "four" + } + ], + "extra" : { + "Tokens" : null + }, + "version" : "3.0" +} + diff --git a/pkg/services/notary/testdata/notary2.json b/pkg/services/notary/testdata/notary2.json index 329c11390..a2a6b2f48 100644 --- a/pkg/services/notary/testdata/notary2.json +++ b/pkg/services/notary/testdata/notary2.json @@ -1 +1,30 @@ -{"version":"3.0","accounts":[{"address":"NfFcJvWcHe8SSS92hNZhyQUJ6cg3pb36Tf","key":"6PYU2QoD52Xt9Z6QmNGUJWn89qUD1W6QqAL4Y8nfTWtTKvmVpQh8wsH6qY","label":"NotaryNode2","contract":{"script":"DCECIcKj0GFdv4b1NZrw9X6zLNLWzmNKAxtw6olIMZxpPRQLQZVEDXg=","parameters":[{"name":"parameter0","type":"Signature"}],"deployed":false},"lock":false,"isdefault":false}],"scrypt":{"n":16384,"r":8,"p":8},"extra":{"Tokens":null}} +{ + "scrypt" : { + "r" : 8, + "p" : 8, + "n" : 16384 + }, + "version" : "3.0", + "extra" : { + "Tokens" : null + }, + "accounts" : [ + { + "address" : "NYt1oLCMMvqxnAVMJCSk87kZTP693GxK11", + "key" : "6PYWejAoqoF4JT5P9N3EcqC5tRC1MXx2gZ1R2WWryjDUH1bMAo3Bd68nCo", + "lock" : false, + "isdefault" : false, + "contract" : { + "parameters" : [ + { + "name" : "parameter0", + "type" : "Signature" + } + ], + "deployed" : false, + "script" : "DCECIcKj0GFdv4b1NZrw9X6zLNLWzmNKAxtw6olIMZxpPRRBdHR2qg==" + }, + "label" : "NotaryNode2" + } + ] +} diff --git a/pkg/services/oracle/testdata/oracle1.json b/pkg/services/oracle/testdata/oracle1.json index ae817cdbf..21bd210aa 100644 --- a/pkg/services/oracle/testdata/oracle1.json +++ b/pkg/services/oracle/testdata/oracle1.json @@ -1 +1,30 @@ -{"version":"3.0","accounts":[{"address":"NMy1PN9GCdGc26YFG7JruYg7UBStw2pPKN","key":"6PYML6dDTMXJBD7ywRwiCAhseCPToWkMfvPUViuxiXM6s5oi7ggf4ho3AK","label":"","contract":{"script":"DCEDNxK01e1DnGA+TiGU3H4DKUuGliSz89/NuZCbVvA2u0wLQZVEDXg=","parameters":[{"name":"parameter0","type":"Signature"}],"deployed":false},"lock":false,"isdefault":false}],"scrypt":{"n":16384,"r":8,"p":8},"extra":{"Tokens":null}} +{ + "accounts" : [ + { + "address" : "NPcxgUcZorwb1njfRGL7JEyc6SsTku42ek", + "key" : "6PYPy72Gnoif27u9Uy5r2sqMwTTYMLRBGwPcJmB1GP1FTPp4U3M9fZVdtg", + "lock" : false, + "isdefault" : false, + "contract" : { + "parameters" : [ + { + "type" : "Signature", + "name" : "parameter0" + } + ], + "script" : "DCEDNxK01e1DnGA+TiGU3H4DKUuGliSz89/NuZCbVvA2u0xBdHR2qg==", + "deployed" : false + }, + "label" : "" + } + ], + "extra" : { + "Tokens" : null + }, + "version" : "3.0", + "scrypt" : { + "n" : 16384, + "p" : 8, + "r" : 8 + } +} diff --git a/pkg/services/oracle/testdata/oracle2.json b/pkg/services/oracle/testdata/oracle2.json index d5d131b5f..ecfd9346c 100644 --- a/pkg/services/oracle/testdata/oracle2.json +++ b/pkg/services/oracle/testdata/oracle2.json @@ -1 +1,30 @@ -{"version":"3.0","accounts":[{"address":"NU7QxQXULbmZU7kaWUaeF3r9v3zimU42bV","key":"6PYKv77p5wihN64XaPB5Nbci1sCLV5CrzSu8GKv7UHXHRtytfLt8zfrMgT","label":"","contract":{"script":"DCEDEXzwIl4Jhvsj98GYIPFFiedeb1QdP8T79uSBSDNsiswLQZVEDXg=","parameters":[{"name":"parameter0","type":"Signature"}],"deployed":false},"lock":false,"isdefault":false}],"scrypt":{"n":16384,"r":8,"p":8},"extra":{"Tokens":null}} +{ + "version" : "3.0", + "extra" : { + "Tokens" : null + }, + "accounts" : [ + { + "isdefault" : false, + "label" : "", + "key" : "6PYTgfwm5kuahFNN391D6p21ivKrHpvr8Wnn1mBpMnavn6PxkK2prSsxye", + "address" : "NhSCnPJdgLdxnQaYHmW9A3WFLT9DiicBfK", + "lock" : false, + "contract" : { + "script" : "DCEDEXzwIl4Jhvsj98GYIPFFiedeb1QdP8T79uSBSDNsisxBdHR2qg==", + "deployed" : false, + "parameters" : [ + { + "type" : "Signature", + "name" : "parameter0" + } + ] + } + } + ], + "scrypt" : { + "p" : 8, + "n" : 16384, + "r" : 8 + } +} diff --git a/pkg/vm/contract_checks.go b/pkg/vm/contract_checks.go index 7a721aa3a..8faa7d9e8 100644 --- a/pkg/vm/contract_checks.go +++ b/pkg/vm/contract_checks.go @@ -13,7 +13,7 @@ import ( ) var ( - verifyInteropID = interopnames.ToID([]byte(interopnames.NeoCryptoVerifyWithECDsaSecp256r1)) + verifyInteropID = interopnames.ToID([]byte(interopnames.NeoCryptoCheckSig)) multisigInteropID = interopnames.ToID([]byte(interopnames.NeoCryptoCheckMultisigWithECDsaSecp256r1)) ) @@ -112,7 +112,7 @@ func IsSignatureContract(script []byte) bool { // ParseSignatureContract parses simple signature contract and returns // public key. func ParseSignatureContract(script []byte) ([]byte, bool) { - if len(script) != 41 { + if len(script) != 40 { return nil, false } @@ -122,10 +122,6 @@ func ParseSignatureContract(script []byte) ([]byte, bool) { return nil, false } pub := param - instr, _, err = ctx.Next() - if err != nil || instr != opcode.PUSHNULL { - return nil, false - } instr, param, err = ctx.Next() if err != nil || instr != opcode.SYSCALL || binary.LittleEndian.Uint32(param) != verifyInteropID { return nil, false diff --git a/pkg/vm/contract_checks_test.go b/pkg/vm/contract_checks_test.go index 29146c4f4..c77d28d25 100644 --- a/pkg/vm/contract_checks_test.go +++ b/pkg/vm/contract_checks_test.go @@ -16,12 +16,11 @@ import ( ) func testSignatureContract() []byte { - prog := make([]byte, 41) + prog := make([]byte, 40) prog[0] = byte(opcode.PUSHDATA1) prog[1] = 33 - prog[35] = byte(opcode.PUSHNULL) - prog[36] = byte(opcode.SYSCALL) - binary.LittleEndian.PutUint32(prog[37:], verifyInteropID) + prog[35] = byte(opcode.SYSCALL) + binary.LittleEndian.PutUint32(prog[36:], verifyInteropID) return prog } @@ -43,7 +42,7 @@ func TestIsSignatureContract(t *testing.T) { t.Run("invalid interop ID", func(t *testing.T) { prog := testSignatureContract() - binary.LittleEndian.PutUint32(prog[37:], ^verifyInteropID) + binary.LittleEndian.PutUint32(prog[36:], ^verifyInteropID) assert.False(t, IsSignatureContract(prog)) assert.False(t, IsStandardContract(prog)) }) @@ -55,13 +54,6 @@ func TestIsSignatureContract(t *testing.T) { assert.False(t, IsStandardContract(prog)) }) - t.Run("no PUSHNULL", func(t *testing.T) { - prog := testSignatureContract() - prog[35] = byte(opcode.PUSH1) - assert.False(t, IsSignatureContract(prog)) - assert.False(t, IsStandardContract(prog)) - }) - t.Run("invalid length", func(t *testing.T) { prog := testSignatureContract() prog = append(prog, 0) diff --git a/pkg/wallet/account_test.go b/pkg/wallet/account_test.go index f44eeb6ef..1cbab5c1c 100644 --- a/pkg/wallet/account_test.go +++ b/pkg/wallet/account_test.go @@ -135,11 +135,11 @@ func convertPubs(t *testing.T, hexKeys []string) []*keys.PublicKey { func compareFields(t *testing.T, tk keytestcases.Ktype, acc *Account) { want, have := tk.Address, acc.Address - require.Equalf(t, want, have, "expected %s got %s", want, have) + require.Equalf(t, want, have, "expected address %s got %s", want, have) want, have = tk.Wif, acc.wif - require.Equalf(t, want, have, "expected %s got %s", want, have) + require.Equalf(t, want, have, "expected wif %s got %s", want, have) want, have = tk.PublicKey, hex.EncodeToString(acc.publicKey) - require.Equalf(t, want, have, "expected %s got %s", want, have) + require.Equalf(t, want, have, "expected pub key %s got %s", want, have) want, have = tk.PrivateKey, acc.privateKey.String() - require.Equalf(t, want, have, "expected %s got %s", want, have) + require.Equalf(t, want, have, "expected priv key %s got %s", want, have) } diff --git a/pkg/wallet/testdata/wallet1.json b/pkg/wallet/testdata/wallet1.json index 27a48a3ed..1141c9777 100644 --- a/pkg/wallet/testdata/wallet1.json +++ b/pkg/wallet/testdata/wallet1.json @@ -2,11 +2,11 @@ "version": "3.0", "accounts": [ { - "address": "NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc", - "key": "6PYN7LvaWqBNw7Xb7a52LSbPnP91kyuzYi3HncGvQwQoYAY2W8DncTgpux", + "address": "NTh9TnZTstvAePEYWDGLLxidBikJE24uTo", + "key": "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL", "label": "", "contract": { - "script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcILQZVEDXg=", + "script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcJBdHR2qg==", "parameters": [ { "name": "parameter0", @@ -20,7 +20,7 @@ }, { "address": "NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY", - "key": "6PYN7LvaWqBNw7Xb7a52LSbPnP91kyuzYi3HncGvQwQoYAY2W8DncTgpux", + "key": "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL", "label": "", "contract": { "script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBE43vrw==", diff --git a/pkg/wallet/testdata/wallet2.json b/pkg/wallet/testdata/wallet2.json index d5030380c..b7e396c5e 100644 --- a/pkg/wallet/testdata/wallet2.json +++ b/pkg/wallet/testdata/wallet2.json @@ -2,11 +2,11 @@ "version": "3.0", "accounts": [ { - "address": "NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc", - "key": "6PYN7LvaWqBNw7Xb7a52LSbPnP91kyuzYi3HncGvQwQoYAY2W8DncTgpux", + "address": "NTh9TnZTstvAePEYWDGLLxidBikJE24uTo", + "key": "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL", "label": "", "contract": { - "script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcILQZVEDXg=", + "script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcJBdHR2qg==", "parameters": [ { "name": "parameter0", @@ -20,7 +20,7 @@ }, { "address": "NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY", - "key": "6PYN7LvaWqBNw7Xb7a52LSbPnP91kyuzYi3HncGvQwQoYAY2W8DncTgpux", + "key": "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL", "label": "", "contract": { "script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBE43vrw==", @@ -44,11 +44,11 @@ "isdefault": false }, { - "address": "NWvKSwutC8D6VKmmPxAEgFKx2NLvFhn8q5", - "key": "6PYKEHagXJ3mDLdga1FoyTGRtPdJgPz6Gb8sjEFwZvRu7ncD9PVZfHtMzL", + "address": "NUREbqw2kfbPgDeEz8Dac2QxntGGqqFMm7", + "key": "6PYXADog3RQCwKRhqQsobwZEFopdcCJuMfPosM9pXPaDWSguKvznLdpADk", "label": "", "contract": { - "script": "DCECEDp/fdAWVYWX95YNJ8UWpDlP2Wi55lFV60sBPkBAQG4LQZVEDXg=", + "script": "DCECEDp/fdAWVYWX95YNJ8UWpDlP2Wi55lFV60sBPkBAQG5BdHR2qg==", "parameters": [ { "name": "parameter0", diff --git a/pkg/wallet/wallet_test.go b/pkg/wallet/wallet_test.go index 1811062df..4f3854fc9 100644 --- a/pkg/wallet/wallet_test.go +++ b/pkg/wallet/wallet_test.go @@ -186,14 +186,14 @@ func TestWalletGetChangeAddress(t *testing.T) { require.NoError(t, err) sh := w1.GetChangeAddress() // No default address, the first one is used. - expected, err := address.StringToUint160("NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc") + expected, err := address.StringToUint160("NTh9TnZTstvAePEYWDGLLxidBikJE24uTo") require.NoError(t, err) require.Equal(t, expected, sh) w2, err := NewWalletFromFile("testdata/wallet2.json") require.NoError(t, err) sh = w2.GetChangeAddress() // Default address. - expected, err = address.StringToUint160("NWvKSwutC8D6VKmmPxAEgFKx2NLvFhn8q5") + expected, err = address.StringToUint160("NUREbqw2kfbPgDeEz8Dac2QxntGGqqFMm7") require.NoError(t, err) require.Equal(t, expected, sh) } diff --git a/scripts/gendump/main.go b/scripts/gendump/main.go index bf6abc9be..40581d2ae 100644 --- a/scripts/gendump/main.go +++ b/scripts/gendump/main.go @@ -75,7 +75,7 @@ func main() { handleError("can't tranfser GAS", err) lastBlock = addBlock(bc, lastBlock, valScript, txMoveNeo, txMoveGas) - tx, contractHash, err := testchain.NewDeployTx(bc, "DumpContract", h, strings.NewReader(contract)) + tx, contractHash, _, err := testchain.NewDeployTx(bc, "DumpContract", h, strings.NewReader(contract)) handleError("can't create deploy tx", err) tx.NetworkFee = 10_000_000 tx.ValidUntilBlock = bc.BlockHeight() + 1