Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEP: NEO Executable Format (NEF) #121

Merged
merged 26 commits into from
Jul 29, 2021
Merged
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions nep-16.mediawiki
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<pre>
NEP: 16
Title: NEO Executable Format (NEF)
Author: Fernando Díaz Toledano <shargon@gmail.com>, Erik Zhang <erik@neo.org>, Igor Machado Coelho <igormachado@gmail.com>, Li Jianying <lightsever@hotmail.com>, Vitor Nazário Coelho <vncoelho@gmail.com>
Type: Standard
Status: Accepted
Created: 2020-03-31
</pre>

==Abstract==

A <code>NefFile</code> is a file meeting the standard format for a valid NEO executable file. It provides the basic information about the script, including the compiler and version.

This NEP describes the NEF standard for NEO smart contracts.

==Motivation==

Although we use neo-vm as the virtual machine currently, we should have other scripts in the future. A standard definition for the executable file format can guarantee both the feasibility of other vm code and the validity of the script file.
erikzhang marked this conversation as resolved.
Show resolved Hide resolved

==Specification==

In the field definitions below, we provide both the definitions of the fields as well as the corresponding functions.

==NefFile Structure==
erikzhang marked this conversation as resolved.
Show resolved Hide resolved

A <code>nef</code> file consists of a stream of 8-bit bytes. Multibyte data items are always stored in little-endian order, where the low bytes come first. Its structure is described further below.

{| class="wikitable sortable" style="width: auto; text-align: center; font-size: smaller; table-layout: fixed;"
!<nowiki>#</nowiki>
!size
!item
|-
| 1
| 4 bytes
| magic
|-
| 2
| 32 bytes
| compiler
|-
| 3
| 32 bytes
| version
|-
| 4
| 4 bytes
| Reserve
|-
| 5
| variable bytes
| script
|-
| 6
| 4 bytes
| checksum
|}

erikzhang marked this conversation as resolved.
Show resolved Hide resolved
===magic===

The <code>magic</code> item supplies the magic number identifying the <code>NEF3</code> file format; it has the value <code>0x3346454E</code>.

===compiler===

The <code>compiler</code> is a UTF-8 encoded <code>string</code> representing the compiler used to create the data in the <code>script</code> item. It is a fixed-length item, which is padded to force alignment on 32-byte boundary.

===version===

The compiler <code>version</code> is represented using a 32-byte string encoded in UTF-8. It must be padded with padding bytes to make it up to the required length if shorter than 32 bytes.

===reserve===

All bits of the <code>reserve</code> item are reserved for future use. They should be set to zero in generated nef files and should be ignored by Neo Virtual Machine implementations.

===script===

The value of <code>script</code> stores the raw VM opcodes. The data should be serialised using the variable length format as described in the [https://docs.neo.org/developerguide/en/articles/conventions.html#variable-length-types documentation].

===checksum===

The <code>checksum</code> item is used not only to ensure a corrupt-free transmission, but also to ensure that the file has not been tampered with. It is computed by using the SHA256 algorithm to hash the serialised `NefFile` excluding `checksum` twice, and converting the result into a 32-bit unsigned integer.