From d0c29f52c906c395923a80e81c08dec446d0d380 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 17 Aug 2020 22:02:15 +0300 Subject: [PATCH] core: verification script must return exactly one value C# node is quite picky as it expects there to be exactly one value returned, but our testchain actually adds 4 signatures for multisig cases instead of 3 which makes it technically incompatible with C# node. --- pkg/core/blockchain.go | 3 +++ pkg/core/blockchain_test.go | 9 +++++++++ pkg/internal/testchain/address.go | 2 +- pkg/rpc/server/server_test.go | 6 +++--- pkg/rpc/server/testdata/testblocks.acc | Bin 7230 -> 6681 bytes 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 182ed9ac5..ab8cae8b7 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -1490,6 +1490,9 @@ func (bc *Blockchain) verifyHashAgainstScript(hash util.Uint160, witness *transa if !resEl.Bool() { return fmt.Errorf("%w: invalid signature", ErrVerificationFailed) } + if vm.Estack().Len() != 0 { + return fmt.Errorf("%w: expected exactly one returned value", ErrVerificationFailed) + } if useKeys { bc.keyCacheLock.RLock() _, ok := bc.keyCache[hash] diff --git a/pkg/core/blockchain_test.go b/pkg/core/blockchain_test.go index 7f281b012..18b520288 100644 --- a/pkg/core/blockchain_test.go +++ b/pkg/core/blockchain_test.go @@ -354,6 +354,15 @@ func TestVerifyHashAgainstScript(t *testing.T) { err := bc.verifyHashAgainstScript(hash.Hash160(verif), w, ic, false, gas) require.True(t, errors.Is(err, ErrVerificationFailed)) }) + t.Run("TooManyResults", func(t *testing.T) { + verif := []byte{byte(opcode.NOP)} + w := &transaction.Witness{ + InvocationScript: []byte{byte(opcode.PUSH1), byte(opcode.PUSH1)}, + VerificationScript: verif, + } + err := bc.verifyHashAgainstScript(hash.Hash160(verif), w, ic, false, gas) + require.True(t, errors.Is(err, ErrVerificationFailed)) + }) } func TestHasBlock(t *testing.T) { diff --git a/pkg/internal/testchain/address.go b/pkg/internal/testchain/address.go index b242b5747..27cc58d6a 100644 --- a/pkg/internal/testchain/address.go +++ b/pkg/internal/testchain/address.go @@ -84,7 +84,7 @@ func MultisigAddress() string { // Sign signs data by all consensus nodes and returns invocation script. func Sign(data []byte) []byte { buf := io.NewBufBinWriter() - for i := 0; i < Size(); i++ { + for i := 0; i < 3; i++ { pKey := PrivateKey(i) sig := pKey.Sign(data) if len(sig) != 64 { diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 8c6c3cba6..d0a759625 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -52,8 +52,8 @@ type rpcTestCase struct { check func(t *testing.T, e *executor, result interface{}) } -const testContractHash = "5b5f77b947194ba45ff5fa1ba6e066af5636d110" -const deploymentTxHash = "af0f94f6bdc5aada7abf1db19f1fcd2ea56cea596c41dc4abdfa6cd9664a7d72" +const testContractHash = "93c4983afe01a75f74c1e56011bd630e9d8cc755" +const deploymentTxHash = "583cf0e49d69d8854869efc3e97ad741061da478292a7280580789351a39a1ac" var rpcTestCases = map[string][]rpcTestCase{ "getapplicationlog": { @@ -1027,7 +1027,7 @@ func checkNep5Balances(t *testing.T, e *executor, acc interface{}) { }, { Asset: e.chain.UtilityTokenHash(), - Amount: "915.61054740", + Amount: "915.61059740", LastUpdated: 6, }}, Address: testchain.PrivateKeyByID(0).GetScriptHash().StringLE(), diff --git a/pkg/rpc/server/testdata/testblocks.acc b/pkg/rpc/server/testdata/testblocks.acc index 430f85dcd94de8c18a4ecd3ec43ef900b4ba7326..baacf2786d048814a60ab0e9c4c5e04db2849564 100644 GIT binary patch delta 2384 zcmaKuc|6qH8^>oX!;BGzK}b@z5R<`-+-69OOxCd!X0paFjK(rIOQrl|pXzI}jhKp( zRBEzQlYL2-Y`GL6OGrX?7eDv+*L~gRpL3q`I_JF3^LgIS^E%a-bTkA40)evlZ$Zp> zOB>g3S?{}2564e082XtQZtf9kSu@R1?2GhauX9{%GQJ%5)`*Rov?uxwWw@=0=+pa_ z&L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