Skip to content

Commit

Permalink
smartcontract: reserve 4 bytes in NEF file
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnaShaleva committed Dec 17, 2020
1 parent f2365e2 commit f6786b2
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 2 deletions.
Binary file modified cli/testdata/verify.nef
Binary file not shown.
Empty file added cli/testdata/verify.yml
Empty file.
4 changes: 2 additions & 2 deletions pkg/rpc/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type rpcTestCase struct {
}

const testContractHash = "743ed26f78e29ecd595535b74a943b1f9ccbc444"
const deploymentTxHash = "faa8d607f4000dbb3fc41dda51110369888b8b65c40de85d36ae9e4879dc4982"
const deploymentTxHash = "e1dc00fc7410e704c9af45ad8d13114c32a7db32e3401bd00fe85e4ed3aa0243"
const genesisBlockHash = "0542f4350c6e236d0509bcd98188b0034bfbecc1a0c7fcdb8e4295310d468b70"

const verifyContractHash = "a2eb22340979804cb10cc1add0b8822c201f4d8a"
Expand Down Expand Up @@ -1347,7 +1347,7 @@ func checkNep17Balances(t *testing.T, e *executor, acc interface{}) {
},
{
Asset: e.chain.UtilityTokenHash(),
Amount: "80006564770",
Amount: "80006674650",
LastUpdated: 7,
}},
Address: testchain.PrivateKeyByID(0).GetScriptHash().StringLE(),
Expand Down
Binary file modified pkg/rpc/server/testdata/testblocks.acc
Binary file not shown.
7 changes: 7 additions & 0 deletions pkg/smartcontract/nef/nef.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
// | Compiler | 32 bytes | Compiler used |
// | Version | 32 bytes | Compiler version |
// +------------+-----------+------------------------------------------------------------+
// | Reserve | 4 bytes | 4 bytes are reserved for future 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 |
Expand Down Expand Up @@ -115,13 +117,18 @@ func (n *File) CalculateChecksum() uint32 {
// EncodeBinary implements io.Serializable interface.
func (n *File) EncodeBinary(w *io.BinWriter) {
n.Header.EncodeBinary(w)
w.WriteU32LE(0) // Reserve
w.WriteVarBytes(n.Script)
w.WriteU32LE(n.Checksum)
}

// DecodeBinary implements io.Serializable interface.
func (n *File) DecodeBinary(r *io.BinReader) {
n.Header.DecodeBinary(r)
reserved := r.ReadU32LE()
if reserved != 0 {
r.Err = errors.New("reserve should be 0")
}
n.Script = r.ReadVarBytes(MaxScriptLength)
if len(n.Script) == 0 {
r.Err = errors.New("empty script")
Expand Down

0 comments on commit f6786b2

Please sign in to comment.