diff --git a/neo.UnitTests/Ledger/UT_Blockchain.cs b/neo.UnitTests/Ledger/UT_Blockchain.cs index eb17e71c62..af0ec69a79 100644 --- a/neo.UnitTests/Ledger/UT_Blockchain.cs +++ b/neo.UnitTests/Ledger/UT_Blockchain.cs @@ -70,13 +70,13 @@ public void TestContainsTransaction() [TestMethod] public void TestGetCurrentBlockHash() { - Blockchain.Singleton.CurrentBlockHash.Should().Be(UInt256.Parse("5662a113d8fa9532ea9c52046a463e2e3fcfcdd6192d99cad805b376fb643ceb")); + Blockchain.Singleton.CurrentBlockHash.Should().Be(UInt256.Parse("0x0d492ce0f38090a65b2b01af50f7a6d685b6b76fbc41672762e96b05d15d742c")); } [TestMethod] public void TestGetCurrentHeaderHash() { - Blockchain.Singleton.CurrentHeaderHash.Should().Be(UInt256.Parse("5662a113d8fa9532ea9c52046a463e2e3fcfcdd6192d99cad805b376fb643ceb")); + Blockchain.Singleton.CurrentHeaderHash.Should().Be(UInt256.Parse("0x0d492ce0f38090a65b2b01af50f7a6d685b6b76fbc41672762e96b05d15d742c")); } [TestMethod] @@ -88,7 +88,7 @@ public void TestGetBlock() [TestMethod] public void TestGetBlockHash() { - Blockchain.Singleton.GetBlockHash(0).Should().Be(UInt256.Parse("5662a113d8fa9532ea9c52046a463e2e3fcfcdd6192d99cad805b376fb643ceb")); + Blockchain.Singleton.GetBlockHash(0).Should().Be(UInt256.Parse("0x0d492ce0f38090a65b2b01af50f7a6d685b6b76fbc41672762e96b05d15d742c")); Blockchain.Singleton.GetBlockHash(10).Should().BeNull(); } diff --git a/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs b/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs index 570151d941..c8c874cee6 100644 --- a/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs +++ b/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs @@ -165,10 +165,9 @@ public void FeeIsMultiSigContract() } var sizeGas = tx.Size * NativeContract.Policy.GetFeePerByte(snapshot); - Assert.AreEqual(verificationGas, 2000540); - Assert.AreEqual(sizeGas, 358000); - Assert.AreEqual(verificationGas + sizeGas, 2358540); - Assert.AreEqual(tx.NetworkFee, 2358540); + Assert.AreEqual(verificationGas, 2000570); + Assert.AreEqual(sizeGas, 359000); + Assert.AreEqual(tx.NetworkFee, 2359570); } } @@ -214,7 +213,7 @@ public void FeeIsSignatureContractDetailed() Assert.IsNull(tx.Witnesses); // check pre-computed network fee (already guessing signature sizes) - tx.NetworkFee.Should().Be(1257240); + tx.NetworkFee.Should().Be(1258270); // ---- // Sign @@ -251,12 +250,12 @@ public void FeeIsSignatureContractDetailed() verificationGas += engine.GasConsumed; } } - Assert.AreEqual(verificationGas, 1000240); + Assert.AreEqual(verificationGas, 1000270); // ------------------ // check tx_size cost // ------------------ - Assert.AreEqual(tx.Size, 257); + Assert.AreEqual(tx.Size, 258); // will verify tx size, step by step @@ -272,16 +271,16 @@ public void FeeIsSignatureContractDetailed() // Part III Assert.AreEqual(tx.Script.GetVarSize(), 82); // Part IV - Assert.AreEqual(tx.Witnesses.GetVarSize(), 107); + Assert.AreEqual(tx.Witnesses.GetVarSize(), 108); // I + II + III + IV - Assert.AreEqual(tx.Size, 45 + 23 + 82 + 107); + Assert.AreEqual(tx.Size, 45 + 23 + 82 + 108); Assert.AreEqual(NativeContract.Policy.GetFeePerByte(snapshot), 1000); var sizeGas = tx.Size * NativeContract.Policy.GetFeePerByte(snapshot); - Assert.AreEqual(sizeGas, 257000); + Assert.AreEqual(sizeGas, 258000); // final check on sum: verification_cost + tx_size - Assert.AreEqual(verificationGas + sizeGas, 1257240); + Assert.AreEqual(verificationGas + sizeGas, 1258270); // final assert Assert.AreEqual(tx.NetworkFee, verificationGas + sizeGas); } @@ -372,7 +371,7 @@ public void FeeIsSignatureContract_TestScope_Global() // get sizeGas var sizeGas = tx.Size * NativeContract.Policy.GetFeePerByte(snapshot); // final check on sum: verification_cost + tx_size - Assert.AreEqual(verificationGas + sizeGas, 1257240); + Assert.AreEqual(verificationGas + sizeGas, 1258270); // final assert Assert.AreEqual(tx.NetworkFee, verificationGas + sizeGas); } @@ -464,7 +463,7 @@ public void FeeIsSignatureContract_TestScope_CurrentHash_GAS() // get sizeGas var sizeGas = tx.Size * NativeContract.Policy.GetFeePerByte(snapshot); // final check on sum: verification_cost + tx_size - Assert.AreEqual(verificationGas + sizeGas, 1278240); + Assert.AreEqual(verificationGas + sizeGas, 1279270); // final assert Assert.AreEqual(tx.NetworkFee, verificationGas + sizeGas); } @@ -559,7 +558,7 @@ public void FeeIsSignatureContract_TestScope_CalledByEntry_Plus_GAS() // get sizeGas var sizeGas = tx.Size * NativeContract.Policy.GetFeePerByte(snapshot); // final check on sum: verification_cost + tx_size - Assert.AreEqual(verificationGas + sizeGas, 1278240); + Assert.AreEqual(verificationGas + sizeGas, 1279270); // final assert Assert.AreEqual(tx.NetworkFee, verificationGas + sizeGas); } @@ -714,7 +713,7 @@ public void FeeIsSignatureContract_TestScope_CurrentHash_NEO_GAS() // get sizeGas var sizeGas = tx.Size * NativeContract.Policy.GetFeePerByte(snapshot); // final check on sum: verification_cost + tx_size - Assert.AreEqual(verificationGas + sizeGas, 1298240); + Assert.AreEqual(verificationGas + sizeGas, 1299270); // final assert Assert.AreEqual(tx.NetworkFee, verificationGas + sizeGas); } @@ -1062,7 +1061,7 @@ public void FeeIsSignatureContract_TestScope_Global_Default() // get sizeGas var sizeGas = tx.Size * NativeContract.Policy.GetFeePerByte(snapshot); // final check on sum: verification_cost + tx_size - Assert.AreEqual(verificationGas + sizeGas, 1257240); + Assert.AreEqual(verificationGas + sizeGas, 1258270); // final assert Assert.AreEqual(tx.NetworkFee, verificationGas + sizeGas); } diff --git a/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs b/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs index 502317e604..87c82124b5 100644 --- a/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs +++ b/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs @@ -82,9 +82,9 @@ public void MaxSize_OK() // Check max size - witness.Size.Should().Be(1003); + witness.Size.Should().Be(1004); witness.InvocationScript.GetVarSize().Should().Be(653); - witness.VerificationScript.GetVarSize().Should().Be(350); + witness.VerificationScript.GetVarSize().Should().Be(351); Assert.IsTrue(witness.Size <= 1024); diff --git a/neo.UnitTests/SmartContract/UT_Contract.cs b/neo.UnitTests/SmartContract/UT_Contract.cs index 458128f569..c0f4a86cf1 100644 --- a/neo.UnitTests/SmartContract/UT_Contract.cs +++ b/neo.UnitTests/SmartContract/UT_Contract.cs @@ -21,11 +21,12 @@ public void TestGetAddress() KeyPair key = new KeyPair(privateKey); Contract contract = Contract.CreateSignatureContract(key.PublicKey); byte[] script = contract.Script; - byte[] expectedArray = new byte[39]; + byte[] expectedArray = new byte[40]; expectedArray[0] = 0x21; Array.Copy(key.PublicKey.EncodePoint(true), 0, expectedArray, 1, 33); - expectedArray[34] = 0x68; - Array.Copy(BitConverter.GetBytes(InteropService.Neo_Crypto_CheckSig), 0, expectedArray, 35, 4); + expectedArray[34] = 0x50; + expectedArray[35] = 0x68; + Array.Copy(BitConverter.GetBytes(InteropService.Neo_Crypto_ECDsaVerify), 0, expectedArray, 36, 4); Assert.AreEqual(expectedArray.ToScriptHash().ToAddress(), contract.Address); } @@ -38,11 +39,12 @@ public void TestGetScriptHash() KeyPair key = new KeyPair(privateKey); Contract contract = Contract.CreateSignatureContract(key.PublicKey); byte[] script = contract.Script; - byte[] expectedArray = new byte[39]; + byte[] expectedArray = new byte[40]; expectedArray[0] = 0x21; Array.Copy(key.PublicKey.EncodePoint(true), 0, expectedArray, 1, 33); - expectedArray[34] = 0x68; - Array.Copy(BitConverter.GetBytes(InteropService.Neo_Crypto_CheckSig), 0, expectedArray, 35, 4); + expectedArray[34] = 0x50; + expectedArray[35] = 0x68; + Array.Copy(BitConverter.GetBytes(InteropService.Neo_Crypto_ECDsaVerify), 0, expectedArray, 36, 4); Assert.AreEqual(expectedArray.ToScriptHash(), contract.ScriptHash); } @@ -73,15 +75,16 @@ public void TestCreateMultiSigContract() publicKeys[1] = key2.PublicKey; publicKeys = publicKeys.OrderBy(p => p).ToArray(); Contract contract = Contract.CreateMultiSigContract(2, publicKeys); - byte[] expectedArray = new byte[75]; + byte[] expectedArray = new byte[76]; expectedArray[0] = 0x52; expectedArray[1] = 0x21; Array.Copy(publicKeys[0].EncodePoint(true), 0, expectedArray, 2, 33); expectedArray[35] = 0x21; Array.Copy(publicKeys[1].EncodePoint(true), 0, expectedArray, 36, 33); expectedArray[69] = 0x52; - expectedArray[70] = 0x68; - Array.Copy(BitConverter.GetBytes(InteropService.Neo_Crypto_CheckMultiSig), 0, expectedArray, 71, 4); + expectedArray[70] = 0x50; + expectedArray[71] = 0x68; + Array.Copy(BitConverter.GetBytes(InteropService.Neo_Crypto_ECDsaCheckMultiSig), 0, expectedArray, 72, 4); Assert.AreEqual(Encoding.Default.GetString(expectedArray), Encoding.Default.GetString(contract.Script)); Assert.AreEqual(2, contract.ParameterList.Length); Assert.AreEqual(ContractParameterType.Signature, contract.ParameterList[0]); @@ -106,15 +109,16 @@ public void TestCreateMultiSigRedeemScript() Action action = () => Contract.CreateMultiSigRedeemScript(0, publicKeys); action.Should().Throw(); byte[] script = Contract.CreateMultiSigRedeemScript(2, publicKeys); - byte[] expectedArray = new byte[75]; + byte[] expectedArray = new byte[76]; expectedArray[0] = 0x52; expectedArray[1] = 0x21; Array.Copy(publicKeys[0].EncodePoint(true), 0, expectedArray, 2, 33); expectedArray[35] = 0x21; Array.Copy(publicKeys[1].EncodePoint(true), 0, expectedArray, 36, 33); expectedArray[69] = 0x52; - expectedArray[70] = 0x68; - Array.Copy(BitConverter.GetBytes(InteropService.Neo_Crypto_CheckMultiSig), 0, expectedArray, 71, 4); + expectedArray[70] = 0x50; + expectedArray[71] = 0x68; + Array.Copy(BitConverter.GetBytes(InteropService.Neo_Crypto_ECDsaCheckMultiSig), 0, expectedArray, 72, 4); Assert.AreEqual(Encoding.Default.GetString(expectedArray), Encoding.Default.GetString(script)); } @@ -127,11 +131,12 @@ public void TestCreateSignatureContract() KeyPair key = new KeyPair(privateKey); Contract contract = Contract.CreateSignatureContract(key.PublicKey); byte[] script = contract.Script; - byte[] expectedArray = new byte[39]; + byte[] expectedArray = new byte[40]; expectedArray[0] = 0x21; Array.Copy(key.PublicKey.EncodePoint(true), 0, expectedArray, 1, 33); - expectedArray[34] = 0x68; - Array.Copy(BitConverter.GetBytes(InteropService.Neo_Crypto_CheckSig), 0, expectedArray, 35, 4); + expectedArray[34] = 0x50; + expectedArray[35] = 0x68; + Array.Copy(BitConverter.GetBytes(InteropService.Neo_Crypto_ECDsaVerify), 0, expectedArray, 36, 4); Assert.AreEqual(Encoding.Default.GetString(expectedArray), Encoding.Default.GetString(script)); Assert.AreEqual(1, contract.ParameterList.Length); Assert.AreEqual(ContractParameterType.Signature, contract.ParameterList[0]); @@ -145,11 +150,12 @@ public void TestCreateSignatureRedeemScript() rng.GetBytes(privateKey); KeyPair key = new KeyPair(privateKey); byte[] script = Contract.CreateSignatureRedeemScript(key.PublicKey); - byte[] expectedArray = new byte[39]; + byte[] expectedArray = new byte[40]; expectedArray[0] = 0x21; Array.Copy(key.PublicKey.EncodePoint(true), 0, expectedArray, 1, 33); - expectedArray[34] = 0x68; - Array.Copy(BitConverter.GetBytes(InteropService.Neo_Crypto_CheckSig), 0, expectedArray, 35, 4); + expectedArray[34] = 0x50; + expectedArray[35] = 0x68; + Array.Copy(BitConverter.GetBytes(InteropService.Neo_Crypto_ECDsaVerify), 0, expectedArray, 36, 4); Assert.AreEqual(Encoding.Default.GetString(expectedArray), Encoding.Default.GetString(script)); } } diff --git a/neo.UnitTests/SmartContract/UT_ContractParameterContext.cs b/neo.UnitTests/SmartContract/UT_ContractParameterContext.cs index 0e035349d1..f5fd304243 100644 --- a/neo.UnitTests/SmartContract/UT_ContractParameterContext.cs +++ b/neo.UnitTests/SmartContract/UT_ContractParameterContext.cs @@ -33,7 +33,7 @@ public static void ClassSetUp(TestContext context) public void TestGetComplete() { Transaction tx = TestUtils.GetTransaction(); - tx.Sender = UInt160.Parse("0xbecaad15c0ea585211faf99738a4354014f177f2"); + tx.Sender = UInt160.Parse("0x1a2791a63139294337863c7d822d17454876977c"); var context = new ContractParametersContext(tx); context.Completed.Should().BeFalse(); } @@ -42,11 +42,11 @@ public void TestGetComplete() public void TestToString() { Transaction tx = TestUtils.GetTransaction(); - tx.Sender = UInt160.Parse("0xbecaad15c0ea585211faf99738a4354014f177f2"); + tx.Sender = UInt160.Parse("0x1a2791a63139294337863c7d822d17454876977c"); var context = new ContractParametersContext(tx); context.Add(contract, 0, new byte[] { 0x01 }); string str = context.ToString(); - str.Should().Be("{\"type\":\"Neo.Network.P2P.Payloads.Transaction\",\"hex\":\"AAAAAADyd\\/EUQDWkOJf5\\u002BhFSWOrAFa3KvgAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAA==\",\"items\":{\"0xbecaad15c0ea585211faf99738a4354014f177f2\":{\"script\":\"IQJv8DuUkkHOHa3UNRnmlg4KhbQaaaBcMoEDqivOFZTKFmh0dHaq\",\"parameters\":[{\"type\":\"Signature\",\"value\":\"AQ==\"}]}}}"); + str.Should().Be(@"{""type"":""Neo.Network.P2P.Payloads.Transaction"",""hex"":""AAAAAAB8l3ZIRRctgn08hjdDKTkxppEnGgAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAA=="",""items"":{""0x1a2791a63139294337863c7d822d17454876977c"":{""script"":""IQJv8DuUkkHOHa3UNRnmlg4KhbQaaaBcMoEDqivOFZTKFlBoCpBq1A=="",""parameters"":[{""type"":""Signature"",""value"":""AQ==""}]}}}"); } [TestMethod] @@ -60,7 +60,7 @@ public void TestParse() [TestMethod] public void TestFromJson() { - Action action = () => ContractParametersContext.Parse("{\"type\":\"wrongType\",\"hex\":\"0000000000f277f1144035a43897f9fa115258eac015adcabe0000000000000000000000000000000000000000000100\",\"items\":{\"0xbecaad15c0ea585211faf99738a4354014f177f2\":{\"script\":\"21026ff03b949241ce1dadd43519e6960e0a85b41a69a05c328103aa2bce1594ca1668747476aa\",\"parameters\":[{\"type\":\"Signature\",\"value\":\"01\"}]}}}"); + Action action = () => ContractParametersContext.Parse("{\"type\":\"wrongType\",\"hex\":\"00000000007c97764845172d827d3c863743293931a691271a0000000000000000000000000000000000000000000100\",\"items\":{\"0x1a2791a63139294337863c7d822d17454876977c\":{\"script\":\"21026ff03b949241ce1dadd43519e6960e0a85b41a69a05c328103aa2bce1594ca1650680a906ad4\",\"parameters\":[{\"type\":\"Signature\",\"value\":\"01\"}]}}}"); action.Should().Throw(); } @@ -71,7 +71,7 @@ public void TestAdd() var context1 = new ContractParametersContext(tx); context1.Add(contract, 0, new byte[] { 0x01 }).Should().BeFalse(); - tx.Sender = UInt160.Parse("0xbecaad15c0ea585211faf99738a4354014f177f2"); + tx.Sender = UInt160.Parse("0x1a2791a63139294337863c7d822d17454876977c"); var context2 = new ContractParametersContext(tx); context2.Add(contract, 0, new byte[] { 0x01 }).Should().BeTrue(); //test repeatlly createItem @@ -82,7 +82,7 @@ public void TestAdd() public void TestGetParameter() { Transaction tx = TestUtils.GetTransaction(); - tx.Sender = UInt160.Parse("0xbecaad15c0ea585211faf99738a4354014f177f2"); + tx.Sender = UInt160.Parse("0x1a2791a63139294337863c7d822d17454876977c"); var context = new ContractParametersContext(tx); context.GetParameter(tx.Sender, 0).Should().BeNull(); @@ -95,7 +95,7 @@ public void TestGetParameter() public void TestGetWitnesses() { Transaction tx = TestUtils.GetTransaction(); - tx.Sender = UInt160.Parse("0xbecaad15c0ea585211faf99738a4354014f177f2"); + tx.Sender = UInt160.Parse("0x1a2791a63139294337863c7d822d17454876977c"); var context = new ContractParametersContext(tx); context.Add(contract, 0, new byte[] { 0x01 }); Witness[] witnesses = context.GetWitnesses(); @@ -108,7 +108,7 @@ public void TestGetWitnesses() public void TestAddSignature() { Transaction tx = TestUtils.GetTransaction(); - var singleSender = UInt160.Parse("0xbecaad15c0ea585211faf99738a4354014f177f2"); + var singleSender = UInt160.Parse("0x1a2791a63139294337863c7d822d17454876977c"); tx.Sender = singleSender; //singleSign @@ -138,7 +138,7 @@ public void TestAddSignature() key.PublicKey, key2.PublicKey }); - var multiSender = UInt160.Parse("0xa4712ed1a8d813561b28ec828930d85e6e08ec7a"); + var multiSender = UInt160.Parse("0xfc8b59f1a337dcc17b1a201d327a2081d41fac8d"); tx.Sender = multiSender; context = new ContractParametersContext(tx); context.AddSignature(multiSignContract, key.PublicKey, new byte[] { 0x01 }).Should().BeTrue(); diff --git a/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs b/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs index 885f3d3498..703fc6241e 100644 --- a/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs +++ b/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs @@ -11,6 +11,7 @@ using Neo.SmartContract.Enumerators; using Neo.SmartContract.Iterators; using Neo.SmartContract.Manifest; +using Neo.VM; using Neo.VM.Types; using Neo.Wallets; using System.Linq; @@ -33,12 +34,14 @@ public void TestCheckSig() byte[] signature = Crypto.Default.Sign(message, privateKey, pubkey.EncodePoint(false).Skip(1).ToArray()); engine.CurrentContext.EvaluationStack.Push(signature); engine.CurrentContext.EvaluationStack.Push(pubkey.EncodePoint(false)); - InteropService.Invoke(engine, InteropService.Neo_Crypto_CheckSig).Should().BeTrue(); + engine.CurrentContext.EvaluationStack.Push(StackItem.Null); + InteropService.Invoke(engine, InteropService.Neo_Crypto_ECDsaVerify).Should().BeTrue(); engine.CurrentContext.EvaluationStack.Pop().GetBoolean().Should().BeTrue(); engine.CurrentContext.EvaluationStack.Push(signature); engine.CurrentContext.EvaluationStack.Push(new byte[70]); - InteropService.Invoke(engine, InteropService.Neo_Crypto_CheckSig).Should().BeTrue(); + engine.CurrentContext.EvaluationStack.Push(StackItem.Null); + InteropService.Invoke(engine, InteropService.Neo_Crypto_ECDsaVerify).Should().BeTrue(); engine.CurrentContext.EvaluationStack.Pop().GetBoolean().Should().BeFalse(); } @@ -73,13 +76,15 @@ public void TestCrypto_CheckMultiSig() }; engine.CurrentContext.EvaluationStack.Push(signatures); engine.CurrentContext.EvaluationStack.Push(pubkeys); - InteropService.Invoke(engine, InteropService.Neo_Crypto_CheckMultiSig).Should().BeTrue(); + engine.CurrentContext.EvaluationStack.Push(StackItem.Null); + InteropService.Invoke(engine, InteropService.Neo_Crypto_ECDsaCheckMultiSig).Should().BeTrue(); engine.CurrentContext.EvaluationStack.Pop().GetBoolean().Should().BeTrue(); pubkeys = new VMArray(); engine.CurrentContext.EvaluationStack.Push(signatures); engine.CurrentContext.EvaluationStack.Push(pubkeys); - InteropService.Invoke(engine, InteropService.Neo_Crypto_CheckMultiSig).Should().BeFalse(); + engine.CurrentContext.EvaluationStack.Push(StackItem.Null); + InteropService.Invoke(engine, InteropService.Neo_Crypto_ECDsaCheckMultiSig).Should().BeFalse(); pubkeys = new VMArray { @@ -89,7 +94,8 @@ public void TestCrypto_CheckMultiSig() signatures = new VMArray(); engine.CurrentContext.EvaluationStack.Push(signatures); engine.CurrentContext.EvaluationStack.Push(pubkeys); - InteropService.Invoke(engine, InteropService.Neo_Crypto_CheckMultiSig).Should().BeFalse(); + engine.CurrentContext.EvaluationStack.Push(StackItem.Null); + InteropService.Invoke(engine, InteropService.Neo_Crypto_ECDsaCheckMultiSig).Should().BeFalse(); pubkeys = new VMArray { @@ -103,7 +109,8 @@ public void TestCrypto_CheckMultiSig() }; engine.CurrentContext.EvaluationStack.Push(signatures); engine.CurrentContext.EvaluationStack.Push(pubkeys); - InteropService.Invoke(engine, InteropService.Neo_Crypto_CheckMultiSig).Should().BeTrue(); + engine.CurrentContext.EvaluationStack.Push(StackItem.Null); + InteropService.Invoke(engine, InteropService.Neo_Crypto_ECDsaCheckMultiSig).Should().BeTrue(); engine.CurrentContext.EvaluationStack.Pop().GetBoolean().Should().BeFalse(); pubkeys = new VMArray @@ -118,7 +125,8 @@ public void TestCrypto_CheckMultiSig() }; engine.CurrentContext.EvaluationStack.Push(signatures); engine.CurrentContext.EvaluationStack.Push(pubkeys); - InteropService.Invoke(engine, InteropService.Neo_Crypto_CheckMultiSig).Should().BeTrue(); + engine.CurrentContext.EvaluationStack.Push(StackItem.Null); + InteropService.Invoke(engine, InteropService.Neo_Crypto_ECDsaCheckMultiSig).Should().BeTrue(); engine.CurrentContext.EvaluationStack.Pop().GetBoolean().Should().BeFalse(); } diff --git a/neo.UnitTests/SmartContract/UT_InteropService.cs b/neo.UnitTests/SmartContract/UT_InteropService.cs index fe28f1503d..cc6eac738a 100644 --- a/neo.UnitTests/SmartContract/UT_InteropService.cs +++ b/neo.UnitTests/SmartContract/UT_InteropService.cs @@ -365,7 +365,7 @@ public void TestCrypto_Verify() engine.CurrentContext.EvaluationStack.Push(signature); engine.CurrentContext.EvaluationStack.Push(pubkey.EncodePoint(false)); engine.CurrentContext.EvaluationStack.Push(message); - InteropService.Invoke(engine, InteropService.System_Crypto_Verify).Should().BeTrue(); + InteropService.Invoke(engine, InteropService.Neo_Crypto_ECDsaVerify).Should().BeTrue(); engine.CurrentContext.EvaluationStack.Pop().GetBoolean().Should().BeTrue(); byte[] wrongkey = pubkey.EncodePoint(false); @@ -373,8 +373,8 @@ public void TestCrypto_Verify() engine.CurrentContext.EvaluationStack.Push(signature); engine.CurrentContext.EvaluationStack.Push(wrongkey); engine.CurrentContext.EvaluationStack.Push(new InteropInterface(engine.ScriptContainer)); - InteropService.Invoke(engine, InteropService.System_Crypto_Verify).Should().BeFalse(); - + InteropService.Invoke(engine, InteropService.Neo_Crypto_ECDsaVerify).Should().BeTrue(); + engine.CurrentContext.EvaluationStack.Peek().GetBoolean().Should().BeFalse(); } [TestMethod] diff --git a/neo.UnitTests/Wallets/SQLite/UT_VerificationContract.cs b/neo.UnitTests/Wallets/SQLite/UT_VerificationContract.cs index 8f111f2112..70d0ba2e4b 100644 --- a/neo.UnitTests/Wallets/SQLite/UT_VerificationContract.cs +++ b/neo.UnitTests/Wallets/SQLite/UT_VerificationContract.cs @@ -120,11 +120,11 @@ public void TestSerialize() byte[] byteArray = new byte[stream.Length]; stream.Read(byteArray, 0, (int)stream.Length); byte[] script = Neo.SmartContract.Contract.CreateSignatureRedeemScript(key.PublicKey); - byte[] result = new byte[62]; + byte[] result = new byte[63]; result[20] = 0x01; result[21] = 0x00; - result[22] = 0x27; - Array.Copy(script, 0, result, 23, 39); + result[22] = 0x28; + Array.Copy(script, 0, result, 23, 40); Assert.AreEqual(Encoding.Default.GetString(result), Encoding.Default.GetString(byteArray)); } @@ -142,7 +142,7 @@ public void TestGetSize() Script = Neo.SmartContract.Contract.CreateSignatureRedeemScript(key.PublicKey), ParameterList = new[] { ContractParameterType.Signature } }; - Assert.AreEqual(62, contract1.Size); + Assert.AreEqual(63, contract1.Size); } } } diff --git a/neo.UnitTests/Wallets/UT_Wallet.cs b/neo.UnitTests/Wallets/UT_Wallet.cs index ed48a047e5..e6bf40721c 100644 --- a/neo.UnitTests/Wallets/UT_Wallet.cs +++ b/neo.UnitTests/Wallets/UT_Wallet.cs @@ -168,9 +168,9 @@ public void TestGetVersion() public void TestGetAccount1() { MyWallet wallet = new MyWallet(); - wallet.CreateAccount(UInt160.Parse("522a2b818c308c7a2c77cfdda11763fe043bfb40")); + wallet.CreateAccount(UInt160.Parse("0xc43d04da83afcf7df3b2908c169cfbfbf7512d7f")); WalletAccount account = wallet.GetAccount(ECCurve.Secp256r1.G); - account.ScriptHash.Should().Be(UInt160.Parse("0x522a2b818c308c7a2c77cfdda11763fe043bfb40")); + account.ScriptHash.Should().Be(UInt160.Parse("0xc43d04da83afcf7df3b2908c169cfbfbf7512d7f")); } [TestMethod] diff --git a/neo/Network/P2P/Payloads/Witness.cs b/neo/Network/P2P/Payloads/Witness.cs index 55ba4f2564..1cd5bf7ee8 100644 --- a/neo/Network/P2P/Payloads/Witness.cs +++ b/neo/Network/P2P/Payloads/Witness.cs @@ -31,7 +31,7 @@ void ISerializable.Deserialize(BinaryReader reader) // This is designed to allow a MultiSig 10/10 (around 1003 bytes) ~1024 bytes // Invocation = 10 * 64 + 10 = 650 ~ 664 (exact is 653) InvocationScript = reader.ReadVarBytes(664); - // Verification = 10 * 33 + 10 = 340 ~ 360 (exact is 350) + // Verification = 10 * 33 + 10 = 340 ~ 360 (exact is 351) VerificationScript = reader.ReadVarBytes(360); } diff --git a/neo/Network/RPC/TransactionManager.cs b/neo/Network/RPC/TransactionManager.cs index d4a651fd78..ba714a52ef 100644 --- a/neo/Network/RPC/TransactionManager.cs +++ b/neo/Network/RPC/TransactionManager.cs @@ -98,7 +98,7 @@ private long EstimateNetworkFee() foreach (var hash in hashes) { size += 166; - networkFee += ApplicationEngine.OpCodePrices[OpCode.PUSHBYTES64] + ApplicationEngine.OpCodePrices[OpCode.PUSHBYTES33] + InteropService.GetPrice(InteropService.Neo_Crypto_CheckSig, null); + networkFee += ApplicationEngine.OpCodePrices[OpCode.PUSHBYTES64] + ApplicationEngine.OpCodePrices[OpCode.PUSHBYTES33] + InteropService.GetPrice(InteropService.Neo_Crypto_ECDsaVerify, null); } networkFee += size * new PolicyAPI(rpcClient).GetFeePerByte(); diff --git a/neo/SmartContract/Contract.cs b/neo/SmartContract/Contract.cs index 58e32768d7..35fd0cb95b 100644 --- a/neo/SmartContract/Contract.cs +++ b/neo/SmartContract/Contract.cs @@ -81,7 +81,8 @@ public static byte[] CreateMultiSigRedeemScript(int m, params ECPoint[] publicKe sb.EmitPush(publicKey.EncodePoint(true)); } sb.EmitPush(publicKeys.Length); - sb.EmitSysCall(InteropService.Neo_Crypto_CheckMultiSig); + sb.Emit(OpCode.PUSHNULL); + sb.EmitSysCall(InteropService.Neo_Crypto_ECDsaCheckMultiSig); return sb.ToArray(); } } @@ -100,7 +101,8 @@ public static byte[] CreateSignatureRedeemScript(ECPoint publicKey) using (ScriptBuilder sb = new ScriptBuilder()) { sb.EmitPush(publicKey.EncodePoint(true)); - sb.EmitSysCall(InteropService.Neo_Crypto_CheckSig); + sb.Emit(OpCode.PUSHNULL); + sb.EmitSysCall(InteropService.Neo_Crypto_ECDsaVerify); return sb.ToArray(); } } diff --git a/neo/SmartContract/Helper.cs b/neo/SmartContract/Helper.cs index 809ec8345f..4f7e320c37 100644 --- a/neo/SmartContract/Helper.cs +++ b/neo/SmartContract/Helper.cs @@ -115,7 +115,7 @@ public static bool IsMultiSigContract(this byte[] script, out int m, out int n) { m = 0; n = 0; int i = 0; - if (script.Length < 41) return false; + if (script.Length < 42) return false; if (script[i] > (byte)OpCode.PUSH16) return false; if (script[i] < (byte)OpCode.PUSH1 && script[i] != 1 && script[i] != 2) return false; switch (script[i]) @@ -154,19 +154,21 @@ public static bool IsMultiSigContract(this byte[] script, out int m, out int n) if (n != script[i++] - 80) return false; break; } + if (script[i++] != (byte)OpCode.PUSHNULL) return false; if (script[i++] != (byte)OpCode.SYSCALL) return false; if (script.Length != i + 4) return false; - if (BitConverter.ToUInt32(script, i) != InteropService.Neo_Crypto_CheckMultiSig) + if (BitConverter.ToUInt32(script, i) != InteropService.Neo_Crypto_ECDsaCheckMultiSig) return false; return true; } public static bool IsSignatureContract(this byte[] script) { - if (script.Length != 39) return false; + if (script.Length != 40) return false; if (script[0] != (byte)OpCode.PUSHBYTES33 - || script[34] != (byte)OpCode.SYSCALL - || BitConverter.ToUInt32(script, 35) != InteropService.Neo_Crypto_CheckSig) + || script[34] != (byte)OpCode.PUSHNULL + || script[35] != (byte)OpCode.SYSCALL + || BitConverter.ToUInt32(script, 36) != InteropService.Neo_Crypto_ECDsaVerify) return false; return true; } diff --git a/neo/SmartContract/InteropService.NEO.cs b/neo/SmartContract/InteropService.NEO.cs index e500eeb235..90a49a4df2 100644 --- a/neo/SmartContract/InteropService.NEO.cs +++ b/neo/SmartContract/InteropService.NEO.cs @@ -2,6 +2,7 @@ using Neo.IO.Json; using Neo.Ledger; using Neo.Network.P2P; +using Neo.Network.P2P.Payloads; using Neo.SmartContract.Enumerators; using Neo.SmartContract.Iterators; using Neo.SmartContract.Manifest; @@ -17,8 +18,8 @@ namespace Neo.SmartContract static partial class InteropService { public static readonly uint Neo_Native_Deploy = Register("Neo.Native.Deploy", Native_Deploy, 0, TriggerType.Application); - public static readonly uint Neo_Crypto_CheckSig = Register("Neo.Crypto.CheckSig", Crypto_CheckSig, 0_01000000, TriggerType.All); - public static readonly uint Neo_Crypto_CheckMultiSig = Register("Neo.Crypto.CheckMultiSig", Crypto_CheckMultiSig, GetCheckMultiSigPrice, TriggerType.All); + public static readonly uint Neo_Crypto_ECDsaVerify = Register("Neo.Crypto.ECDsaVerify", Crypto_ECDsaVerify, 0_01000000, TriggerType.All); + public static readonly uint Neo_Crypto_ECDsaCheckMultiSig = Register("Neo.Crypto.ECDsaCheckMultiSig", Crypto_ECDsaCheckMultiSig, GetECDsaCheckMultiSigPrice, TriggerType.All); public static readonly uint Neo_Account_IsStandard = Register("Neo.Account.IsStandard", Account_IsStandard, 0_00030000, TriggerType.All); public static readonly uint Neo_Contract_Create = Register("Neo.Contract.Create", Contract_Create, GetDeploymentPrice, TriggerType.Application); public static readonly uint Neo_Contract_Update = Register("Neo.Contract.Update", Contract_Update, GetDeploymentPrice, TriggerType.Application); @@ -41,15 +42,15 @@ static InteropService() Register(contract.ServiceName, contract.Invoke, contract.GetPrice, TriggerType.System | TriggerType.Application); } - private static long GetCheckMultiSigPrice(RandomAccessStack stack) + private static long GetECDsaCheckMultiSigPrice(RandomAccessStack stack) { - if (stack.Count == 0) return 0; - var item = stack.Peek(); + if (stack.Count < 2) return 0; + var item = stack.Peek(1); int n; if (item is VMArray array) n = array.Count; else n = (int)item.GetBigInteger(); if (n < 1) return 0; - return GetPrice(Neo_Crypto_CheckSig, stack) * n; + return GetPrice(Neo_Crypto_ECDsaVerify, stack) * n; } private static long GetDeploymentPrice(RandomAccessStack stack) @@ -73,14 +74,20 @@ private static bool Native_Deploy(ApplicationEngine engine) return true; } - private static bool Crypto_CheckSig(ApplicationEngine engine) + private static bool Crypto_ECDsaVerify(ApplicationEngine engine) { + StackItem item0 = engine.CurrentContext.EvaluationStack.Pop(); + byte[] message = item0 switch + { + InteropInterface _interface => _interface.GetInterface().GetHashData(), + Null _ => engine.ScriptContainer.GetHashData(), + _ => item0.GetByteArray() + }; byte[] pubkey = engine.CurrentContext.EvaluationStack.Pop().GetByteArray(); byte[] signature = engine.CurrentContext.EvaluationStack.Pop().GetByteArray(); - try { - engine.CurrentContext.EvaluationStack.Push(Crypto.Default.VerifySignature(engine.ScriptContainer.GetHashData(), signature, pubkey)); + engine.CurrentContext.EvaluationStack.Push(Crypto.Default.VerifySignature(message, signature, pubkey)); } catch (ArgumentException) { @@ -89,12 +96,18 @@ private static bool Crypto_CheckSig(ApplicationEngine engine) return true; } - private static bool Crypto_CheckMultiSig(ApplicationEngine engine) + private static bool Crypto_ECDsaCheckMultiSig(ApplicationEngine engine) { + StackItem item0 = engine.CurrentContext.EvaluationStack.Pop(); + byte[] message = item0 switch + { + InteropInterface _interface => _interface.GetInterface().GetHashData(), + Null _ => engine.ScriptContainer.GetHashData(), + _ => item0.GetByteArray() + }; int n; byte[][] pubkeys; StackItem item = engine.CurrentContext.EvaluationStack.Pop(); - if (item is VMArray array1) { pubkeys = array1.Select(p => p.GetByteArray()).ToArray(); @@ -109,7 +122,6 @@ private static bool Crypto_CheckMultiSig(ApplicationEngine engine) for (int i = 0; i < n; i++) pubkeys[i] = engine.CurrentContext.EvaluationStack.Pop().GetByteArray(); } - int m; byte[][] signatures; item = engine.CurrentContext.EvaluationStack.Pop(); @@ -127,7 +139,6 @@ private static bool Crypto_CheckMultiSig(ApplicationEngine engine) for (int i = 0; i < m; i++) signatures[i] = engine.CurrentContext.EvaluationStack.Pop().GetByteArray(); } - byte[] message = engine.ScriptContainer.GetHashData(); bool fSuccess = true; try { diff --git a/neo/SmartContract/InteropService.cs b/neo/SmartContract/InteropService.cs index eed16fe17a..be80366811 100644 --- a/neo/SmartContract/InteropService.cs +++ b/neo/SmartContract/InteropService.cs @@ -2,7 +2,6 @@ using Neo.Cryptography.ECC; using Neo.IO; using Neo.Ledger; -using Neo.Network.P2P; using Neo.Network.P2P.Payloads; using Neo.Persistence; using Neo.SmartContract.Manifest; @@ -42,7 +41,6 @@ public static partial class InteropService public static readonly uint System_Runtime_Deserialize = Register("System.Runtime.Deserialize", Runtime_Deserialize, 0_00500000, TriggerType.All); public static readonly uint System_Runtime_GetInvocationCounter = Register("System.Runtime.GetInvocationCounter", Runtime_GetInvocationCounter, 0_00000400, TriggerType.All); public static readonly uint System_Runtime_GetNotifications = Register("System.Runtime.GetNotifications", Runtime_GetNotifications, 0_00010000, TriggerType.All); - public static readonly uint System_Crypto_Verify = Register("System.Crypto.Verify", Crypto_Verify, 0_01000000, TriggerType.All); public static readonly uint System_Blockchain_GetHeight = Register("System.Blockchain.GetHeight", Blockchain_GetHeight, 0_00000400, TriggerType.Application); public static readonly uint System_Blockchain_GetBlock = Register("System.Blockchain.GetBlock", Blockchain_GetBlock, 0_02500000, TriggerType.Application); public static readonly uint System_Blockchain_GetTransaction = Register("System.Blockchain.GetTransaction", Blockchain_GetTransaction, 0_01000000, TriggerType.Application); @@ -329,23 +327,6 @@ private static bool Runtime_Deserialize(ApplicationEngine engine) return true; } - private static bool Crypto_Verify(ApplicationEngine engine) - { - StackItem item0 = engine.CurrentContext.EvaluationStack.Pop(); - byte[] message; - if (item0 is InteropInterface _interface) - message = _interface.GetInterface().GetHashData(); - else - message = item0.GetByteArray(); - byte[] pubkey = engine.CurrentContext.EvaluationStack.Pop().GetByteArray(); - if (pubkey[0] != 2 && pubkey[0] != 3 && pubkey[0] != 4) - return false; - byte[] signature = engine.CurrentContext.EvaluationStack.Pop().GetByteArray(); - bool result = Crypto.Default.VerifySignature(message, signature, pubkey); - engine.CurrentContext.EvaluationStack.Push(result); - return true; - } - private static bool Blockchain_GetHeight(ApplicationEngine engine) { engine.CurrentContext.EvaluationStack.Push(engine.Snapshot.Height); diff --git a/neo/Wallets/Wallet.cs b/neo/Wallets/Wallet.cs index 5149c2b2fe..bc52b9b368 100644 --- a/neo/Wallets/Wallet.cs +++ b/neo/Wallets/Wallet.cs @@ -353,7 +353,7 @@ public static long CalculateNetWorkFee(byte[] witness_script, ref int size) if (witness_script.IsSignatureContract()) { size += 66 + witness_script.GetVarSize(); - networkFee += ApplicationEngine.OpCodePrices[OpCode.PUSHBYTES64] + ApplicationEngine.OpCodePrices[OpCode.PUSHBYTES33] + InteropService.GetPrice(InteropService.Neo_Crypto_CheckSig, null); + networkFee += ApplicationEngine.OpCodePrices[OpCode.PUSHBYTES64] + ApplicationEngine.OpCodePrices[OpCode.PUSHBYTES33] + ApplicationEngine.OpCodePrices[OpCode.PUSHNULL] + InteropService.GetPrice(InteropService.Neo_Crypto_ECDsaVerify, null); } else if (witness_script.IsMultiSigContract(out int m, out int n)) { @@ -365,7 +365,7 @@ public static long CalculateNetWorkFee(byte[] witness_script, ref int size) networkFee += ApplicationEngine.OpCodePrices[OpCode.PUSHBYTES33] * n; using (ScriptBuilder sb = new ScriptBuilder()) networkFee += ApplicationEngine.OpCodePrices[(OpCode)sb.EmitPush(n).ToArray()[0]]; - networkFee += InteropService.GetPrice(InteropService.Neo_Crypto_CheckSig, null) * n; + networkFee += ApplicationEngine.OpCodePrices[OpCode.PUSHNULL] + InteropService.GetPrice(InteropService.Neo_Crypto_ECDsaVerify, null) * n; } else { diff --git a/neo/neo.csproj b/neo/neo.csproj index b60b204915..98824eb526 100644 --- a/neo/neo.csproj +++ b/neo/neo.csproj @@ -17,7 +17,7 @@ Neo The Neo Project Neo - latest + preview