From 7fb40e104a705863ad1f25a3426279db2e6b10d8 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Fri, 15 Jan 2021 11:00:39 +0300 Subject: [PATCH 1/4] io: allow to restrict string size --- pkg/io/binaryReader.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/io/binaryReader.go b/pkg/io/binaryReader.go index b8c935c80..6915f5109 100644 --- a/pkg/io/binaryReader.go +++ b/pkg/io/binaryReader.go @@ -193,7 +193,7 @@ func (r *BinReader) ReadBytes(buf []byte) { } // ReadString calls ReadVarBytes and casts the results as a string. -func (r *BinReader) ReadString() string { - b := r.ReadVarBytes() +func (r *BinReader) ReadString(maxSize ...int) string { + b := r.ReadVarBytes(maxSize...) return string(b) } From 52843fc1bf5a8227481c1e0e960a521dc054d8ab Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Mon, 18 Jan 2021 17:05:11 +0300 Subject: [PATCH 2/4] nef: add Tokens field --- cli/testdata/verify.manifest.json | 2 +- cli/testdata/verify.nef | Bin 82 -> 83 bytes pkg/core/state/contract_test.go | 1 + pkg/rpc/client/rpc_test.go | 6 +-- pkg/rpc/server/server_test.go | 4 +- pkg/rpc/server/testdata/testblocks.acc | Bin 7665 -> 7667 bytes pkg/smartcontract/nef/method_token.go | 57 +++++++++++++++++++++ pkg/smartcontract/nef/method_token_test.go | 50 ++++++++++++++++++ pkg/smartcontract/nef/nef.go | 13 +++-- pkg/smartcontract/nef/nef_test.go | 41 +++++++++++++++ 10 files changed, 164 insertions(+), 10 deletions(-) create mode 100644 pkg/smartcontract/nef/method_token.go create mode 100644 pkg/smartcontract/nef/method_token_test.go diff --git a/cli/testdata/verify.manifest.json b/cli/testdata/verify.manifest.json index 518bcd896..627b44167 100755 --- a/cli/testdata/verify.manifest.json +++ b/cli/testdata/verify.manifest.json @@ -1 +1 @@ -{"name":"verify","abi":{"hash":"0xbf214a7551e50d6fbe0bef05271719325d9fc1ef","methods":[{"name":"verify","offset":0,"parameters":[],"returntype":"Boolean"},{"name":"onPayment","offset":5,"parameters":[{"name":"from","type":"ByteArray"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void"}],"events":[]},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"safemethods":[],"extra":null} \ No newline at end of file +{"name":"verify","abi":{"methods":[{"name":"onPayment","offset":5,"parameters":[{"name":"from","type":"ByteArray"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"verify","offset":0,"parameters":[],"returntype":"Boolean","safe":false}],"events":[{"name":"Hello world!","parameters":[{"name":"args","type":"Array"}]}]},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null} \ No newline at end of file diff --git a/cli/testdata/verify.nef b/cli/testdata/verify.nef index 5bb3c8bbe40518db36efb14d911e84b0a574ee9e..3de780aee21a23f0914246ef4aa0425972083f83 100755 GIT binary patch delta 49 wcmWFvo}jK{tY@HGP?V}`Vy>H>Vw`AUV32IY00*4mj0}Pf;S9_UI+A5Y01lf8SO5S3 delta 48 ycmWFznxL+2q-UU8lx(PLXl$vQZenhbYG`U{!~g}H;fxG|4&e;U4l|PW%?1GbxC$8n diff --git a/pkg/core/state/contract_test.go b/pkg/core/state/contract_test.go index 9ea4c627a..634cca9a4 100644 --- a/pkg/core/state/contract_test.go +++ b/pkg/core/state/contract_test.go @@ -44,6 +44,7 @@ func TestEncodeDecodeContractState(t *testing.T) { Compiler: "neo-go.test", Version: "test", }, + Tokens: []nef.MethodToken{}, Script: script, Checksum: 0, }, diff --git a/pkg/rpc/client/rpc_test.go b/pkg/rpc/client/rpc_test.go index aa2b4bca4..087ead720 100644 --- a/pkg/rpc/client/rpc_test.go +++ b/pkg/rpc/client/rpc_test.go @@ -330,7 +330,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ } return c.GetContractStateByHash(hash) }, - serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go","version":"3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":749050685},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"permissions":null,"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, + serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go","version":"3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":2354924458},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"permissions":null,"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, result: func(c *Client) interface{} { script, err := base64.StdEncoding.DecodeString("VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==") if err != nil { @@ -351,7 +351,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ invoke: func(c *Client) (interface{}, error) { return c.GetContractStateByAddressOrName("NWiu5oejTu925aeL9Hc1LX8SvaJhE23h15") }, - serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go","version":"3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":749050685},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"permissions":null,"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, + serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go","version":"3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":2354924458},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"permissions":null,"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, result: func(c *Client) interface{} { script, err := base64.StdEncoding.DecodeString("VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==") if err != nil { @@ -372,7 +372,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ invoke: func(c *Client) (interface{}, error) { return c.GetContractStateByID(0) }, - serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go","version":"3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":749050685},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"permissions":null,"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, + serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go","version":"3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":2354924458},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"permissions":null,"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, result: func(c *Client) interface{} { script, err := base64.StdEncoding.DecodeString("VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==") if err != nil { diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 41fc7282a..99c8dc3e5 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -57,7 +57,7 @@ type rpcTestCase struct { } const testContractHash = "0b3bc97e94ed99e32dda46c9ecd2d3626979af06" -const deploymentTxHash = "4288bb6ad12426a9e34f6af4c050bc291798a46958443d614f457a9a12f087c2" +const deploymentTxHash = "fe9e91388ba9be39f771fddaf07d3719c490eb179788a3d193f248c7ed4cff61" const genesisBlockHash = "0542f4350c6e236d0509bcd98188b0034bfbecc1a0c7fcdb8e4295310d468b70" const verifyContractHash = "d2da8ee8c0bf6c5bf3dda1ef671dbf5fef7226e9" @@ -1408,7 +1408,7 @@ func checkNep17Balances(t *testing.T, e *executor, acc interface{}) { }, { Asset: e.chain.UtilityTokenHash(), - Amount: "80006675650", + Amount: "80006673650", LastUpdated: 7, }}, Address: testchain.PrivateKeyByID(0).GetScriptHash().StringLE(), diff --git a/pkg/rpc/server/testdata/testblocks.acc b/pkg/rpc/server/testdata/testblocks.acc index f98ff66b7d996af67ccb71c84765cfe80f251b46..501ed5fe66f009c369ec4f6978e82c6d45cc45fd 100644 GIT binary patch delta 2088 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 diff --git a/pkg/smartcontract/nef/method_token.go b/pkg/smartcontract/nef/method_token.go new file mode 100644 index 000000000..48aeacd89 --- /dev/null +++ b/pkg/smartcontract/nef/method_token.go @@ -0,0 +1,57 @@ +package nef + +import ( + "errors" + "strings" + + "github.com/nspcc-dev/neo-go/pkg/io" + "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" + "github.com/nspcc-dev/neo-go/pkg/util" +) + +// maxMethodLength is the maximum length of method. +const maxMethodLength = 32 + +var ( + errInvalidMethodName = errors.New("method name should't start with '_'") + errInvalidCallFlag = errors.New("invalid call flag") +) + +// MethodToken is contract method description. +type MethodToken struct { + // Hash is contract hash. + Hash util.Uint160 `json:"hash"` + // Method is method name. + Method string `json:"method"` + // ParamCount is method parameter count. + ParamCount uint16 `json:"paramcount"` + // HasReturn is true if method returns value. + HasReturn bool `json:"hasreturnvalue"` + // CallFlag is a set of call flags the method will be called with. + CallFlag callflag.CallFlag `json:"callflags"` +} + +// EncodeBinary implements io.Serializable. +func (t *MethodToken) EncodeBinary(w *io.BinWriter) { + w.WriteBytes(t.Hash[:]) + w.WriteString(t.Method) + w.WriteU16LE(t.ParamCount) + w.WriteBool(t.HasReturn) + w.WriteB(byte(t.CallFlag)) +} + +// DecodeBinary implements io.Serializable. +func (t *MethodToken) DecodeBinary(r *io.BinReader) { + r.ReadBytes(t.Hash[:]) + t.Method = r.ReadString(maxMethodLength) + if r.Err == nil && strings.HasPrefix(t.Method, "_") { + r.Err = errInvalidMethodName + return + } + t.ParamCount = r.ReadU16LE() + t.HasReturn = r.ReadBool() + t.CallFlag = callflag.CallFlag(r.ReadB()) + if r.Err == nil && t.CallFlag&^callflag.All != 0 { + r.Err = errInvalidCallFlag + } +} diff --git a/pkg/smartcontract/nef/method_token_test.go b/pkg/smartcontract/nef/method_token_test.go new file mode 100644 index 000000000..05072723d --- /dev/null +++ b/pkg/smartcontract/nef/method_token_test.go @@ -0,0 +1,50 @@ +package nef + +import ( + "errors" + "strings" + "testing" + + "github.com/nspcc-dev/neo-go/internal/random" + "github.com/nspcc-dev/neo-go/internal/testserdes" + "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" + "github.com/stretchr/testify/require" +) + +func TestMethodToken_Serializable(t *testing.T) { + getToken := func() *MethodToken { + return &MethodToken{ + Hash: random.Uint160(), + Method: "MethodName", + ParamCount: 2, + HasReturn: true, + CallFlag: callflag.ReadStates, + } + } + t.Run("good", func(t *testing.T) { + testserdes.EncodeDecodeBinary(t, getToken(), new(MethodToken)) + }) + t.Run("too long name", func(t *testing.T) { + tok := getToken() + tok.Method = strings.Repeat("s", maxMethodLength+1) + data, err := testserdes.EncodeBinary(tok) + require.NoError(t, err) + require.Error(t, testserdes.DecodeBinary(data, new(MethodToken))) + }) + t.Run("start with '_'", func(t *testing.T) { + tok := getToken() + tok.Method = "_method" + data, err := testserdes.EncodeBinary(tok) + require.NoError(t, err) + err = testserdes.DecodeBinary(data, new(MethodToken)) + require.True(t, errors.Is(err, errInvalidMethodName)) + }) + t.Run("invalid call flag", func(t *testing.T) { + tok := getToken() + tok.CallFlag = ^callflag.All + data, err := testserdes.EncodeBinary(tok) + require.NoError(t, err) + err = testserdes.DecodeBinary(data, new(MethodToken)) + require.True(t, errors.Is(err, errInvalidCallFlag)) + }) +} diff --git a/pkg/smartcontract/nef/nef.go b/pkg/smartcontract/nef/nef.go index 74476d0ab..cbf14c3d6 100644 --- a/pkg/smartcontract/nef/nef.go +++ b/pkg/smartcontract/nef/nef.go @@ -20,6 +20,7 @@ import ( // | Compiler | 32 bytes | Compiler used | // | Version | 32 bytes | Compiler version | // +------------+-----------+------------------------------------------------------------+ +// | Tokens | Var array | List of method tokens | // | Script | Var bytes | Var bytes for the payload | // +------------+-----------+------------------------------------------------------------+ // | Checksum | 4 bytes | First four bytes of double SHA256 hash of the header | @@ -37,8 +38,9 @@ const ( // File represents compiled contract file structure according to the NEF3 standard. type File struct { Header - Script []byte `json:"script"` - Checksum uint32 `json:"checksum"` + Tokens []MethodToken `json:"tokens"` + Script []byte `json:"script"` + Checksum uint32 `json:"checksum"` } // Header represents File header. @@ -56,6 +58,7 @@ func NewFile(script []byte) (*File, error) { Compiler: "neo-go", Version: config.Version, }, + Tokens: []MethodToken{}, Script: script, } if len(config.Version) > compilerFieldSize { @@ -115,6 +118,7 @@ func (n *File) CalculateChecksum() uint32 { // EncodeBinary implements io.Serializable interface. func (n *File) EncodeBinary(w *io.BinWriter) { n.Header.EncodeBinary(w) + w.WriteArray(n.Tokens) w.WriteVarBytes(n.Script) w.WriteU32LE(n.Checksum) } @@ -122,14 +126,15 @@ func (n *File) EncodeBinary(w *io.BinWriter) { // DecodeBinary implements io.Serializable interface. func (n *File) DecodeBinary(r *io.BinReader) { n.Header.DecodeBinary(r) + r.ReadArray(&n.Tokens) n.Script = r.ReadVarBytes(MaxScriptLength) - if len(n.Script) == 0 { + if r.Err == nil && len(n.Script) == 0 { r.Err = errors.New("empty script") return } n.Checksum = r.ReadU32LE() checksum := n.CalculateChecksum() - if checksum != n.Checksum { + if r.Err == nil && checksum != n.Checksum { r.Err = errors.New("checksum verification failure") return } diff --git a/pkg/smartcontract/nef/nef_test.go b/pkg/smartcontract/nef/nef_test.go index c0054e461..e96dd259f 100644 --- a/pkg/smartcontract/nef/nef_test.go +++ b/pkg/smartcontract/nef/nef_test.go @@ -6,7 +6,10 @@ import ( "strconv" "testing" + "github.com/nspcc-dev/neo-go/internal/random" "github.com/nspcc-dev/neo-go/internal/testserdes" + "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" + "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/require" ) @@ -18,6 +21,13 @@ func TestEncodeDecodeBinary(t *testing.T) { Compiler: "the best compiler ever", Version: "1.2.3.4", }, + Tokens: []MethodToken{{ + Hash: random.Uint160(), + Method: "method", + ParamCount: 3, + HasReturn: true, + CallFlag: callflag.WriteStates, + }}, Script: script, } @@ -45,8 +55,16 @@ func TestEncodeDecodeBinary(t *testing.T) { checkDecodeError(t, expected) }) + t.Run("invalid tokens list", func(t *testing.T) { + expected.Script = script + expected.Tokens[0].Method = "_reserved" + expected.Checksum = expected.CalculateChecksum() + checkDecodeError(t, expected) + }) + t.Run("positive", func(t *testing.T) { expected.Script = script + expected.Tokens[0].Method = "method" expected.Checksum = expected.CalculateChecksum() expected.Header.Magic = Magic testserdes.EncodeDecodeBinary(t, expected, &File{}) @@ -67,6 +85,13 @@ func TestBytesFromBytes(t *testing.T) { Compiler: "the best compiler ever", Version: "1.2.3.4", }, + Tokens: []MethodToken{{ + Hash: random.Uint160(), + Method: "someMethod", + ParamCount: 3, + HasReturn: true, + CallFlag: callflag.WriteStates, + }}, Script: script, } expected.Checksum = expected.CalculateChecksum() @@ -85,6 +110,13 @@ func TestMarshalUnmarshalJSON(t *testing.T) { Compiler: "test.compiler", Version: "test.ver", }, + Tokens: []MethodToken{{ + Hash: util.Uint160{0x12, 0x34, 0x56, 0x78, 0x91, 0x00}, + Method: "someMethod", + ParamCount: 3, + HasReturn: true, + CallFlag: callflag.WriteStates, + }}, Script: []byte{1, 2, 3, 4}, } expected.Checksum = expected.CalculateChecksum() @@ -95,6 +127,15 @@ func TestMarshalUnmarshalJSON(t *testing.T) { "magic":`+strconv.FormatUint(uint64(Magic), 10)+`, "compiler": "test.compiler", "version": "test.ver", + "tokens": [ + { + "hash": "0x`+expected.Tokens[0].Hash.StringLE()+`", + "method": "someMethod", + "paramcount": 3, + "hasreturnvalue": true, + "callflags": `+strconv.FormatInt(int64(expected.Tokens[0].CallFlag), 10)+` + } + ], "script": "`+base64.StdEncoding.EncodeToString(expected.Script)+`", "checksum":`+strconv.FormatUint(uint64(expected.Checksum), 10)+`}`, string(data)) From 0bbdee2ce1be103a7014ba12d72180ccb0b3a512 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Tue, 19 Jan 2021 10:55:34 +0300 Subject: [PATCH 3/4] nef: add Reserved bytes --- cli/testdata/verify.manifest.json | 2 +- cli/testdata/verify.nef | Bin 83 -> 87 bytes pkg/rpc/client/rpc_test.go | 6 +++--- pkg/rpc/server/server_test.go | 4 ++-- pkg/rpc/server/testdata/testblocks.acc | Bin 7667 -> 7675 bytes pkg/smartcontract/nef/nef.go | 16 ++++++++++++++++ pkg/smartcontract/nef/nef_test.go | 20 +++++++++++++++++++- 7 files changed, 41 insertions(+), 7 deletions(-) diff --git a/cli/testdata/verify.manifest.json b/cli/testdata/verify.manifest.json index 627b44167..103a744a8 100755 --- a/cli/testdata/verify.manifest.json +++ b/cli/testdata/verify.manifest.json @@ -1 +1 @@ -{"name":"verify","abi":{"methods":[{"name":"onPayment","offset":5,"parameters":[{"name":"from","type":"ByteArray"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"verify","offset":0,"parameters":[],"returntype":"Boolean","safe":false}],"events":[{"name":"Hello world!","parameters":[{"name":"args","type":"Array"}]}]},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null} \ No newline at end of file +{"name":"verify","abi":{"methods":[{"name":"verify","offset":0,"parameters":[],"returntype":"Boolean","safe":false},{"name":"onPayment","offset":5,"parameters":[{"name":"from","type":"ByteArray"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false}],"events":[{"name":"Hello world!","parameters":[{"name":"args","type":"Array"}]}]},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null} \ No newline at end of file diff --git a/cli/testdata/verify.nef b/cli/testdata/verify.nef index 3de780aee21a23f0914246ef4aa0425972083f83..5023c45488398a850b2e79ec0496eda99b301c52 100755 GIT binary patch delta 41 lcmWFzpJ1$FX_97SnrxiPfC4zf85sl}!WozyVz1vX0RWc#2bur? delta 37 kcmWF!o?xtyVw`AUV32IY00*4mj0}Pf;S9_UI+A5Y0D|8JEC2ui diff --git a/pkg/rpc/client/rpc_test.go b/pkg/rpc/client/rpc_test.go index 087ead720..51dc2940c 100644 --- a/pkg/rpc/client/rpc_test.go +++ b/pkg/rpc/client/rpc_test.go @@ -330,7 +330,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ } return c.GetContractStateByHash(hash) }, - serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go","version":"3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":2354924458},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"permissions":null,"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, + serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go","version":"3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":4011113905},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"permissions":null,"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, result: func(c *Client) interface{} { script, err := base64.StdEncoding.DecodeString("VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==") if err != nil { @@ -351,7 +351,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ invoke: func(c *Client) (interface{}, error) { return c.GetContractStateByAddressOrName("NWiu5oejTu925aeL9Hc1LX8SvaJhE23h15") }, - serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go","version":"3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":2354924458},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"permissions":null,"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, + serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go","version":"3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":4011113905},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"permissions":null,"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, result: func(c *Client) interface{} { script, err := base64.StdEncoding.DecodeString("VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==") if err != nil { @@ -372,7 +372,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ invoke: func(c *Client) (interface{}, error) { return c.GetContractStateByID(0) }, - serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go","version":"3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":2354924458},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"permissions":null,"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, + serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go","version":"3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":4011113905},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"permissions":null,"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, result: func(c *Client) interface{} { script, err := base64.StdEncoding.DecodeString("VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==") if err != nil { diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 99c8dc3e5..259321b3f 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -57,7 +57,7 @@ type rpcTestCase struct { } const testContractHash = "0b3bc97e94ed99e32dda46c9ecd2d3626979af06" -const deploymentTxHash = "fe9e91388ba9be39f771fddaf07d3719c490eb179788a3d193f248c7ed4cff61" +const deploymentTxHash = "e3a67acac29014dc8c24773752ac4535a0f020486749ec5c907234fc9328246c" const genesisBlockHash = "0542f4350c6e236d0509bcd98188b0034bfbecc1a0c7fcdb8e4295310d468b70" const verifyContractHash = "d2da8ee8c0bf6c5bf3dda1ef671dbf5fef7226e9" @@ -1408,7 +1408,7 @@ func checkNep17Balances(t *testing.T, e *executor, acc interface{}) { }, { Asset: e.chain.UtilityTokenHash(), - Amount: "80006673650", + Amount: "80006665650", LastUpdated: 7, }}, Address: testchain.PrivateKeyByID(0).GetScriptHash().StringLE(), diff --git a/pkg/rpc/server/testdata/testblocks.acc b/pkg/rpc/server/testdata/testblocks.acc index 501ed5fe66f009c369ec4f6978e82c6d45cc45fd..f3e5350c932bd6f549901eebe9f55a93e9601a99 100644 GIT binary patch delta 2097 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 diff --git a/pkg/smartcontract/nef/nef.go b/pkg/smartcontract/nef/nef.go index cbf14c3d6..92763a1a2 100644 --- a/pkg/smartcontract/nef/nef.go +++ b/pkg/smartcontract/nef/nef.go @@ -20,7 +20,9 @@ import ( // | Compiler | 32 bytes | Compiler used | // | Version | 32 bytes | Compiler version | // +------------+-----------+------------------------------------------------------------+ +// | Reserved | 2-bytes | Reserved for extensions. Must be 0. | // | Tokens | Var array | List of method tokens | +// | Reserved | 2-bytes | Reserved for extensions. Must be 0. | // | Script | Var bytes | Var bytes for the payload | // +------------+-----------+------------------------------------------------------------+ // | Checksum | 4 bytes | First four bytes of double SHA256 hash of the header | @@ -118,15 +120,29 @@ func (n *File) CalculateChecksum() uint32 { // EncodeBinary implements io.Serializable interface. func (n *File) EncodeBinary(w *io.BinWriter) { n.Header.EncodeBinary(w) + w.WriteU16LE(0) w.WriteArray(n.Tokens) + w.WriteU16LE(0) w.WriteVarBytes(n.Script) w.WriteU32LE(n.Checksum) } +var errInvalidReserved = errors.New("reserved bytes must be 0") + // DecodeBinary implements io.Serializable interface. func (n *File) DecodeBinary(r *io.BinReader) { n.Header.DecodeBinary(r) + reserved := r.ReadU16LE() + if r.Err == nil && reserved != 0 { + r.Err = errInvalidReserved + return + } r.ReadArray(&n.Tokens) + reserved = r.ReadU16LE() + if r.Err == nil && reserved != 0 { + r.Err = errInvalidReserved + return + } n.Script = r.ReadVarBytes(MaxScriptLength) if r.Err == nil && len(n.Script) == 0 { r.Err = errors.New("empty script") diff --git a/pkg/smartcontract/nef/nef_test.go b/pkg/smartcontract/nef/nef_test.go index e96dd259f..2d9bd7e5d 100644 --- a/pkg/smartcontract/nef/nef_test.go +++ b/pkg/smartcontract/nef/nef_test.go @@ -3,11 +3,13 @@ package nef import ( "encoding/base64" "encoding/json" + "errors" "strconv" "testing" "github.com/nspcc-dev/neo-go/internal/random" "github.com/nspcc-dev/neo-go/internal/testserdes" + "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/require" @@ -54,7 +56,6 @@ func TestEncodeDecodeBinary(t *testing.T) { expected.Checksum = expected.CalculateChecksum() checkDecodeError(t, expected) }) - t.Run("invalid tokens list", func(t *testing.T) { expected.Script = script expected.Tokens[0].Method = "_reserved" @@ -69,6 +70,23 @@ func TestEncodeDecodeBinary(t *testing.T) { expected.Header.Magic = Magic testserdes.EncodeDecodeBinary(t, expected, &File{}) }) + t.Run("invalid reserved bytes", func(t *testing.T) { + expected.Script = script + expected.Tokens = expected.Tokens[:0] + expected.Checksum = expected.CalculateChecksum() + bytes, err := testserdes.EncodeBinary(expected) + require.NoError(t, err) + + sz := io.GetVarSize(&expected.Header) + bytes[sz] = 1 + err = testserdes.DecodeBinary(bytes, new(File)) + require.True(t, errors.Is(err, errInvalidReserved), "got: %v", err) + + bytes[sz] = 0 + bytes[sz+3] = 1 + err = testserdes.DecodeBinary(bytes, new(File)) + require.True(t, errors.Is(err, errInvalidReserved), "got: %v", err) + }) } func checkDecodeError(t *testing.T, expected *File) { From 719dceff7727f5175068ad1f9d20181005833333 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Tue, 19 Jan 2021 11:08:34 +0300 Subject: [PATCH 4/4] nef: merge Compiler and Version fields --- pkg/core/interop/context.go | 3 +-- pkg/core/state/contract_test.go | 3 +-- pkg/rpc/client/rpc_test.go | 9 ++++----- pkg/smartcontract/nef/nef.go | 26 ++++++-------------------- pkg/smartcontract/nef/nef_test.go | 12 ++++-------- 5 files changed, 16 insertions(+), 37 deletions(-) diff --git a/pkg/core/interop/context.go b/pkg/core/interop/context.go index d82ff2748..02ac19bfb 100644 --- a/pkg/core/interop/context.go +++ b/pkg/core/interop/context.go @@ -117,9 +117,8 @@ func NewContractMD(name string, id int32) *ContractMD { // NEF is now stored in contract state and affects state dump. // Therefore values are taken from C# node. - c.NEF.Header.Compiler = "ScriptBuilder" + c.NEF.Header.Compiler = "neo-core-v3.0" c.NEF.Header.Magic = nef.Magic - c.NEF.Header.Version = "3.0" c.NEF.Script, c.Hash = state.CreateNativeContractHash(id) c.NEF.Checksum = c.NEF.CalculateChecksum() c.Manifest = *manifest.DefaultManifest(name) diff --git a/pkg/core/state/contract_test.go b/pkg/core/state/contract_test.go index 634cca9a4..5d4c224f1 100644 --- a/pkg/core/state/contract_test.go +++ b/pkg/core/state/contract_test.go @@ -41,8 +41,7 @@ func TestEncodeDecodeContractState(t *testing.T) { NEF: nef.File{ Header: nef.Header{ Magic: nef.Magic, - Compiler: "neo-go.test", - Version: "test", + Compiler: "neo-go.test-test", }, Tokens: []nef.MethodToken{}, Script: script, diff --git a/pkg/rpc/client/rpc_test.go b/pkg/rpc/client/rpc_test.go index 51dc2940c..7e5a713d8 100644 --- a/pkg/rpc/client/rpc_test.go +++ b/pkg/rpc/client/rpc_test.go @@ -330,7 +330,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ } return c.GetContractStateByHash(hash) }, - serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go","version":"3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":4011113905},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"permissions":null,"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, + serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go-3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":2512077441},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"permissions":null,"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, result: func(c *Client) interface{} { script, err := base64.StdEncoding.DecodeString("VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==") if err != nil { @@ -351,7 +351,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ invoke: func(c *Client) (interface{}, error) { return c.GetContractStateByAddressOrName("NWiu5oejTu925aeL9Hc1LX8SvaJhE23h15") }, - serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go","version":"3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":4011113905},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"permissions":null,"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, + serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go-3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":2512077441},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"permissions":null,"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, result: func(c *Client) interface{} { script, err := base64.StdEncoding.DecodeString("VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==") if err != nil { @@ -372,7 +372,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ invoke: func(c *Client) (interface{}, error) { return c.GetContractStateByID(0) }, - serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go","version":"3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":4011113905},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"permissions":null,"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, + serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go-3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":2512077441},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"permissions":null,"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, result: func(c *Client) interface{} { script, err := base64.StdEncoding.DecodeString("VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==") if err != nil { @@ -1632,8 +1632,7 @@ func TestUninitedClient(t *testing.T) { func newTestNEF(script []byte) nef.File { var ne nef.File ne.Header.Magic = nef.Magic - ne.Header.Version = "3.0" - ne.Header.Compiler = "neo-go" + ne.Header.Compiler = "neo-go-3.0" ne.Script = script ne.Checksum = ne.CalculateChecksum() return ne diff --git a/pkg/smartcontract/nef/nef.go b/pkg/smartcontract/nef/nef.go index 92763a1a2..71e470dc2 100644 --- a/pkg/smartcontract/nef/nef.go +++ b/pkg/smartcontract/nef/nef.go @@ -17,8 +17,7 @@ import ( // | Field | Length | Comment | // +------------+-----------+------------------------------------------------------------+ // | Magic | 4 bytes | Magic header | -// | Compiler | 32 bytes | Compiler used | -// | Version | 32 bytes | Compiler version | +// | Compiler | 64 bytes | Compiler used and it's version | // +------------+-----------+------------------------------------------------------------+ // | Reserved | 2-bytes | Reserved for extensions. Must be 0. | // | Tokens | Var array | List of method tokens | @@ -33,8 +32,8 @@ const ( Magic uint32 = 0x3346454E // MaxScriptLength is the maximum allowed contract script length. MaxScriptLength = 512 * 1024 - // compilerFieldSize is the length of `Compiler` and `Version` File header fields in bytes. - compilerFieldSize = 32 + // compilerFieldSize is the length of `Compiler` File header field in bytes. + compilerFieldSize = 64 ) // File represents compiled contract file structure according to the NEF3 standard. @@ -49,7 +48,6 @@ type File struct { type Header struct { Magic uint32 `json:"magic"` Compiler string `json:"compiler"` - Version string `json:"version"` } // NewFile returns new NEF3 file with script specified. @@ -57,14 +55,13 @@ func NewFile(script []byte) (*File, error) { file := &File{ Header: Header{ Magic: Magic, - Compiler: "neo-go", - Version: config.Version, + Compiler: "neo-go-" + config.Version, }, Tokens: []MethodToken{}, Script: script, } - if len(config.Version) > compilerFieldSize { - return nil, errors.New("too long version") + if len(file.Compiler) > compilerFieldSize { + return nil, errors.New("too long compiler field") } file.Checksum = file.CalculateChecksum() return file, nil @@ -80,11 +77,6 @@ func (h *Header) EncodeBinary(w *io.BinWriter) { var b = make([]byte, compilerFieldSize) copy(b, []byte(h.Compiler)) w.WriteBytes(b) - for i := range b { - b[i] = 0 - } - copy(b, []byte(h.Version)) - w.WriteBytes(b) } // DecodeBinary implements io.Serializable interface. @@ -100,12 +92,6 @@ func (h *Header) DecodeBinary(r *io.BinReader) { return r == 0 }) h.Compiler = string(buf) - buf = buf[:compilerFieldSize] - r.ReadBytes(buf) - buf = bytes.TrimRightFunc(buf, func(r rune) bool { - return r == 0 - }) - h.Version = string(buf) } // CalculateChecksum returns first 4 bytes of double-SHA256(Header) converted to uint32. diff --git a/pkg/smartcontract/nef/nef_test.go b/pkg/smartcontract/nef/nef_test.go index 2d9bd7e5d..8c52bae2c 100644 --- a/pkg/smartcontract/nef/nef_test.go +++ b/pkg/smartcontract/nef/nef_test.go @@ -20,8 +20,7 @@ func TestEncodeDecodeBinary(t *testing.T) { expected := &File{ Header: Header{ Magic: Magic, - Compiler: "the best compiler ever", - Version: "1.2.3.4", + Compiler: "best compiler version 1", }, Tokens: []MethodToken{{ Hash: random.Uint160(), @@ -100,8 +99,7 @@ func TestBytesFromBytes(t *testing.T) { expected := File{ Header: Header{ Magic: Magic, - Compiler: "the best compiler ever", - Version: "1.2.3.4", + Compiler: "best compiler version 1", }, Tokens: []MethodToken{{ Hash: random.Uint160(), @@ -125,8 +123,7 @@ func TestMarshalUnmarshalJSON(t *testing.T) { expected := &File{ Header: Header{ Magic: Magic, - Compiler: "test.compiler", - Version: "test.ver", + Compiler: "test.compiler-test.ver", }, Tokens: []MethodToken{{ Hash: util.Uint160{0x12, 0x34, 0x56, 0x78, 0x91, 0x00}, @@ -143,8 +140,7 @@ func TestMarshalUnmarshalJSON(t *testing.T) { require.NoError(t, err) require.JSONEq(t, `{ "magic":`+strconv.FormatUint(uint64(Magic), 10)+`, - "compiler": "test.compiler", - "version": "test.ver", + "compiler": "test.compiler-test.ver", "tokens": [ { "hash": "0x`+expected.Tokens[0].Hash.StringLE()+`",