From 6e0926e59ffbd824ba76dc7935e3cb4ab3581e08 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 6 May 2024 16:57:38 +0300 Subject: [PATCH] native: adjust NamedCurveHash values Use 122 and 123 respectively for Secp256k1Keccak256 and Secp256r1Keccak256, ref. https://github.com/neo-project/neo/pull/3209#issuecomment-2095798056. Signed-off-by: Anna Shaleva --- pkg/core/native/crypto.go | 4 ++-- pkg/core/native/crypto_test.go | 2 +- .../native_test/cryptolib_verification_test.go | 12 ++++++------ pkg/interop/native/crypto/crypto.go | 4 ++-- pkg/services/rpcsrv/server_test.go | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pkg/core/native/crypto.go b/pkg/core/native/crypto.go index bcc6b2f60..d63a20c70 100644 --- a/pkg/core/native/crypto.go +++ b/pkg/core/native/crypto.go @@ -39,8 +39,8 @@ type NamedCurveHash byte const ( Secp256k1Sha256 NamedCurveHash = 22 Secp256r1Sha256 NamedCurveHash = 23 - Secp256k1Keccak256 NamedCurveHash = 24 - Secp256r1Keccak256 NamedCurveHash = 25 + Secp256k1Keccak256 NamedCurveHash = 122 + Secp256r1Keccak256 NamedCurveHash = 123 ) const cryptoContractID = -3 diff --git a/pkg/core/native/crypto_test.go b/pkg/core/native/crypto_test.go index db8207f73..0227a9da8 100644 --- a/pkg/core/native/crypto_test.go +++ b/pkg/core/native/crypto_test.go @@ -199,7 +199,7 @@ func testECDSAVerify(t *testing.T, curve NamedCurveHash) { 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)) + runCase(t, true, false, msg, priv.PublicKey().Bytes(), sign, int64(124)) }) t.Run("invalid signature", func(t *testing.T) { s := priv.Sign(msg) diff --git a/pkg/core/native/native_test/cryptolib_verification_test.go b/pkg/core/native/native_test/cryptolib_verification_test.go index f119a8556..2143a1217 100644 --- a/pkg/core/native/native_test/cryptolib_verification_test.go +++ b/pkg/core/native/native_test/cryptolib_verification_test.go @@ -175,7 +175,7 @@ func buildKoblitzVerificationScript(t *testing.T, pub *keys.PublicKey) []byte { // READY: loaded 110 instructions // NEO-GO-VM 0 > ops // INDEX OPCODE PARAMETER - // 0 PUSHINT8 24 (18) << + // 0 PUSHINT8 122 (7a) << // 2 SWAP // 3 PUSHDATA1 02a088bfab1e4b4bede7d4624572861b401cb20c3b14e90687bd8862272a4e6166 // 38 SYSCALL System.Runtime.GetNetwork (c5fba0e0) @@ -232,7 +232,7 @@ func buildKoblitzVerificationScriptSimpleSingleHash(t *testing.T, pub *keys.Publ // READY: loaded 98 instructions // NEO-GO-VM 0 > ops // INDEX OPCODE PARAMETER - // 0 PUSHINT8 24 (18) << + // 0 PUSHINT8 122 (7a) << // 2 SWAP // 3 PUSHDATA1 0363d7a48125a76cdea6e098c9f128e82920ed428e5fb4caf1d7f81c16cad0c205 // 38 SYSCALL System.Runtime.GetNetwork (c5fba0e0) @@ -288,7 +288,7 @@ func buildKoblitzVerificationScriptSimpleSingleHashStaticMagic(t *testing.T, pub // READY: loaded 95 instructions // NEO-GO-VM 0 > ops // INDEX OPCODE PARAMETER - // 0 PUSHINT8 24 (18) << + // 0 PUSHINT8 122 (7a) << // 2 SWAP // 3 PUSHDATA1 0296e13080ade92a2ab722338c2a249ee8d83a14f649c68321664165f06bd110bd // 38 PUSHINT8 42 (2a) @@ -348,7 +348,7 @@ func buildKoblitzVerificationScriptSimple(t *testing.T, pub *keys.PublicKey) []b // READY: loaded 136 instructions // NEO-GO-VM 0 > ops // INDEX OPCODE PARAMETER - // 0 PUSHINT8 24 (18) << + // 0 PUSHINT8 122 (7a) << // 2 SWAP // 3 PUSHDATA1 03a77f137afbb4b68d7a450aa5a28fe335f804c589a808494b4b626eb98707f37d // 38 SYSCALL System.Runtime.GetNetwork (c5fba0e0) @@ -449,7 +449,7 @@ func buildKoblitzVerificationScriptCompat(t *testing.T, pub *keys.PublicKey) []b // READY: loaded 186 instructions // NEO-GO-VM 0 > ops // INDEX OPCODE PARAMETER - // 0 PUSHINT8 24 (18) << + // 0 PUSHINT8 122 (7a) << // 2 SWAP // 3 PUSHDATA1 02627ef9c3631e3ccb8fbc4c5b6c49e38ccede5a79afb1e1b0708fbb958a7802d7 // 38 SYSCALL System.Runtime.GetNetwork (c5fba0e0) @@ -866,7 +866,7 @@ func buildKoblitzMultisigVerificationScript(t *testing.T, m int, pubs keys.Publi // 193 GE // 194 OR // 195 JMPIF 261 (66/42) - // 197 PUSHINT8 24 (18) + // 197 PUSHINT8 122 (7a) // 199 LDLOC0 // 200 LDLOC3 // 201 PICKITEM diff --git a/pkg/interop/native/crypto/crypto.go b/pkg/interop/native/crypto/crypto.go index 40fd1a0e3..b3574fcde 100644 --- a/pkg/interop/native/crypto/crypto.go +++ b/pkg/interop/native/crypto/crypto.go @@ -20,8 +20,8 @@ type NamedCurveHash byte const ( Secp256k1Sha256 NamedCurveHash = 22 Secp256r1Sha256 NamedCurveHash = 23 - Secp256k1Keccak256 NamedCurveHash = 24 - Secp256r1Keccak256 NamedCurveHash = 25 + Secp256k1Keccak256 NamedCurveHash = 122 + Secp256r1Keccak256 NamedCurveHash = 123 ) // Sha256 calls `sha256` method of native CryptoLib contract and computes SHA256 hash of b. diff --git a/pkg/services/rpcsrv/server_test.go b/pkg/services/rpcsrv/server_test.go index 439b27dd4..f6c89d7fd 100644 --- a/pkg/services/rpcsrv/server_test.go +++ b/pkg/services/rpcsrv/server_test.go @@ -3239,11 +3239,11 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) [] checkCalc(t, tx, 2315100) // Perfectly matches FeeIsMultiSigContract() C# test. }) t.Run("Koblitz custom multisignature witness", func(t *testing.T) { - tx := "AAIAAACWP5gAAAAAAIBniwAAAAAAAgAAAAFSPSnnAijsThGazYipphHw5ljbTgEAVgsVDBQBAgMAAAAAAAAAAAAAAAAAAAAAAAw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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD9CAETDCECbSVpJ0BN2xiveIGNU0LzEz4V7FUAp1NV8s7YI4kq9eQMIQOaHY3bh+3OmXuU9t72Pj62loLM7gZDgXJwnBV2zO4u1wwhAsvP18ohoYHcHBPt4wwPqAOstOhazEegr4klYmDlWpzeDCED9EsK7L0qFMP1QpBBfKMMVXPLa894ONINLRtjtBLBM6oUVwcAdW3AcXZDbigDOG7AcEHF+6DgAwAAAAABAAAAnhSNQS1RCDAQzotyEHMQdGtuuGxtuJIkQgB6aGvOaWzOahTAEAwPdmVyaWZ5V2l0aEVDRHNhDBQb9XWrEYlohBNhCjWhKIbN4LZsckFifVtSa55zbJx0IrlrbrM=" resp := checkErrGetResult(t, calcReqExactly(t, tx), false, 0) res := new(result.NetworkFee) require.NoError(t, json.Unmarshal(resp, res)) - require.Equal(t, int64(8995470), res.Value) + require.Equal(t, int64(8992070), res.Value) }) checkContract := func(t *testing.T, verAcc util.Uint160, invoc []byte, fee int64) { txScript, err := smartcontract.CreateCallWithAssertScript(chain.UtilityTokenHash(), "transfer",