Neo DevPack v3.11.3 adds Huyao APIs, compiler GAS optimizations
Developers who write Neo N3 smart contracts in C# can now write code for the new contract features of the Huyao hard fork, such as storage for data that expires and is removed automatically.
Neo DevPack v3.11.3 for .NET, released Dec. 2, also means contracts compiled with it need fewer instructions for many common operations, and so generally less GAS.
DevPack is the official toolkit for writing N3 contracts in C#. Its main parts are a framework library of ready-made contract code, the nccs compiler that turns C# into NeoVM instructions, and a testing engine for running contracts in automated tests.
The release is the first since v3.10.2 in early November and contains 135 merged pull requests. The new packages are published on NuGet as v3.11.3, and standalone builds of the compiler are available for Linux, macOS, and Windows.
Huyao features for contracts
DevPack v3.11.3 is built on the same Neo v3.11.3 core libraries as Neo-CLI v3.11.3, the node release that switches on the Huyao hard fork at block 21,560,000 on N3 TestNet and block 15,990,000 on MainNet.
The headline Huyao feature for contract developers is TemporaryStorage, a new built-in contract for data that only needs to exist for a while. A contract stores an entry with an expiry time, and the entry disappears once that time has passed (PR #2391).
A contract can read, renew, and delete its own entries, and it can read another contract’s entries that haven’t expired yet.
Contracts can also search their stored records from a chosen starting point, rather than from the beginning, with Storage.FindWithStart (PR #2333).
The framework also adds the new functions of the Policy contract, which holds network settings controlled by the Neo Council. Contracts can look up when a hard fork activates, and the Council can schedule hard forks after Huyao and set the longest time a TemporaryStorage entry may last.
These features only work on a network once Huyao has activated there. Huyao went live on N3 TestNet on Dec. 3 and is expected on MainNet around Dec. 25.
The DevPack testing engine treats Huyao as active from the first block, so GAS costs measured in tests reflect Huyao’s new pricing, which charges some instructions by the work they actually do.
Cheaper common operations
More than 30 pull requests in this release cut the instructions or GAS needed for specific operations, through changes to both the compiler and the framework library.
The operations include reading addresses, hashes, and public keys from text (PRs #2248 and #2291), converting hexadecimal text (PR #2275), and checking how a string starts or ends (PRs #2256, #2261, #2264, and #2384).
The framework’s NEP-17 and NEP-11 base classes, which developers build their own tokens on, were also optimized (PR #2273).
The compiler’s optimizer gained new stages that remove or combine redundant steps in compiled code and work out calculations on fixed values in advance (PRs #2313, #2332, and #2297).
The savings only apply to contracts compiled with v3.11.3. Contracts already on the network keep their existing code unless their developers recompile and update them.
New building blocks
PausableAccessControl is a new ready-made emergency stop that several accounts can operate, rather than a single owner (PR #2271). Accounts given a “pauser” role can pause and unpause the contract, and each action must be signed by that account. The existing single-owner version, PausableOwnable, remains available.
Three new collections store lists of addresses in a contract’s storage: UInt160Set, UInt160List, and UInt160IndexedSet (PR #2289). Each saves its addresses one by one, so adding or removing an address doesn’t mean rewriting the whole list.
Testing tools
Developers can now have their tests fail automatically when a contract starts using more GAS than before. To opt in, developers build their tests on a new ready-made test class, TestBaseWithGasTracking, which compares the GAS each contract run uses with a stored baseline (PRs #2269 and #2306).
The testing engine can also record in detail what happens inside a contract run, including calls to other contracts, storage reads and writes, and GAS used (PR #2295).
The release adds tools for fuzz testing, which runs a test repeatedly with automatically generated inputs to find cases that break the contract. The inputs are repeatable, so a failure can be replayed.
The release also includes examples for NEP-17 token transfers, minting, and burning, along with a guide to fuzz testing (PRs #2298 and #2381).
The compiler’s --security-analysis option runs several checks. One of them flags code that runs when a contract receives tokens and changes stored data without first checking which token contract sent the payment, and it was rewritten to raise fewer false alarms and miss fewer real problems (PR #2377).
Changes to check before upgrading
Most of the remaining pull requests fix cases where the compiler produced incorrect code. Developers upgrading should note the following:
StorageMap.GetIntegerandLocalStorageMap.GetInteger, which read a number from storage, now have a return type that allows null, which is what they return when nothing is stored under the requested key. Code that stores the result as a plain number may need updating (PR #2262).- Some C# patterns the compiler can’t translate correctly, such as lambdas that refer to the contract instance, now cause a build error instead of producing incorrect code (PR #2334).
- In NFT contracts built on
RoyaltyNep11Token, burning a token now also removes its royalty setting, so a new token minted with the same ID no longer inherits it (PR #2292). - The compiler now accepts manifest settings, such as which contracts a contract trusts and which standards it supports, only from the official framework’s own attributes. Before, a look-alike attribute with the same name from another library the contract used could add entries to its manifest (PR #2375).
The full release notes can be found at the link below:
https://github.com/neo-project/neo-devpack-dotnet/releases/tag/v3.11.3