From 3d3fe9398eff29ffc912b5d3b7024dae96683907 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 10 Jun 2020 11:20:57 +0300 Subject: [PATCH 1/4] core: remove Neo.Header/Witness/Account.* interops They are not present in NEO3. --- pkg/compiler/syscall.go | 22 ------ pkg/core/interop_neo.go | 105 --------------------------- pkg/core/interop_neo_test.go | 70 ------------------ pkg/core/interop_system.go | 15 ---- pkg/core/interops.go | 18 ----- pkg/core/interops_test.go | 10 --- pkg/interop/account/account.go | 43 ----------- pkg/interop/blockchain/blockchain.go | 29 +------- pkg/interop/header/header.go | 61 ---------------- pkg/interop/witness/witness.go | 14 ---- 10 files changed, 2 insertions(+), 385 deletions(-) delete mode 100644 pkg/interop/account/account.go delete mode 100644 pkg/interop/header/header.go delete mode 100644 pkg/interop/witness/witness.go diff --git a/pkg/compiler/syscall.go b/pkg/compiler/syscall.go index f6bbf3ccf..b8f597736 100644 --- a/pkg/compiler/syscall.go +++ b/pkg/compiler/syscall.go @@ -1,12 +1,6 @@ package compiler var syscalls = map[string]map[string]string{ - "account": { - "GetBalance": "Neo.Account.GetBalance", - "GetScriptHash": "Neo.Account.GetScriptHash", - "GetVotes": "Neo.Account.GetVotes", - "IsStandard": "Neo.Account.IsStandard", - }, "crypto": { "ECDsaVerify": "Neo.Crypto.ECDsaVerify", }, @@ -35,25 +29,12 @@ var syscalls = map[string]map[string]string{ "Deserialize": "Neo.Runtime.Deserialize", }, "blockchain": { - "GetAccount": "Neo.Blockchain.GetAccount", "GetBlock": "System.Blockchain.GetBlock", "GetContract": "Neo.Blockchain.GetContract", - "GetHeader": "Neo.Blockchain.GetHeader", "GetHeight": "Neo.Blockchain.GetHeight", "GetTransaction": "System.Blockchain.GetTransaction", "GetTransactionFromBlock": "System.Blockchain.GetTransactionFromBlock", "GetTransactionHeight": "System.Blockchain.GetTransactionHeight", - "GetValidators": "Neo.Blockchain.GetValidators", - }, - "header": { - "GetIndex": "Neo.Header.GetIndex", - "GetHash": "Neo.Header.GetHash", - "GetPrevHash": "Neo.Header.GetPrevHash", - "GetTimestamp": "Neo.Header.GetTimestamp", - "GetVersion": "Neo.Header.GetVersion", - "GetMerkleRoot": "Neo.Header.GetMerkleRoot", - "GetConsensusData": "Neo.Header.GetConsensusData", - "GetNextConsensus": "Neo.Header.GetNextConsensus", }, "contract": { "GetScript": "Neo.Contract.GetScript", @@ -78,7 +59,4 @@ var syscalls = map[string]map[string]string{ "Value": "Neo.Iterator.Value", "Values": "Neo.Iterator.Values", }, - "witness": { - "GetVerificationScript": "Neo.Witness.GetVerificationScript", - }, } diff --git a/pkg/core/interop_neo.go b/pkg/core/interop_neo.go index d855890f8..a79757cb7 100644 --- a/pkg/core/interop_neo.go +++ b/pkg/core/interop_neo.go @@ -8,10 +8,8 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/interop" "github.com/nspcc-dev/neo-go/pkg/core/state" - "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" - "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" ) @@ -27,109 +25,6 @@ const ( MaxContractStringLen = 252 ) -// headerGetVersion returns version from the header. -func headerGetVersion(ic *interop.Context, v *vm.VM) error { - header, err := popHeaderFromVM(v) - if err != nil { - return err - } - v.Estack().PushVal(header.Version) - return nil -} - -// headerGetMerkleRoot returns version from the header. -func headerGetMerkleRoot(ic *interop.Context, v *vm.VM) error { - header, err := popHeaderFromVM(v) - if err != nil { - return err - } - v.Estack().PushVal(header.MerkleRoot.BytesBE()) - return nil -} - -// headerGetNextConsensus returns version from the header. -func headerGetNextConsensus(ic *interop.Context, v *vm.VM) error { - header, err := popHeaderFromVM(v) - if err != nil { - return err - } - v.Estack().PushVal(header.NextConsensus.BytesBE()) - return nil -} - -// witnessGetVerificationScript returns current witness' script. -func witnessGetVerificationScript(ic *interop.Context, v *vm.VM) error { - witInterface := v.Estack().Pop().Value() - wit, ok := witInterface.(*transaction.Witness) - if !ok { - return errors.New("value is not a witness") - } - // It's important not to share wit.VerificationScript slice with the code running in VM. - script := make([]byte, len(wit.VerificationScript)) - copy(script, wit.VerificationScript) - v.Estack().PushVal(script) - return nil -} - -// bcGetAccount returns or creates an account. -func bcGetAccount(ic *interop.Context, v *vm.VM) error { - accbytes := v.Estack().Pop().Bytes() - acchash, err := util.Uint160DecodeBytesBE(accbytes) - if err != nil { - return err - } - acc, err := ic.DAO.GetAccountStateOrNew(acchash) - if err != nil { - return err - } - v.Estack().PushVal(stackitem.NewInterop(acc)) - return nil -} - -// accountGetBalance returns balance for a given account. -func accountGetBalance(ic *interop.Context, v *vm.VM) error { - accInterface := v.Estack().Pop().Value() - acc, ok := accInterface.(*state.Account) - if !ok { - return fmt.Errorf("%T is not an account state", acc) - } - asbytes := v.Estack().Pop().Bytes() - ashash, err := util.Uint256DecodeBytesBE(asbytes) - if err != nil { - return err - } - balance, ok := acc.GetBalanceValues()[ashash] - if !ok { - balance = util.Fixed8(0) - } - v.Estack().PushVal(int64(balance)) - return nil -} - -// accountGetScriptHash returns script hash of a given account. -func accountGetScriptHash(ic *interop.Context, v *vm.VM) error { - accInterface := v.Estack().Pop().Value() - acc, ok := accInterface.(*state.Account) - if !ok { - return fmt.Errorf("%T is not an account state", acc) - } - v.Estack().PushVal(acc.ScriptHash.BytesBE()) - return nil -} - -// accountIsStandard checks whether given account is standard. -func accountIsStandard(ic *interop.Context, v *vm.VM) error { - accbytes := v.Estack().Pop().Bytes() - acchash, err := util.Uint160DecodeBytesBE(accbytes) - if err != nil { - return err - } - contract, err := ic.DAO.GetContractState(acchash) - res := err != nil || vm.IsStandardContract(contract.Script) - v.Estack().PushVal(res) - return nil -} - // storageFind finds stored key-value pair. func storageFind(ic *interop.Context, v *vm.VM) error { stcInterface := v.Estack().Pop().Value() diff --git a/pkg/core/interop_neo_test.go b/pkg/core/interop_neo_test.go index 626e0c5cd..853e9850d 100644 --- a/pkg/core/interop_neo_test.go +++ b/pkg/core/interop_neo_test.go @@ -2,7 +2,6 @@ package core import ( "fmt" - "math/big" "testing" "github.com/nspcc-dev/neo-go/pkg/core/block" @@ -136,64 +135,6 @@ func TestStorageFind(t *testing.T) { }) } -func TestHeaderGetVersion(t *testing.T) { - v, block, context, chain := createVMAndPushBlock(t) - defer chain.Close() - - err := headerGetVersion(context, v) - require.NoError(t, err) - value := v.Estack().Pop().Value().(*big.Int) - require.Equal(t, uint64(block.Version), value.Uint64()) -} - -func TestHeaderGetVersion_Negative(t *testing.T) { - v := vm.New() - block := newDumbBlock() - chain := newTestChain(t) - defer chain.Close() - context := chain.newInteropContext(trigger.Application, dao.NewSimple(storage.NewMemoryStore()), block, nil) - v.Estack().PushVal(stackitem.NewBool(false)) - - err := headerGetVersion(context, v) - require.Errorf(t, err, "value is not a header or block") -} - -func TestHeaderGetMerkleRoot(t *testing.T) { - v, block, context, chain := createVMAndPushBlock(t) - defer chain.Close() - - err := headerGetMerkleRoot(context, v) - require.NoError(t, err) - value := v.Estack().Pop().Value() - require.Equal(t, block.MerkleRoot.BytesBE(), value) -} - -func TestHeaderGetNextConsensus(t *testing.T) { - v, block, context, chain := createVMAndPushBlock(t) - defer chain.Close() - - err := headerGetNextConsensus(context, v) - require.NoError(t, err) - value := v.Estack().Pop().Value() - require.Equal(t, block.NextConsensus.BytesBE(), value) -} - -func TestWitnessGetVerificationScript(t *testing.T) { - v := vm.New() - script := []byte{byte(opcode.PUSHM1), byte(opcode.RET)} - witness := transaction.Witness{InvocationScript: nil, VerificationScript: script} - - chain := newTestChain(t) - defer chain.Close() - - context := chain.newInteropContext(trigger.Application, dao.NewSimple(storage.NewMemoryStore()), nil, nil) - v.Estack().PushVal(stackitem.NewInterop(&witness)) - err := witnessGetVerificationScript(context, v) - require.NoError(t, err) - value := v.Estack().Pop().Value().([]byte) - require.Equal(t, witness.VerificationScript, value) -} - func TestECDSAVerify(t *testing.T) { priv, err := keys.NewPrivateKey() require.NoError(t, err) @@ -270,17 +211,6 @@ func TestECDSAVerify(t *testing.T) { }) } -func TestAccountGetScriptHash(t *testing.T) { - v, accState, context, chain := createVMAndAccState(t) - defer chain.Close() - v.Estack().PushVal(stackitem.NewInterop(accState)) - - err := accountGetScriptHash(context, v) - require.NoError(t, err) - hash := v.Estack().Pop().Value() - require.Equal(t, accState.ScriptHash.BytesBE(), hash) -} - func TestContractGetScript(t *testing.T) { v, contractState, context, chain := createVMAndContractState(t) defer chain.Close() diff --git a/pkg/core/interop_system.go b/pkg/core/interop_system.go index 9a30fbaf8..2c4f6335e 100644 --- a/pkg/core/interop_system.go +++ b/pkg/core/interop_system.go @@ -98,21 +98,6 @@ func bcGetContract(ic *interop.Context, v *vm.VM) error { return nil } -// bcGetHeader returns block header. -func bcGetHeader(ic *interop.Context, v *vm.VM) error { - hash, err := getBlockHashFromElement(ic.Chain, v.Estack().Pop()) - if err != nil { - return err - } - header, err := ic.Chain.GetHeader(hash) - if err != nil { - v.Estack().PushVal([]byte{}) - } else { - v.Estack().PushVal(stackitem.NewInterop(header)) - } - return nil -} - // bcGetHeight returns blockchain height. func bcGetHeight(ic *interop.Context, v *vm.VM) error { v.Estack().PushVal(ic.Chain.BlockHeight()) diff --git a/pkg/core/interops.go b/pkg/core/interops.go index 889742b3a..be271a10e 100644 --- a/pkg/core/interops.go +++ b/pkg/core/interops.go @@ -64,7 +64,6 @@ func getInteropFromSlice(ic *interop.Context, slice []interop.Function) func(uin var systemInterops = []interop.Function{ {Name: "System.Blockchain.GetBlock", Func: bcGetBlock, Price: 250}, {Name: "System.Blockchain.GetContract", Func: bcGetContract, Price: 100}, - {Name: "System.Blockchain.GetHeader", Func: bcGetHeader, Price: 100}, {Name: "System.Blockchain.GetHeight", Func: bcGetHeight, Price: 1}, {Name: "System.Blockchain.GetTransaction", Func: bcGetTransaction, Price: 100}, {Name: "System.Blockchain.GetTransactionFromBlock", Func: bcGetTransactionFromBlock, Price: 100}, @@ -77,10 +76,6 @@ var systemInterops = []interop.Function{ {Name: "System.ExecutionEngine.GetEntryScriptHash", Func: engineGetEntryScriptHash, Price: 1}, {Name: "System.ExecutionEngine.GetExecutingScriptHash", Func: engineGetExecutingScriptHash, Price: 1}, {Name: "System.ExecutionEngine.GetScriptContainer", Func: engineGetScriptContainer, Price: 1}, - {Name: "System.Header.GetHash", Func: headerGetHash, Price: 1}, - {Name: "System.Header.GetIndex", Func: headerGetIndex, Price: 1}, - {Name: "System.Header.GetPrevHash", Func: headerGetPrevHash, Price: 1}, - {Name: "System.Header.GetTimestamp", Func: headerGetTimestamp, Price: 1}, {Name: "System.Runtime.CheckWitness", Func: runtime.CheckWitness, Price: 200}, {Name: "System.Runtime.Deserialize", Func: runtimeDeserialize, Price: 1}, {Name: "System.Runtime.GetTime", Func: runtimeGetTime, Price: 1}, @@ -99,12 +94,7 @@ var systemInterops = []interop.Function{ } var neoInterops = []interop.Function{ - {Name: "Neo.Account.GetBalance", Func: accountGetBalance, Price: 1}, - {Name: "Neo.Account.GetScriptHash", Func: accountGetScriptHash, Price: 1}, - {Name: "Neo.Account.IsStandard", Func: accountIsStandard, Price: 100}, - {Name: "Neo.Blockchain.GetAccount", Func: bcGetAccount, Price: 100}, {Name: "Neo.Blockchain.GetContract", Func: bcGetContract, Price: 100}, - {Name: "Neo.Blockchain.GetHeader", Func: bcGetHeader, Price: 100}, {Name: "Neo.Blockchain.GetHeight", Func: bcGetHeight, Price: 1}, {Name: "Neo.Contract.Create", Func: contractCreate, Price: 0}, {Name: "Neo.Contract.Destroy", Func: contractDestroy, Price: 1}, @@ -119,13 +109,6 @@ var neoInterops = []interop.Function{ {Name: "Neo.Enumerator.Create", Func: enumerator.Create, Price: 1}, {Name: "Neo.Enumerator.Next", Func: enumerator.Next, Price: 1}, {Name: "Neo.Enumerator.Value", Func: enumerator.Value, Price: 1}, - {Name: "Neo.Header.GetHash", Func: headerGetHash, Price: 1}, - {Name: "Neo.Header.GetIndex", Func: headerGetIndex, Price: 1}, - {Name: "Neo.Header.GetMerkleRoot", Func: headerGetMerkleRoot, Price: 1}, - {Name: "Neo.Header.GetNextConsensus", Func: headerGetNextConsensus, Price: 1}, - {Name: "Neo.Header.GetPrevHash", Func: headerGetPrevHash, Price: 1}, - {Name: "Neo.Header.GetTimestamp", Func: headerGetTimestamp, Price: 1}, - {Name: "Neo.Header.GetVersion", Func: headerGetVersion, Price: 1}, {Name: "Neo.Iterator.Concat", Func: iterator.Concat, Price: 1}, {Name: "Neo.Iterator.Create", Func: iterator.Create, Price: 1}, {Name: "Neo.Iterator.Key", Func: iterator.Key, Price: 1}, @@ -146,7 +129,6 @@ var neoInterops = []interop.Function{ {Name: "Neo.Storage.GetReadOnlyContext", Func: storageGetReadOnlyContext, Price: 1}, {Name: "Neo.Storage.Put", Func: storagePut, Price: 0}, {Name: "Neo.StorageContext.AsReadOnly", Func: storageContextAsReadOnly, Price: 1}, - {Name: "Neo.Witness.GetVerificationScript", Func: witnessGetVerificationScript, Price: 100}, // Aliases. {Name: "Neo.Iterator.Next", Func: enumerator.Next, Price: 1}, diff --git a/pkg/core/interops_test.go b/pkg/core/interops_test.go index 40d4db5ae..b346926e2 100644 --- a/pkg/core/interops_test.go +++ b/pkg/core/interops_test.go @@ -32,25 +32,15 @@ func TestUnexpectedNonInterops(t *testing.T) { // All of these functions expect an interop item on the stack. funcs := []func(*interop.Context, *vm.VM) error{ - accountGetBalance, - accountGetScriptHash, contractGetScript, contractGetStorageContext, contractIsPayable, - headerGetHash, - headerGetIndex, - headerGetMerkleRoot, - headerGetNextConsensus, - headerGetPrevHash, - headerGetTimestamp, - headerGetVersion, storageContextAsReadOnly, storageDelete, storageFind, storageGet, storagePut, storagePutEx, - witnessGetVerificationScript, } for _, f := range funcs { for k, v := range vals { diff --git a/pkg/interop/account/account.go b/pkg/interop/account/account.go deleted file mode 100644 index f0595eec0..000000000 --- a/pkg/interop/account/account.go +++ /dev/null @@ -1,43 +0,0 @@ -/* -Package account provides getter functions for Account interop structure. -To use these functions you need to get an Account first via blockchain.GetAccount -call. -*/ -package account - -// Account represents NEO account type that is used in interop functions, it's -// an opaque data structure that you can get data from only using functions from -// this package. It's similar in function to the Account class in the Neo .net -// framework. -type Account struct{} - -// GetScriptHash returns the script hash of the given Account (20 bytes in BE -// representation). It uses `Neo.Account.GetBalance` syscall internally. -func GetScriptHash(a Account) []byte { - return nil -} - -// GetVotes returns current votes of the given account represented as a slice of -// public keys. Keys are serialized into byte slices in their compressed form (33 -// bytes long each). This function uses `Neo.Account.GetVotes` syscall -// internally. -func GetVotes(a Account) [][]byte { - return nil -} - -// GetBalance returns current balance of the given asset (by its ID, 256 bit -// hash in BE form) for the given account. Only native UTXO assets can be -// queiried via this function, for NEP-5 ones use respective contract calls. -// The value returned is represented as an integer with original value multiplied -// by 10⁸ so you can work with fractional parts of the balance too. This function -// uses `Neo.Account.GetBalance` syscall internally. -func GetBalance(a Account, assetID []byte) int { - return 0 -} - -// IsStandard checks whether given account uses standard (CHECKSIG or -// CHECKMULTISIG) contract. It only works for deployed contracts and uses -// `Neo.Account.IsStandard` syscall internally. -func IsStandard(a Account) bool { - return false -} diff --git a/pkg/interop/blockchain/blockchain.go b/pkg/interop/blockchain/blockchain.go index 5afb272a5..417cd9d76 100644 --- a/pkg/interop/blockchain/blockchain.go +++ b/pkg/interop/blockchain/blockchain.go @@ -4,9 +4,7 @@ Package blockchain provides functions to access various blockchain data. package blockchain import ( - "github.com/nspcc-dev/neo-go/pkg/interop/account" "github.com/nspcc-dev/neo-go/pkg/interop/contract" - "github.com/nspcc-dev/neo-go/pkg/interop/header" ) // Transaction represents a NEO transaction. It's similar to Transaction class @@ -63,19 +61,11 @@ type Block struct { // Note that when transaction is being run as a part of new block this block is // considered as not yet accepted (persisted) and thus you'll get an index of // the previous (already accepted) block. This function uses -// `Neo.Blockchain.GetHeight` syscall. +// `System.Blockchain.GetHeight` syscall. func GetHeight() int { return 0 } -// GetHeader returns header found by the given hash (256 bit hash in BE format -// represented as a slice of 32 bytes) or index (integer). Refer to the `header` -// package for possible uses of returned structure. This function uses -// `Neo.Blockchain.GetHeader` syscall. -func GetHeader(heightOrHash interface{}) header.Header { - return header.Header{} -} - // GetBlock returns block found by the given hash or index (with the same // encoding as for GetHeader). This function uses `System.Blockchain.GetBlock` // syscall. @@ -108,22 +98,7 @@ func GetTransactionHeight(hash []byte) int { // GetContract returns contract found by the given script hash (160 bit in BE // format represented as a slice of 20 bytes). Refer to the `contract` package // for details on how to use the returned structure. This function uses -// `Neo.Blockchain.GetContract` syscall. +// `System.Blockchain.GetContract` syscall. func GetContract(scriptHash []byte) contract.Contract { return contract.Contract{} } - -// GetAccount returns account found by the given script hash (160 bit in BE -// format represented as a slice of 20 bytes). Refer to the `account` package -// for details on how to use the returned structure. This function uses -// `Neo.Blockchain.GetAccount` syscall. -func GetAccount(scriptHash []byte) account.Account { - return account.Account{} -} - -// GetValidators returns a slice of current validators public keys represented -// as a compressed serialized byte slice (33 bytes long). This function uses -// `Neo.Blockchain.GetValidators` syscall. -func GetValidators() [][]byte { - return nil -} diff --git a/pkg/interop/header/header.go b/pkg/interop/header/header.go deleted file mode 100644 index 37abe9676..000000000 --- a/pkg/interop/header/header.go +++ /dev/null @@ -1,61 +0,0 @@ -/* -Package header contains functions working with block headers. -*/ -package header - -// Header represents Neo block header type, it's an opaque data structure that -// can be used by functions from this package. You can create it with -// blockchain.GetHeader. In its function it's similar to the Header class -// of the Neo .net framework. -type Header struct{} - -// GetIndex returns the index (height) of the given header. It uses -// `Neo.Header.GetIndex` syscall. -func GetIndex(h Header) int { - return 0 -} - -// GetHash returns the hash (256-bit BE value packed into 32 byte slice) of the -// given header (which also is a hash of the block). It uses `Neo.Header.GetHash` -// syscall. -func GetHash(h Header) []byte { - return nil -} - -// GetPrevHash returns the hash (256-bit BE value packed into 32 byte slice) of -// the previous block stored in the given header. It uses `Neo.Header.GetPrevHash` -// syscall. -func GetPrevHash(h Header) []byte { - return nil -} - -// GetTimestamp returns the timestamp of the given header. It uses -// `Neo.Header.GetTimestamp` syscall. -func GetTimestamp(h Header) int { - return 0 -} - -// GetVersion returns the version of the given header. It uses -// `Neo.Header.GetVersion` syscall. -func GetVersion(h Header) int { - return 0 -} - -// GetMerkleRoot returns the Merkle root (256-bit BE value packed into 32 byte -// slice) of the given header. It uses `Neo.Header.GetMerkleRoot` syscall. -func GetMerkleRoot(h Header) []byte { - return nil -} - -// GetConsensusData returns the consensus data (nonce) of the given header. -// It uses `Neo.Header.GetConsensusData` syscall. -func GetConsensusData(h Header) int { - return 0 -} - -// GetNextConsensus returns the next consensus field (verification script hash, -// 160-bit BE value packed into 20 byte slice) of the given header. It uses -// `Neo.Header.GetNextConsensus` syscall. -func GetNextConsensus(h Header) []byte { - return nil -} diff --git a/pkg/interop/witness/witness.go b/pkg/interop/witness/witness.go deleted file mode 100644 index 5bf742f83..000000000 --- a/pkg/interop/witness/witness.go +++ /dev/null @@ -1,14 +0,0 @@ -/* -Package witness provides functions dealing with transaction's witnesses. -*/ -package witness - -// Witness is an opaque data structure that can only be created by -// transaction.GetWitnesses and representing transaction's witness. -type Witness struct{} - -// GetVerificationScript returns verification script stored in the given -// witness. It uses `Neo.Witness.GetVerificationScript` syscall. -func GetVerificationScript(w Witness) []byte { - return nil -} From 97c6ac7a73085125f763a0df2195b0dc08a7fd00 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 10 Jun 2020 12:12:31 +0300 Subject: [PATCH 2/4] core: move Neo.Blockchain.* syscalls to System.* --- pkg/compiler/syscall.go | 4 ++-- pkg/core/interops.go | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/compiler/syscall.go b/pkg/compiler/syscall.go index b8f597736..5f46ca9af 100644 --- a/pkg/compiler/syscall.go +++ b/pkg/compiler/syscall.go @@ -30,8 +30,8 @@ var syscalls = map[string]map[string]string{ }, "blockchain": { "GetBlock": "System.Blockchain.GetBlock", - "GetContract": "Neo.Blockchain.GetContract", - "GetHeight": "Neo.Blockchain.GetHeight", + "GetContract": "System.Blockchain.GetContract", + "GetHeight": "System.Blockchain.GetHeight", "GetTransaction": "System.Blockchain.GetTransaction", "GetTransactionFromBlock": "System.Blockchain.GetTransactionFromBlock", "GetTransactionHeight": "System.Blockchain.GetTransactionHeight", diff --git a/pkg/core/interops.go b/pkg/core/interops.go index be271a10e..b20758e0c 100644 --- a/pkg/core/interops.go +++ b/pkg/core/interops.go @@ -94,8 +94,6 @@ var systemInterops = []interop.Function{ } var neoInterops = []interop.Function{ - {Name: "Neo.Blockchain.GetContract", Func: bcGetContract, Price: 100}, - {Name: "Neo.Blockchain.GetHeight", Func: bcGetHeight, Price: 1}, {Name: "Neo.Contract.Create", Func: contractCreate, Price: 0}, {Name: "Neo.Contract.Destroy", Func: contractDestroy, Price: 1}, {Name: "Neo.Contract.GetScript", Func: contractGetScript, Price: 1}, From 0472a0b0b1f1119396c2f3c95053d7ee7d6c175f Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 10 Jun 2020 11:49:39 +0300 Subject: [PATCH 3/4] core: move Neo.Runtime/Enumerator/Iterator.* interops to System.* --- pkg/compiler/codegen.go | 10 ++--- pkg/compiler/panic_test.go | 2 +- pkg/compiler/syscall.go | 36 +++++++-------- pkg/compiler/vm_test.go | 2 +- pkg/core/blockchain_test.go | 6 +-- pkg/core/interops.go | 29 ++++-------- pkg/interop/enumerator/enumerator.go | 8 ++-- pkg/interop/iterator/iterator.go | 14 +++--- pkg/interop/runtime/runtime.go | 14 +++--- pkg/rpc/server/server_test.go | 8 ++-- pkg/rpc/server/testdata/test_contract.avm | Bin 727 -> 727 bytes pkg/rpc/server/testdata/testblocks.acc | Bin 6516 -> 6516 bytes pkg/vm/emit/emit_test.go | 6 +-- pkg/vm/interop.go | 52 ++++++++++------------ pkg/vm/vm_test.go | 32 ++++++------- 15 files changed, 102 insertions(+), 117 deletions(-) diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index 39b005081..9055abd16 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -898,23 +898,23 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor { c.currentSwitch = label ast.Walk(c, n.X) - emit.Syscall(c.prog.BinWriter, "Neo.Iterator.Create") + emit.Syscall(c.prog.BinWriter, "System.Iterator.Create") c.pushStackLabel(label, 1) c.setLabel(start) emit.Opcode(c.prog.BinWriter, opcode.DUP) - emit.Syscall(c.prog.BinWriter, "Neo.Enumerator.Next") + emit.Syscall(c.prog.BinWriter, "System.Enumerator.Next") emit.Jmp(c.prog.BinWriter, opcode.JMPIFNOTL, end) if n.Key != nil { emit.Opcode(c.prog.BinWriter, opcode.DUP) - emit.Syscall(c.prog.BinWriter, "Neo.Iterator.Key") + emit.Syscall(c.prog.BinWriter, "System.Iterator.Key") c.emitStoreVar(n.Key.(*ast.Ident).Name) } if n.Value != nil { emit.Opcode(c.prog.BinWriter, opcode.DUP) - emit.Syscall(c.prog.BinWriter, "Neo.Enumerator.Value") + emit.Syscall(c.prog.BinWriter, "System.Enumerator.Value") c.emitStoreVar(n.Value.(*ast.Ident).Name) } @@ -1092,7 +1092,7 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) { emit.Opcode(c.prog.BinWriter, opcode.THROW) } else if isString(c.typeInfo.Types[arg].Type) { ast.Walk(c, arg) - emit.Syscall(c.prog.BinWriter, "Neo.Runtime.Log") + emit.Syscall(c.prog.BinWriter, "System.Runtime.Log") emit.Opcode(c.prog.BinWriter, opcode.THROW) } else { c.prog.Err = errors.New("panic should have string or nil argument") diff --git a/pkg/compiler/panic_test.go b/pkg/compiler/panic_test.go index e8e506db4..0661f75c0 100644 --- a/pkg/compiler/panic_test.go +++ b/pkg/compiler/panic_test.go @@ -55,7 +55,7 @@ func getPanicSource(need bool, message string) string { } func logGetter(logs *[]string) vm.InteropGetterFunc { - logID := emit.InteropNameToID([]byte("Neo.Runtime.Log")) + logID := emit.InteropNameToID([]byte("System.Runtime.Log")) return func(id uint32) *vm.InteropFuncPrice { if id != logID { return nil diff --git a/pkg/compiler/syscall.go b/pkg/compiler/syscall.go index 5f46ca9af..8109fffa2 100644 --- a/pkg/compiler/syscall.go +++ b/pkg/compiler/syscall.go @@ -5,10 +5,10 @@ var syscalls = map[string]map[string]string{ "ECDsaVerify": "Neo.Crypto.ECDsaVerify", }, "enumerator": { - "Concat": "Neo.Enumerator.Concat", - "Create": "Neo.Enumerator.Create", - "Next": "Neo.Enumerator.Next", - "Value": "Neo.Enumerator.Value", + "Concat": "System.Enumerator.Concat", + "Create": "System.Enumerator.Create", + "Next": "System.Enumerator.Next", + "Value": "System.Enumerator.Value", }, "storage": { "ConvertContextToReadOnly": "Neo.StorageContext.AsReadOnly", @@ -20,13 +20,13 @@ var syscalls = map[string]map[string]string{ "Put": "Neo.Storage.Put", }, "runtime": { - "GetTrigger": "Neo.Runtime.GetTrigger", - "CheckWitness": "Neo.Runtime.CheckWitness", - "Notify": "Neo.Runtime.Notify", - "Log": "Neo.Runtime.Log", - "GetTime": "Neo.Runtime.GetTime", - "Serialize": "Neo.Runtime.Serialize", - "Deserialize": "Neo.Runtime.Deserialize", + "GetTrigger": "System.Runtime.GetTrigger", + "CheckWitness": "System.Runtime.CheckWitness", + "Notify": "System.Runtime.Notify", + "Log": "System.Runtime.Log", + "GetTime": "System.Runtime.GetTime", + "Serialize": "System.Runtime.Serialize", + "Deserialize": "System.Runtime.Deserialize", }, "blockchain": { "GetBlock": "System.Blockchain.GetBlock", @@ -51,12 +51,12 @@ var syscalls = map[string]map[string]string{ "GetExecutingScriptHash": "System.ExecutionEngine.GetExecutingScriptHash", }, "iterator": { - "Concat": "Neo.Iterator.Concat", - "Create": "Neo.Iterator.Create", - "Key": "Neo.Iterator.Key", - "Keys": "Neo.Iterator.Keys", - "Next": "Neo.Iterator.Next", - "Value": "Neo.Iterator.Value", - "Values": "Neo.Iterator.Values", + "Concat": "System.Iterator.Concat", + "Create": "System.Iterator.Create", + "Key": "System.Iterator.Key", + "Keys": "System.Iterator.Keys", + "Next": "System.Enumerator.Next", + "Value": "System.Enumerator.Value", + "Values": "System.Iterator.Values", }, } diff --git a/pkg/compiler/vm_test.go b/pkg/compiler/vm_test.go index f841318d2..9f8f7142a 100644 --- a/pkg/compiler/vm_test.go +++ b/pkg/compiler/vm_test.go @@ -85,7 +85,7 @@ func newStoragePlugin() *storagePlugin { s.interops[emit.InteropNameToID([]byte("Neo.Storage.Get"))] = s.Get s.interops[emit.InteropNameToID([]byte("Neo.Storage.Put"))] = s.Put s.interops[emit.InteropNameToID([]byte("Neo.Storage.GetContext"))] = s.GetContext - s.interops[emit.InteropNameToID([]byte("Neo.Runtime.Notify"))] = s.Notify + s.interops[emit.InteropNameToID([]byte("System.Runtime.Notify"))] = s.Notify return s } diff --git a/pkg/core/blockchain_test.go b/pkg/core/blockchain_test.go index 1b50e88d9..e01dde741 100644 --- a/pkg/core/blockchain_test.go +++ b/pkg/core/blockchain_test.go @@ -265,7 +265,7 @@ func TestSubscriptions(t *testing.T) { script := io.NewBufBinWriter() emit.Bytes(script.BinWriter, []byte("yay!")) - emit.Syscall(script.BinWriter, "Neo.Runtime.Notify") + emit.Syscall(script.BinWriter, "System.Runtime.Notify") require.NoError(t, script.Err) txGood1 := transaction.New(script.Bytes(), 0) txGood1.Sender = neoOwner @@ -276,7 +276,7 @@ func TestSubscriptions(t *testing.T) { // Reset() reuses the script buffer and we need to keep scripts. script = io.NewBufBinWriter() emit.Bytes(script.BinWriter, []byte("nay!")) - emit.Syscall(script.BinWriter, "Neo.Runtime.Notify") + emit.Syscall(script.BinWriter, "System.Runtime.Notify") emit.Opcode(script.BinWriter, opcode.THROW) require.NoError(t, script.Err) txBad := transaction.New(script.Bytes(), 0) @@ -287,7 +287,7 @@ func TestSubscriptions(t *testing.T) { script = io.NewBufBinWriter() emit.Bytes(script.BinWriter, []byte("yay! yay! yay!")) - emit.Syscall(script.BinWriter, "Neo.Runtime.Notify") + emit.Syscall(script.BinWriter, "System.Runtime.Notify") require.NoError(t, script.Err) txGood2 := transaction.New(script.Bytes(), 0) txGood2.Sender = neoOwner diff --git a/pkg/core/interops.go b/pkg/core/interops.go index b20758e0c..d96072b52 100644 --- a/pkg/core/interops.go +++ b/pkg/core/interops.go @@ -72,10 +72,19 @@ var systemInterops = []interop.Function{ {Name: "System.Contract.CallEx", Func: contractCallEx, Price: 1}, {Name: "System.Contract.Destroy", Func: contractDestroy, Price: 1}, {Name: "System.Contract.GetStorageContext", Func: contractGetStorageContext, Price: 1}, + {Name: "System.Enumerator.Concat", Func: enumerator.Concat, Price: 1}, + {Name: "System.Enumerator.Create", Func: enumerator.Create, Price: 1}, + {Name: "System.Enumerator.Next", Func: enumerator.Next, Price: 1}, + {Name: "System.Enumerator.Value", Func: enumerator.Value, Price: 1}, {Name: "System.ExecutionEngine.GetCallingScriptHash", Func: engineGetCallingScriptHash, Price: 1}, {Name: "System.ExecutionEngine.GetEntryScriptHash", Func: engineGetEntryScriptHash, Price: 1}, {Name: "System.ExecutionEngine.GetExecutingScriptHash", Func: engineGetExecutingScriptHash, Price: 1}, {Name: "System.ExecutionEngine.GetScriptContainer", Func: engineGetScriptContainer, Price: 1}, + {Name: "System.Iterator.Concat", Func: iterator.Concat, Price: 1}, + {Name: "System.Iterator.Create", Func: iterator.Create, Price: 1}, + {Name: "System.Iterator.Key", Func: iterator.Key, Price: 1}, + {Name: "System.Iterator.Keys", Func: iterator.Keys, Price: 1}, + {Name: "System.Iterator.Values", Func: iterator.Values, Price: 1}, {Name: "System.Runtime.CheckWitness", Func: runtime.CheckWitness, Price: 200}, {Name: "System.Runtime.Deserialize", Func: runtimeDeserialize, Price: 1}, {Name: "System.Runtime.GetTime", Func: runtimeGetTime, Price: 1}, @@ -103,23 +112,7 @@ var neoInterops = []interop.Function{ {Name: "Neo.Crypto.ECDsaVerify", Func: crypto.ECDSAVerify, Price: 1}, {Name: "Neo.Crypto.ECDsaCheckMultiSig", Func: crypto.ECDSACheckMultisig, Price: 1}, {Name: "Neo.Crypto.SHA256", Func: crypto.Sha256, Price: 1}, - {Name: "Neo.Enumerator.Concat", Func: enumerator.Concat, Price: 1}, - {Name: "Neo.Enumerator.Create", Func: enumerator.Create, Price: 1}, - {Name: "Neo.Enumerator.Next", Func: enumerator.Next, Price: 1}, - {Name: "Neo.Enumerator.Value", Func: enumerator.Value, Price: 1}, - {Name: "Neo.Iterator.Concat", Func: iterator.Concat, Price: 1}, - {Name: "Neo.Iterator.Create", Func: iterator.Create, Price: 1}, - {Name: "Neo.Iterator.Key", Func: iterator.Key, Price: 1}, - {Name: "Neo.Iterator.Keys", Func: iterator.Keys, Price: 1}, - {Name: "Neo.Iterator.Values", Func: iterator.Values, Price: 1}, {Name: "Neo.Native.Deploy", Func: native.Deploy, Price: 1}, - {Name: "Neo.Runtime.CheckWitness", Func: runtime.CheckWitness, Price: 200}, - {Name: "Neo.Runtime.Deserialize", Func: runtimeDeserialize, Price: 1}, - {Name: "Neo.Runtime.GetTime", Func: runtimeGetTime, Price: 1}, - {Name: "Neo.Runtime.GetTrigger", Func: runtimeGetTrigger, Price: 1}, - {Name: "Neo.Runtime.Log", Func: runtimeLog, Price: 1}, - {Name: "Neo.Runtime.Notify", Func: runtimeNotify, Price: 1}, - {Name: "Neo.Runtime.Serialize", Func: runtimeSerialize, Price: 1}, {Name: "Neo.Storage.Delete", Func: storageDelete, Price: 100}, {Name: "Neo.Storage.Find", Func: storageFind, Price: 1}, {Name: "Neo.Storage.Get", Func: storageGet, Price: 100}, @@ -127,10 +120,6 @@ var neoInterops = []interop.Function{ {Name: "Neo.Storage.GetReadOnlyContext", Func: storageGetReadOnlyContext, Price: 1}, {Name: "Neo.Storage.Put", Func: storagePut, Price: 0}, {Name: "Neo.StorageContext.AsReadOnly", Func: storageContextAsReadOnly, Price: 1}, - - // Aliases. - {Name: "Neo.Iterator.Next", Func: enumerator.Next, Price: 1}, - {Name: "Neo.Iterator.Value", Func: enumerator.Value, Price: 1}, } // initIDinInteropsSlice initializes IDs from names in one given diff --git a/pkg/interop/enumerator/enumerator.go b/pkg/interop/enumerator/enumerator.go index a47bff76f..ca52f4dcc 100644 --- a/pkg/interop/enumerator/enumerator.go +++ b/pkg/interop/enumerator/enumerator.go @@ -11,7 +11,7 @@ type Enumerator struct{} // Create creates a new enumerator from the given items (slice or structure). // New enumerator points at index -1 of its items, so the user of it has to -// advance it first with Next. This function uses `Neo.Enumerator.Create` +// advance it first with Next. This function uses `System.Enumerator.Create` // syscall. func Create(items []interface{}) Enumerator { return Enumerator{} @@ -20,13 +20,13 @@ func Create(items []interface{}) Enumerator { // Next moves position of the given enumerator by one and returns a bool that // tells whether there is a new value present in this new position. If it is, // you can use Value to get it, if not then there are no more values in this -// enumerator. This function uses `Neo.Enumerator.Next` syscall. +// enumerator. This function uses `System.Enumerator.Next` syscall. func Next(e Enumerator) bool { return true } // Value returns current enumerator's item value, it's only valid to call it -// after Next returning true. This function uses `Neo.Enumerator.Value` syscall. +// after Next returning true. This function uses `System.Enumerator.Value` syscall. func Value(e Enumerator) interface{} { return nil } @@ -35,7 +35,7 @@ func Value(e Enumerator) interface{} { // a first and then continue with b. Enumerator positions are not reset for a // and b, so if any of them was already advanced by Next the resulting // Enumerator will point at this new position and never go back to previous -// values. This function uses `Neo.Enumerator.Concat` syscall. +// values. This function uses `System.Enumerator.Concat` syscall. func Concat(a, b Enumerator) Enumerator { return Enumerator{} } diff --git a/pkg/interop/iterator/iterator.go b/pkg/interop/iterator/iterator.go index ec407ee0a..9e295f11e 100644 --- a/pkg/interop/iterator/iterator.go +++ b/pkg/interop/iterator/iterator.go @@ -13,7 +13,7 @@ type Iterator struct{} // Create creates an iterator from the given items (array, struct or map). A new // iterator is set to point at element -1, so to access its first element you -// need to call Next first. This function uses `Neo.Iterator.Create` syscall. +// need to call Next first. This function uses `System.Iterator.Create` syscall. func Create(items []interface{}) Iterator { return Iterator{} } @@ -24,13 +24,13 @@ func Create(items []interface{}) Iterator { // Iterator will point at this new position and never go back to previous // key-value pairs. Concatenated iterators also remain completely independent // in results they return, so if both contain the same key you'll receive this -// key twice when iterating. This function uses `Neo.Iterator.Concat` syscall. +// key twice when iterating. This function uses `System.Iterator.Concat` syscall. func Concat(a, b Iterator) Iterator { return Iterator{} } // Key returns iterator's key at current position. It's only valid to call after -// successful Next call. This function uses `Neo.Iterator.Key` syscall. +// successful Next call. This function uses `System.Iterator.Key` syscall. func Key(it Iterator) interface{} { return nil } @@ -38,20 +38,20 @@ func Key(it Iterator) interface{} { // Keys returns Enumerator ranging over keys or the given Iterator. Note that // this Enumerator is actually directly tied to the underlying Iterator, so that // advancing it with Next will actually advance the Iterator too. This function -// uses `Neo.Iterator.Keys` syscall. +// uses `System.Iterator.Keys` syscall. func Keys(it Iterator) enumerator.Enumerator { return enumerator.Enumerator{} } // Next advances the iterator returning true if it is was successful (and you // can use Key or Value) and false otherwise (and there are no more elements in -// this Iterator). This function uses `Neo.Iterator.Next` syscall. +// this Iterator). This function uses `System.Enumerator.Next` syscall. func Next(it Iterator) bool { return true } // Value returns iterator's current value. It's only valid to call after -// successful Next call. This function uses `Neo.Iterator.Value` syscall. +// successful Next call. This function uses `System.Enumerator.Value` syscall. func Value(it Iterator) interface{} { return nil } @@ -59,7 +59,7 @@ func Value(it Iterator) interface{} { // Values returns Enumerator ranging over values or the given Iterator. Note that // this Enumerator is actually directly tied to the underlying Iterator, so that // advancing it with Next will actually advance the Iterator too. This function -// uses `Neo.Iterator.Values` syscall. +// uses `System.Iterator.Values` syscall. func Values(it Iterator) enumerator.Enumerator { return enumerator.Enumerator{} } diff --git a/pkg/interop/runtime/runtime.go b/pkg/interop/runtime/runtime.go index 9b7e837d3..ec7c52a8b 100644 --- a/pkg/interop/runtime/runtime.go +++ b/pkg/interop/runtime/runtime.go @@ -6,14 +6,14 @@ package runtime // CheckWitness verifies if the given script hash (160-bit BE value in a 20 byte // slice) or key (compressed serialized 33-byte form) is one of the signers of -// this invocation. It uses `Neo.Runtime.CheckWitness` syscall. +// this invocation. It uses `System.Runtime.CheckWitness` syscall. func CheckWitness(hashOrKey []byte) bool { return true } // Log instructs VM to log the given message. It's mostly used for debugging // purposes as these messages are not saved anywhere normally and usually are -// only visible in the VM logs. This function uses `Neo.Runtime.Log` syscall. +// only visible in the VM logs. This function uses `System.Runtime.Log` syscall. func Log(message string) {} // Notify sends a notification (collecting all arguments in an array) to the @@ -21,14 +21,14 @@ func Log(message string) {} // notification is saved in application log. It's intended to be used as a // part of contract's API to external systems, these events can be monitored // from outside and act upon accordingly. This function uses -// `Neo.Runtime.Notify` syscall. +// `System.Runtime.Notify` syscall. func Notify(arg ...interface{}) {} // GetTime returns the timestamp of the most recent block. Note that when running // script in test mode this would be the last accepted (persisted) block in the // chain, but when running as a part of the new block the time returned is the // time of this (currently being processed) block. This function uses -// `Neo.Runtime.GetTime` syscall. +// `System.Runtime.GetTime` syscall. func GetTime() int { return 0 } @@ -38,7 +38,7 @@ func GetTime() int { // as a part of verification process from running it as a regular application. // Some interop functions (especially ones that change the state in any way) are // not available when running with verification trigger. This function uses -// `Neo.Runtime.GetTrigger` syscall. +// `System.Runtime.GetTrigger` syscall. func GetTrigger() byte { return 0x00 } @@ -58,13 +58,13 @@ func Verification() byte { // Serialize serializes any given item into a byte slice. It works for all // regular VM types (not ones from interop package) and allows to save them in // storage or pass into Notify and then Deserialize them on the next run or in -// the external event receiver. It uses `Neo.Runtime.Serialize` syscall. +// the external event receiver. It uses `System.Runtime.Serialize` syscall. func Serialize(item interface{}) []byte { return nil } // Deserialize unpacks previously serialized value from a byte slice, it's the -// opposite of Serialize. It uses `Neo.Runtime.Deserialize` syscall. +// opposite of Serialize. It uses `System.Runtime.Deserialize` syscall. func Deserialize(b []byte) interface{} { return nil } diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 69af43432..4d30c07d2 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -49,18 +49,18 @@ type rpcTestCase struct { check func(t *testing.T, e *executor, result interface{}) } -const testContractHash = "1b4357bff5a01bdf2a6581247cf9ed1e24629176" +const testContractHash = "1b061f2295cdf0f4350e12746b8492a364fdd121" var rpcTestCases = map[string][]rpcTestCase{ "getapplicationlog": { { name: "positive", - params: `["5878052c7e9843786d64a9aeab16e74fabffd5abad9a0404aaf4f4bf2b6213e9"]`, + params: `["88da760745bd6cf2c58c7ad1cf206e4cc251c664e65b668fa0df474e68ee5ed3"]`, result: func(e *executor) interface{} { return &result.ApplicationLog{} }, check: func(t *testing.T, e *executor, acc interface{}) { res, ok := acc.(*result.ApplicationLog) require.True(t, ok) - expectedTxHash, err := util.Uint256DecodeStringLE("5878052c7e9843786d64a9aeab16e74fabffd5abad9a0404aaf4f4bf2b6213e9") + expectedTxHash, err := util.Uint256DecodeStringLE("88da760745bd6cf2c58c7ad1cf206e4cc251c664e65b668fa0df474e68ee5ed3") require.NoError(t, err) assert.Equal(t, expectedTxHash, res.TxHash) assert.Equal(t, 1, len(res.Executions)) @@ -484,7 +484,7 @@ var rpcTestCases = map[string][]rpcTestCase{ "gettransactionheight": { { name: "positive", - params: `["5878052c7e9843786d64a9aeab16e74fabffd5abad9a0404aaf4f4bf2b6213e9"]`, + params: `["88da760745bd6cf2c58c7ad1cf206e4cc251c664e65b668fa0df474e68ee5ed3"]`, result: func(e *executor) interface{} { h := 0 return &h diff --git a/pkg/rpc/server/testdata/test_contract.avm b/pkg/rpc/server/testdata/test_contract.avm index 36266c55e1a0b25ebf604acefc076db73f77f3da..3f23cef22206a5399e438774f107307efdc56fbd 100755 GIT binary patch delta 85 zcmcc4dYyHG6w6e`{KScJH(1U;cb_)#mm-)yS)S1kEHJr{Q6Ius!l({moM$wKFxZ%U OAd177LLiKFOqu|}y&&xX delta 85 zcmcc4dYyHG6bmc+B(aHdH(1Or2eD23r3mIvmS^+>3rsF#)Q2#ZFsefs=NXM53^pbo Oh~hA&5C~%(lO_O3CKxLK diff --git a/pkg/rpc/server/testdata/testblocks.acc b/pkg/rpc/server/testdata/testbl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tUh~wKtfhAx<71_LUJi&Rv^xpXL2nphyb{!W0?R>)2YSCJ`Ph?NnkVaPBneqn$aS*g4Lu8JJ+ z3u4M}GV4>?>t9Ck%~n6H-%%F|Tl%7a>v=_IE@;XAXp-+ru|P*vu<>a0p6iV11isF4 zk;nw`VAZ$S0x1#%oq;#TX4T?@g*+932G|!)00>bCxl*}RIbU^S`u=O}wZ(qWl#7;& z%Jg+M*lMSrjn&HJE|pXHQ}R64>U}d0*KW9dptB#1NJL~*@6t1rAOntj)t4{I>Az8` z3@B)36^Q&;$^_?Q-o;VbbjG`#0`i=Y+BMm6U%O+F&%PSwrZSm$f3D{j(l)xZGohNS T8Kjg%!{y0gqt5>Mi{$?SL6^Lf diff --git a/pkg/vm/emit/emit_test.go b/pkg/vm/emit/emit_test.go index bb0024fb9..67fec612d 100644 --- a/pkg/vm/emit/emit_test.go +++ b/pkg/vm/emit/emit_test.go @@ -189,9 +189,9 @@ func TestEmitString(t *testing.T) { func TestEmitSyscall(t *testing.T) { syscalls := []string{ - "Neo.Runtime.Log", - "Neo.Runtime.Notify", - "Neo.Runtime.Whatever", + "System.Runtime.Log", + "System.Runtime.Notify", + "System.Runtime.Whatever", } buf := io.NewBufBinWriter() diff --git a/pkg/vm/interop.go b/pkg/vm/interop.go index 8003d6a76..4024a09f4 100644 --- a/pkg/vm/interop.go +++ b/pkg/vm/interop.go @@ -29,35 +29,31 @@ type interopIDFuncPrice struct { type InteropGetterFunc func(uint32) *InteropFuncPrice var defaultVMInterops = []interopIDFuncPrice{ - {emit.InteropNameToID([]byte("Neo.Runtime.Log")), + {emit.InteropNameToID([]byte("System.Runtime.Log")), InteropFuncPrice{runtimeLog, 1}}, - {emit.InteropNameToID([]byte("Neo.Runtime.Notify")), + {emit.InteropNameToID([]byte("System.Runtime.Notify")), InteropFuncPrice{runtimeNotify, 1}}, - {emit.InteropNameToID([]byte("Neo.Runtime.Serialize")), - InteropFuncPrice{RuntimeSerialize, 1}}, {emit.InteropNameToID([]byte("System.Runtime.Serialize")), InteropFuncPrice{RuntimeSerialize, 1}}, - {emit.InteropNameToID([]byte("Neo.Runtime.Deserialize")), - InteropFuncPrice{RuntimeDeserialize, 1}}, {emit.InteropNameToID([]byte("System.Runtime.Deserialize")), InteropFuncPrice{RuntimeDeserialize, 1}}, - {emit.InteropNameToID([]byte("Neo.Enumerator.Create")), + {emit.InteropNameToID([]byte("System.Enumerator.Create")), InteropFuncPrice{EnumeratorCreate, 1}}, - {emit.InteropNameToID([]byte("Neo.Enumerator.Next")), + {emit.InteropNameToID([]byte("System.Enumerator.Next")), InteropFuncPrice{EnumeratorNext, 1}}, - {emit.InteropNameToID([]byte("Neo.Enumerator.Concat")), + {emit.InteropNameToID([]byte("System.Enumerator.Concat")), InteropFuncPrice{EnumeratorConcat, 1}}, - {emit.InteropNameToID([]byte("Neo.Enumerator.Value")), + {emit.InteropNameToID([]byte("System.Enumerator.Value")), InteropFuncPrice{EnumeratorValue, 1}}, - {emit.InteropNameToID([]byte("Neo.Iterator.Create")), + {emit.InteropNameToID([]byte("System.Iterator.Create")), InteropFuncPrice{IteratorCreate, 1}}, - {emit.InteropNameToID([]byte("Neo.Iterator.Concat")), + {emit.InteropNameToID([]byte("System.Iterator.Concat")), InteropFuncPrice{IteratorConcat, 1}}, - {emit.InteropNameToID([]byte("Neo.Iterator.Key")), + {emit.InteropNameToID([]byte("System.Iterator.Key")), InteropFuncPrice{IteratorKey, 1}}, - {emit.InteropNameToID([]byte("Neo.Iterator.Keys")), + {emit.InteropNameToID([]byte("System.Iterator.Keys")), InteropFuncPrice{IteratorKeys, 1}}, - {emit.InteropNameToID([]byte("Neo.Iterator.Values")), + {emit.InteropNameToID([]byte("System.Iterator.Values")), InteropFuncPrice{IteratorValues, 1}}, } @@ -71,21 +67,21 @@ func getDefaultVMInterop(id uint32) *InteropFuncPrice { return nil } -// runtimeLog handles the syscall "Neo.Runtime.Log" for printing and logging stuff. +// runtimeLog handles the syscall "System.Runtime.Log" for printing and logging stuff. func runtimeLog(vm *VM) error { item := vm.Estack().Pop() fmt.Printf("NEO-GO-VM (log) > %s\n", item.Value()) return nil } -// runtimeNotify handles the syscall "Neo.Runtime.Notify" for printing and logging stuff. +// runtimeNotify handles the syscall "System.Runtime.Notify" for printing and logging stuff. func runtimeNotify(vm *VM) error { item := vm.Estack().Pop() fmt.Printf("NEO-GO-VM (notify) > %s\n", item.Value()) return nil } -// RuntimeSerialize handles syscalls System.Runtime.Serialize and Neo.Runtime.Serialize. +// RuntimeSerialize handles syscalls System.Runtime.Serialize and System.Runtime.Serialize. func RuntimeSerialize(vm *VM) error { item := vm.Estack().Pop() data, err := stackitem.SerializeItem(item.value) @@ -100,7 +96,7 @@ func RuntimeSerialize(vm *VM) error { return nil } -// RuntimeDeserialize handles syscalls System.Runtime.Deserialize and Neo.Runtime.Deserialize. +// RuntimeDeserialize handles syscalls System.Runtime.Deserialize and System.Runtime.Deserialize. func RuntimeDeserialize(vm *VM) error { data := vm.Estack().Pop().Bytes() @@ -121,7 +117,7 @@ func init() { }) } -// EnumeratorCreate handles syscall Neo.Enumerator.Create. +// EnumeratorCreate handles syscall System.Enumerator.Create. func EnumeratorCreate(v *VM) error { data := v.Estack().Pop().Array() v.Estack().Push(&Element{ @@ -134,7 +130,7 @@ func EnumeratorCreate(v *VM) error { return nil } -// EnumeratorNext handles syscall Neo.Enumerator.Next. +// EnumeratorNext handles syscall System.Enumerator.Next. func EnumeratorNext(v *VM) error { iop := v.Estack().Pop().Interop() arr := iop.Value().(enumerator) @@ -143,7 +139,7 @@ func EnumeratorNext(v *VM) error { return nil } -// EnumeratorValue handles syscall Neo.Enumerator.Value. +// EnumeratorValue handles syscall System.Enumerator.Value. func EnumeratorValue(v *VM) error { iop := v.Estack().Pop().Interop() arr := iop.Value().(enumerator) @@ -152,7 +148,7 @@ func EnumeratorValue(v *VM) error { return nil } -// EnumeratorConcat handles syscall Neo.Enumerator.Concat. +// EnumeratorConcat handles syscall System.Enumerator.Concat. func EnumeratorConcat(v *VM) error { iop1 := v.Estack().Pop().Interop() arr1 := iop1.Value().(enumerator) @@ -169,7 +165,7 @@ func EnumeratorConcat(v *VM) error { return nil } -// IteratorCreate handles syscall Neo.Iterator.Create. +// IteratorCreate handles syscall System.Iterator.Create. func IteratorCreate(v *VM) error { data := v.Estack().Pop() var item stackitem.Item @@ -197,7 +193,7 @@ func NewMapIterator(m *stackitem.Map) *stackitem.Interop { }) } -// IteratorConcat handles syscall Neo.Iterator.Concat. +// IteratorConcat handles syscall System.Iterator.Concat. func IteratorConcat(v *VM) error { iop1 := v.Estack().Pop().Interop() iter1 := iop1.Value().(iterator) @@ -214,7 +210,7 @@ func IteratorConcat(v *VM) error { return nil } -// IteratorKey handles syscall Neo.Iterator.Key. +// IteratorKey handles syscall System.Iterator.Key. func IteratorKey(v *VM) error { iop := v.estack.Pop().Interop() iter := iop.Value().(iterator) @@ -223,7 +219,7 @@ func IteratorKey(v *VM) error { return nil } -// IteratorKeys handles syscall Neo.Iterator.Keys. +// IteratorKeys handles syscall System.Iterator.Keys. func IteratorKeys(v *VM) error { iop := v.estack.Pop().Interop() iter := iop.Value().(iterator) @@ -234,7 +230,7 @@ func IteratorKeys(v *VM) error { return nil } -// IteratorValues handles syscall Neo.Iterator.Values. +// IteratorValues handles syscall System.Iterator.Values. func IteratorValues(v *VM) error { iop := v.estack.Pop().Interop() iter := iop.Value().(iterator) diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index bf7d75702..746df0494 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -488,16 +488,16 @@ func getEnumeratorProg(n int, isIter bool) (prog []byte) { prog = []byte{byte(opcode.INITSSLOT), 1, byte(opcode.STSFLD0)} for i := 0; i < n; i++ { prog = append(prog, byte(opcode.LDSFLD0)) - prog = append(prog, getSyscallProg("Neo.Enumerator.Next")...) + prog = append(prog, getSyscallProg("System.Enumerator.Next")...) prog = append(prog, byte(opcode.LDSFLD0)) - prog = append(prog, getSyscallProg("Neo.Enumerator.Value")...) + prog = append(prog, getSyscallProg("System.Enumerator.Value")...) if isIter { prog = append(prog, byte(opcode.LDSFLD0)) - prog = append(prog, getSyscallProg("Neo.Iterator.Key")...) + prog = append(prog, getSyscallProg("System.Iterator.Key")...) } } prog = append(prog, byte(opcode.LDSFLD0)) - prog = append(prog, getSyscallProg("Neo.Enumerator.Next")...) + prog = append(prog, getSyscallProg("System.Enumerator.Next")...) return } @@ -512,7 +512,7 @@ func checkEnumeratorStack(t *testing.T, vm *VM, arr []stackitem.Item) { func testIterableCreate(t *testing.T, typ string) { isIter := typ == "Iterator" - prog := getSyscallProg("Neo." + typ + ".Create") + prog := getSyscallProg("System." + typ + ".Create") prog = append(prog, getEnumeratorProg(2, isIter)...) vm := load(prog) @@ -546,10 +546,10 @@ func TestIteratorCreate(t *testing.T) { func testIterableConcat(t *testing.T, typ string) { isIter := typ == "Iterator" - prog := getSyscallProg("Neo." + typ + ".Create") + prog := getSyscallProg("System." + typ + ".Create") prog = append(prog, byte(opcode.SWAP)) - prog = append(prog, getSyscallProg("Neo."+typ+".Create")...) - prog = append(prog, getSyscallProg("Neo."+typ+".Concat")...) + prog = append(prog, getSyscallProg("System."+typ+".Create")...) + prog = append(prog, getSyscallProg("System."+typ+".Concat")...) prog = append(prog, getEnumeratorProg(3, isIter)...) vm := load(prog) @@ -589,8 +589,8 @@ func TestIteratorConcat(t *testing.T) { } func TestIteratorKeys(t *testing.T) { - prog := getSyscallProg("Neo.Iterator.Create") - prog = append(prog, getSyscallProg("Neo.Iterator.Keys")...) + prog := getSyscallProg("System.Iterator.Create") + prog = append(prog, getSyscallProg("System.Iterator.Keys")...) prog = append(prog, getEnumeratorProg(2, false)...) v := load(prog) @@ -609,8 +609,8 @@ func TestIteratorKeys(t *testing.T) { } func TestIteratorValues(t *testing.T) { - prog := getSyscallProg("Neo.Iterator.Create") - prog = append(prog, getSyscallProg("Neo.Iterator.Values")...) + prog := getSyscallProg("System.Iterator.Create") + prog = append(prog, getSyscallProg("System.Iterator.Values")...) prog = append(prog, getEnumeratorProg(2, false)...) v := load(prog) @@ -643,8 +643,8 @@ func getSyscallProg(name string) (prog []byte) { } func getSerializeProg() (prog []byte) { - prog = append(prog, getSyscallProg("Neo.Runtime.Serialize")...) - prog = append(prog, getSyscallProg("Neo.Runtime.Deserialize")...) + prog = append(prog, getSyscallProg("System.Runtime.Serialize")...) + prog = append(prog, getSyscallProg("System.Runtime.Deserialize")...) prog = append(prog, byte(opcode.RET)) return @@ -749,7 +749,7 @@ func TestSerializeStruct(t *testing.T) { } func TestDeserializeUnknown(t *testing.T) { - prog := append(getSyscallProg("Neo.Runtime.Deserialize"), byte(opcode.RET)) + prog := append(getSyscallProg("System.Runtime.Deserialize"), byte(opcode.RET)) data, err := stackitem.SerializeItem(stackitem.NewBigInteger(big.NewInt(123))) require.NoError(t, err) @@ -785,7 +785,7 @@ func TestSerializeMapCompat(t *testing.T) { emit.Bytes(buf.BinWriter, []byte("key")) emit.Bytes(buf.BinWriter, []byte("value")) emit.Opcode(buf.BinWriter, opcode.SETITEM) - emit.Syscall(buf.BinWriter, "Neo.Runtime.Serialize") + emit.Syscall(buf.BinWriter, "System.Runtime.Serialize") require.NoError(t, buf.Err) vm := load(buf.Bytes()) From 38d020d1a279692f48fbc1847207bbfee528d52f Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 10 Jun 2020 11:55:56 +0300 Subject: [PATCH 4/4] core: move Neo.Storage.* interops to System.* --- pkg/compiler/syscall.go | 14 +++++++------- pkg/compiler/vm_test.go | 6 +++--- pkg/core/interops.go | 10 ++-------- pkg/interop/storage/storage.go | 14 +++++++------- pkg/rpc/server/server_test.go | 8 ++++---- pkg/rpc/server/testdata/test_contract.avm | Bin 727 -> 727 bytes pkg/rpc/server/testdata/testblocks.acc | Bin 6516 -> 6516 bytes 7 files changed, 23 insertions(+), 29 deletions(-) diff --git a/pkg/compiler/syscall.go b/pkg/compiler/syscall.go index 8109fffa2..f4fad18b5 100644 --- a/pkg/compiler/syscall.go +++ b/pkg/compiler/syscall.go @@ -11,13 +11,13 @@ var syscalls = map[string]map[string]string{ "Value": "System.Enumerator.Value", }, "storage": { - "ConvertContextToReadOnly": "Neo.StorageContext.AsReadOnly", - "Delete": "Neo.Storage.Delete", - "Find": "Neo.Storage.Find", - "Get": "Neo.Storage.Get", - "GetContext": "Neo.Storage.GetContext", - "GetReadOnlyContext": "Neo.Storage.GetReadOnlyContext", - "Put": "Neo.Storage.Put", + "ConvertContextToReadOnly": "System.Storage.AsReadOnly", + "Delete": "System.Storage.Delete", + "Find": "System.Storage.Find", + "Get": "System.Storage.Get", + "GetContext": "System.Storage.GetContext", + "GetReadOnlyContext": "System.Storage.GetReadOnlyContext", + "Put": "System.Storage.Put", }, "runtime": { "GetTrigger": "System.Runtime.GetTrigger", diff --git a/pkg/compiler/vm_test.go b/pkg/compiler/vm_test.go index 9f8f7142a..fab6b6eac 100644 --- a/pkg/compiler/vm_test.go +++ b/pkg/compiler/vm_test.go @@ -82,9 +82,9 @@ func newStoragePlugin() *storagePlugin { mem: make(map[string][]byte), interops: make(map[uint32]vm.InteropFunc), } - s.interops[emit.InteropNameToID([]byte("Neo.Storage.Get"))] = s.Get - s.interops[emit.InteropNameToID([]byte("Neo.Storage.Put"))] = s.Put - s.interops[emit.InteropNameToID([]byte("Neo.Storage.GetContext"))] = s.GetContext + s.interops[emit.InteropNameToID([]byte("System.Storage.Get"))] = s.Get + s.interops[emit.InteropNameToID([]byte("System.Storage.Put"))] = s.Put + s.interops[emit.InteropNameToID([]byte("System.Storage.GetContext"))] = s.GetContext s.interops[emit.InteropNameToID([]byte("System.Runtime.Notify"))] = s.Notify return s diff --git a/pkg/core/interops.go b/pkg/core/interops.go index d96072b52..c73f48105 100644 --- a/pkg/core/interops.go +++ b/pkg/core/interops.go @@ -94,12 +94,13 @@ var systemInterops = []interop.Function{ {Name: "System.Runtime.Platform", Func: runtimePlatform, Price: 1}, {Name: "System.Runtime.Serialize", Func: runtimeSerialize, Price: 1}, {Name: "System.Storage.Delete", Func: storageDelete, Price: 100}, + {Name: "System.Storage.Find", Func: storageFind, Price: 1}, {Name: "System.Storage.Get", Func: storageGet, Price: 100}, {Name: "System.Storage.GetContext", Func: storageGetContext, Price: 1}, {Name: "System.Storage.GetReadOnlyContext", Func: storageGetReadOnlyContext, Price: 1}, {Name: "System.Storage.Put", Func: storagePut, Price: 0}, // These don't have static price in C# code. {Name: "System.Storage.PutEx", Func: storagePutEx, Price: 0}, - {Name: "System.StorageContext.AsReadOnly", Func: storageContextAsReadOnly, Price: 1}, + {Name: "System.Storage.AsReadOnly", Func: storageContextAsReadOnly, Price: 1}, } var neoInterops = []interop.Function{ @@ -113,13 +114,6 @@ var neoInterops = []interop.Function{ {Name: "Neo.Crypto.ECDsaCheckMultiSig", Func: crypto.ECDSACheckMultisig, Price: 1}, {Name: "Neo.Crypto.SHA256", Func: crypto.Sha256, Price: 1}, {Name: "Neo.Native.Deploy", Func: native.Deploy, Price: 1}, - {Name: "Neo.Storage.Delete", Func: storageDelete, Price: 100}, - {Name: "Neo.Storage.Find", Func: storageFind, Price: 1}, - {Name: "Neo.Storage.Get", Func: storageGet, Price: 100}, - {Name: "Neo.Storage.GetContext", Func: storageGetContext, Price: 1}, - {Name: "Neo.Storage.GetReadOnlyContext", Func: storageGetReadOnlyContext, Price: 1}, - {Name: "Neo.Storage.Put", Func: storagePut, Price: 0}, - {Name: "Neo.StorageContext.AsReadOnly", Func: storageContextAsReadOnly, Price: 1}, } // initIDinInteropsSlice initializes IDs from names in one given diff --git a/pkg/interop/storage/storage.go b/pkg/interop/storage/storage.go index a047eebb1..748157ef6 100644 --- a/pkg/interop/storage/storage.go +++ b/pkg/interop/storage/storage.go @@ -17,38 +17,38 @@ type Context struct{} // ConvertContextToReadOnly returns new context from the given one, but with // writing capability turned off, so that you could only invoke Get and Find // using this new Context. If Context is already read-only this function is a -// no-op. It uses `Neo.StorageContext.AsReadOnly` syscall. +// no-op. It uses `System.Storage.AsReadOnly` syscall. func ConvertContextToReadOnly(ctx Context) Context { return Context{} } // GetContext returns current contract's (that invokes this function) storage -// context. It uses `Neo.Storage.GetContext` syscall. +// context. It uses `System.Storage.GetContext` syscall. func GetContext() Context { return Context{} } // GetReadOnlyContext returns current contract's (that invokes this function) // storage context in read-only mode, you can use this context for Get and Find // functions, but using it for Put and Delete will fail. It uses -// `Neo.Storage.GetReadOnlyContext` syscall. +// `System.Storage.GetReadOnlyContext` syscall. func GetReadOnlyContext() Context { return Context{} } // Put saves given value with given key in the storage using given Context. // Even though it accepts interface{} for both, you can only pass simple types // there like string, []byte, int or bool (not structures or slices of more // complex types). To put more complex types there serialize them first using -// runtime.Serialize. This function uses `Neo.Storage.Put` syscall. +// runtime.Serialize. This function uses `System.Storage.Put` syscall. func Put(ctx Context, key interface{}, value interface{}) {} // Get retrieves value stored for the given key using given Context. See Put // documentation on possible key and value types. This function uses -// `Neo.Storage.Get` syscall. +// `System.Storage.Get` syscall. func Get(ctx Context, key interface{}) interface{} { return 0 } // Delete removes key-value pair from storage by the given key using given // Context. See Put documentation on possible key types. This function uses -// `Neo.Storage.Delete` syscall. +// `System.Storage.Delete` syscall. func Delete(ctx Context, key interface{}) {} // Find returns an iterator.Iterator over key-value pairs in the given Context // that match the given key (contain it as a prefix). See Put documentation on // possible key types and iterator package documentation on how to use the -// returned value. This function uses `Neo.Storage.Find` syscall. +// returned value. This function uses `System.Storage.Find` syscall. func Find(ctx Context, key interface{}) iterator.Iterator { return iterator.Iterator{} } diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 4d30c07d2..c10180304 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -49,18 +49,18 @@ type rpcTestCase struct { check func(t *testing.T, e *executor, result interface{}) } -const testContractHash = "1b061f2295cdf0f4350e12746b8492a364fdd121" +const testContractHash = "279c86355b30d452386c1717e2ffa01c9dac31f3" var rpcTestCases = map[string][]rpcTestCase{ "getapplicationlog": { { name: "positive", - params: `["88da760745bd6cf2c58c7ad1cf206e4cc251c664e65b668fa0df474e68ee5ed3"]`, + params: `["328190e78f1b5b8dcf86e71ec1894d6144f4e4cdb25abc20ea02b618851941dd"]`, result: func(e *executor) interface{} { return &result.ApplicationLog{} }, check: func(t *testing.T, e *executor, acc interface{}) { res, ok := acc.(*result.ApplicationLog) require.True(t, ok) - expectedTxHash, err := util.Uint256DecodeStringLE("88da760745bd6cf2c58c7ad1cf206e4cc251c664e65b668fa0df474e68ee5ed3") + expectedTxHash, err := util.Uint256DecodeStringLE("328190e78f1b5b8dcf86e71ec1894d6144f4e4cdb25abc20ea02b618851941dd") require.NoError(t, err) assert.Equal(t, expectedTxHash, res.TxHash) assert.Equal(t, 1, len(res.Executions)) @@ -484,7 +484,7 @@ var rpcTestCases = map[string][]rpcTestCase{ "gettransactionheight": { { name: "positive", - params: `["88da760745bd6cf2c58c7ad1cf206e4cc251c664e65b668fa0df474e68ee5ed3"]`, + params: `["328190e78f1b5b8dcf86e71ec1894d6144f4e4cdb25abc20ea02b618851941dd"]`, result: func(e *executor) interface{} { h := 0 return &h diff --git a/pkg/rpc/server/testdata/test_contract.avm b/pkg/rpc/server/testdata/test_contract.avm index 3f23cef22206a5399e438774f107307efdc56fbd..459d4e2218a10e24888c309d04009ca6d91f4c67 100755 GIT binary patch delta 158 zcmcc4dYyHGzVPgC>E{%SvML46RSKR9c6??p(K6AghXo`&@sbhCq}UgRlQ|eozygyU z7-vC5?lIaZgOn=f<#Pl$f)pv1bLVsCbIvR01`6eKLrj`%%VeYiwxOIyAk?w_@TC;R ma$Y6}Cw_)j1-h4i&!pTe)Jm;UgPqR{HWnf@%bpQaQ(>d+{ delta 158 zcmcc4dYyHGzHp1gHD1M{tV)4%m4fGj9fKA+ex2yl!vYeXc*%%GUay*cG6$mxSYWaP z<1C2CJw_X4kW$6Ge2xG|kRru$?tJci&UxkBK%snYh)I)enT%AxHk9)SggUk#zLcU^ l&dcQB#LrO9m(P>Wo6iSTIGM?U$Lw+to0T#v0|SGr0|0S*F_i!S diff --git a/pkg/rpc/server/testdata/testblocks.acc b/pkg/rpc/server/testdata/testblocks.acc index 7e7709a288c0990ab53a619d6dfe83d49efea137..bb02750f547480a62d4c1832ad2c833b447d67e3 100644 GIT binary patch delta 2665 zcmaJ?cRbX69Jf1nKh7B$5h5dG?{$*S$d=ieA$wCsSE0)ucQQ{p#3TDcN>(A{L{=Ks z$z6oUxR7|F=g;T$eE)pEKA-pN`+B{{XG>vAA@eeQLu+uBxd^H~a8lp0hII95%&#U4 z=0?z#^&#z!oRj>SURCZ--FG6~-vLeLmShz-+7vDU3j!C-27V|l2?3%wGrpC@Z)^c@ zono`4oNs*??jF)QpPwjyc`m&!xTxO%G2-I~8BkCDXt}iIC_sFLwWL?l4t9I2)Vyjm zfukGpP#z(-p?>h<0J#651O1{}P6D9&Nn5^X@`;R+r13~zx!X;gM!~8BaYftQNrz(f zE$cy9ovFXjdryyp3To-NK!)0cL75$u?iv7xc62xS22zqXcK8CP75IF#uIIN|-n(ZE zdivJ!LQW>TTX!MIRb8X7uGEmQ!d&W4PZuU@m7ihq~o5Lv>tf2Gu;i#%x~BMg-a zvkVM|?U+iNE}zp?=@$)R3)vGBpXK(hq4F4Yo1!5$0i1>ayk63@a#;Od?hM3xY&xk0 z+1F>#MJj zx?|q{8d)j*M)T*1gGXF(p!&c#5_7z=5oUy~1XBa5#9e|aG71pqEATR1$JxyPxf=pWhY z!Kag3PV`{8QZOT(^fS0+I9sza6Mn4>tPs*VZ(^z1k5keWl_InTW4Ztl6qRRdX^z_II%`r{pf`lPGt6pq!0*4u zn15zUFu@_QZhG`ShxVFRhe6GG&EU?mLHD6+X|=i)0O9q=R94-0^Z>l&jCheR3ki0R zL68jgNMB6a4vu#aU?D^*ULk_f#T0Gyt8IqC3x(Se=_M7FH@OAJ_v7x@balipR59(M zr0w(pIOz4t0&G3|_o~YjS-p-ux+wi6CikNNfBtOEZHAh~GDvZ>W+?P=6Ppc6)3Nl` zi}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