diff --git a/cli/testdata/chain50x2.acc b/cli/testdata/chain50x2.acc index 8466c30b5..21277914f 100644 Binary files a/cli/testdata/chain50x2.acc and b/cli/testdata/chain50x2.acc differ diff --git a/pkg/core/blockchain_test.go b/pkg/core/blockchain_test.go index d8b892ffb..b2d50d93d 100644 --- a/pkg/core/blockchain_test.go +++ b/pkg/core/blockchain_test.go @@ -20,6 +20,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames" "github.com/nspcc-dev/neo-go/pkg/core/mempool" "github.com/nspcc-dev/neo-go/pkg/core/native" + "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" "github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/core/transaction" @@ -555,7 +556,12 @@ func TestVerifyTx(t *testing.T) { }) tx.Scripts = append(tx.Scripts, transaction.Witness{}) t.Run("NonZeroVerification", func(t *testing.T) { - tx.Scripts[len(tx.Scripts)-1].VerificationScript = bc.contracts.Oracle.Script + script, _ := state.CreateNativeContractHash(nativenames.Oracle) + w := io.NewBufBinWriter() + emit.Opcodes(w.BinWriter, opcode.ABORT) + emit.Bytes(w.BinWriter, util.Uint160{}.BytesBE()) + emit.Bytes(w.BinWriter, script) + tx.Scripts[len(tx.Scripts)-1].VerificationScript = w.Bytes() err := bc.VerifyTx(tx) require.True(t, errors.Is(err, ErrNativeContractWitness), "got: %v", err) }) diff --git a/pkg/core/interop/context.go b/pkg/core/interop/context.go index a489dbf69..4322491b7 100644 --- a/pkg/core/interop/context.go +++ b/pkg/core/interop/context.go @@ -8,18 +8,14 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/blockchainer" "github.com/nspcc-dev/neo-go/pkg/core/dao" - "github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames" "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/crypto" - "github.com/nspcc-dev/neo-go/pkg/crypto/hash" - "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "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/emit" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "go.uber.org/zap" ) @@ -114,12 +110,7 @@ func NewContractMD(name string) *ContractMD { Methods: make(map[string]MethodAndPrice), } - w := io.NewBufBinWriter() - emit.String(w.BinWriter, c.Name) - emit.Syscall(w.BinWriter, interopnames.SystemContractCallNative) - - c.Script = w.Bytes() - c.Hash = hash.Hash160(c.Script) + c.Script, c.Hash = state.CreateNativeContractHash(c.Name) c.Manifest = *manifest.DefaultManifest(name) return c diff --git a/pkg/core/native/oracle.go b/pkg/core/native/oracle.go index 49b23ada7..6ad40eeef 100644 --- a/pkg/core/native/oracle.go +++ b/pkg/core/native/oracle.go @@ -48,19 +48,11 @@ const ( oracleRequestPrice = 5000_0000 ) -var ( - oracleInvokeScript []byte - oracleScript []byte -) +var oracleScript []byte func init() { + _, h := state.CreateNativeContractHash(nativenames.Oracle) w := io.NewBufBinWriter() - emit.String(w.BinWriter, nativenames.Oracle) - emit.Syscall(w.BinWriter, interopnames.SystemContractCallNative) - oracleInvokeScript = w.Bytes() - h := hash.Hash160(oracleInvokeScript) - - w = io.NewBufBinWriter() emit.Int(w.BinWriter, 0) emit.Opcodes(w.BinWriter, opcode.NEWARRAY) emit.String(w.BinWriter, "finish") @@ -84,13 +76,6 @@ var ( ErrResponseNotFound = errors.New("oracle response not found") ) -// GetOracleInvokeScript returns oracle contract script. -func GetOracleInvokeScript() []byte { - b := make([]byte, len(oracleInvokeScript)) - copy(b, oracleInvokeScript) - return b -} - // GetOracleResponseScript returns script for transaction with oracle response. func GetOracleResponseScript() []byte { b := make([]byte, len(oracleScript)) diff --git a/pkg/core/state/contract.go b/pkg/core/state/contract.go index 743713fce..34a399c26 100644 --- a/pkg/core/state/contract.go +++ b/pkg/core/state/contract.go @@ -6,6 +6,7 @@ import ( "math" "math/big" + "github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" @@ -114,3 +115,15 @@ func CreateContractHash(sender util.Uint160, script []byte) util.Uint160 { } return hash.Hash160(w.Bytes()) } + +// CreateNativeContractHash returns script and hash for the native contract. +func CreateNativeContractHash(name string) ([]byte, util.Uint160) { + w := io.NewBufBinWriter() + emit.String(w.BinWriter, name) + emit.Syscall(w.BinWriter, interopnames.SystemContractCallNative) + if w.Err != nil { + panic(w.Err) + } + script := w.Bytes() + return script, CreateContractHash(util.Uint160{}, script) +} diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 9c8c0d518..830680ee6 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -57,7 +57,7 @@ type rpcTestCase struct { } const testContractHash = "743ed26f78e29ecd595535b74a943b1f9ccbc444" -const deploymentTxHash = "63605d1ba55b829b7816f2a2016e34b87296dcc824d069b2ee0aef1c1f5898dd" +const deploymentTxHash = "faa8d607f4000dbb3fc41dda51110369888b8b65c40de85d36ae9e4879dc4982" const genesisBlockHash = "0542f4350c6e236d0509bcd98188b0034bfbecc1a0c7fcdb8e4295310d468b70" const verifyContractHash = "a2eb22340979804cb10cc1add0b8822c201f4d8a" diff --git a/pkg/rpc/server/testdata/testblocks.acc b/pkg/rpc/server/testdata/testblocks.acc index 958cf88b5..31e4f10a1 100644 Binary files a/pkg/rpc/server/testdata/testblocks.acc and b/pkg/rpc/server/testdata/testblocks.acc differ