Typefully

Introducing HyperSDK Programs

Avatar

Share

 • 

2 years ago

 • 

View on X

Introducing 𝙃𝙮𝙥𝙚𝙧𝙎𝘿𝙆 𝙋𝙧𝙤𝙜𝙧𝙖𝙢𝙨: A Minimal, Performance-Focused, WASM-Based Smart Contract Framework for @avax @AvaxDevelopers github.com/ava-labs/hypersdk/pull/360 Starting 𝙏𝙊𝘿𝘼𝙔, you can write HyperSDK Programs in #Rust using the 𝘿𝙚𝙫𝙚𝙡𝙤𝙥𝙚𝙧 𝙋𝙧𝙚𝙫𝙞𝙚𝙬 🏗️ .
First, why "Programs" and not "Smart Contracts"? This is about "familiarity". When new developers hear "smart contract" for the first time, they have no idea what I'm talking about. "Programs" convey that if you know how to code, you can do this. That's exactly what we want.
So, how do these newfangled HyperSDK Programs look? Not newfangled 😉. It is difficult/expensive to reach mass adoption if devs have to learn a new language/use odd dialects of existing languages to deploy their code. HyperSDK Programs meet devs where they are. It's minimal.
@samlioku and @hexfusion prepared a few examples using Rust to showcase this notion of "familiarity". First up, here is a simple counter: github.com/ava-labs/hypersdk/blob/main/x/programs/rust/examples/counter_program/src/lib.rs
Counters are cool but I'm familiar with tokens...how would I do that? Look no further: github.com/ava-labs/hypersdk/blob/main/x/programs/rust/examples/token_contract/src/lib.rs
Programs only get cool once you can call other Programs...can you do that? I couldn't agree more: github.com/ava-labs/hypersdk/blob/main/x/programs/rust/examples/lottery/src/lib.rs
WASM only allows a handful of types to be passed into functions (i32, i64, f32, f64, v128, funcref, externref): webassembly.github.io/spec/core/syntax/types.html As you can see, we got around this constraint with a macro that magically transforms complex function args: github.com/ava-labs/hypersdk/blob/main/x/programs/rust/expose_macro/src/lib.rs
Everything HyperSDK is performance-driven and Programs are no exception. To avoid the biggest bottlenecks devs typically run into when using WASM (memory allocation and serialization), complex objs are never injected into the execution environment (just a reference to them). twitter.com/_patrickogrady/status/1628109794732298241
The primary "learning curve" for HyperSDK Programs relates to storing/interacting with variables in state. Normally, interacting with complex objects in Rust (or other languages) is just done "in memory" (ex: a map lives on the heap). Not here.
To interact with complex objects (like a map), developers invoke a "host function" to read specific keys from a map stored in the host environment instead of interacting with the object directly in WASM memory: github.com/ava-labs/hypersdk/blob/main/x/programs/rust/wasmlanche_sdk/src/store/mod.rs
Rust not your jam (hint: don't tell a Rust dev that) ? WASM compilation is supported by many languages. We only have a Rust SDK for now but look forward to community SDKs that unblock development in C/C++/Zig/TinyGo 🤓 .
What can/can't you do 𝙏𝙊𝘿𝘼𝙔? (i.e. What's a "Developer Preview"?) You **can** write your own HyperSDK Programs and run them in a basic WASM runtime. You **can't** deploy HyperSDK Programs on-chain (yet).
With any new framework, community feedback early and often is critical for world-class DX. Although the runtime isn't complete/performant yet, we wanted to shift development into the open as soon as there was a basic foundation to build on. Let us know what could be better!
Concurrently, we are working on a minimal (strip out all unnecessary WASM functionality), metered, deterministic, Golang WASM runtime to execute these programs based on Wazero (github.com/ava-labs/wazero). If you'd like to get involved in this effort, please let us know!
Other future work includes (but not limited to): * Program Constraints (enforce end conditions to protect against bugs) * Multi-Dimensional Fee Pricing (charge for each resource independently): github.com/ava-labs/hypersdk/pull/352 * Use State Keys to Create Parallel Execution Tree
Check out my talk at Summit II if you want more context on the HyperSDK and HyperSDK Programs: youtube.com/watch?v=ua00A10iDyE
Lastly, **HUGE** shoutout to @samlioku and @hexfusion for taking this project from a list of bullets I had on paper into an E2E Developer Preview. ❤️ Stay tuned for @samlioku's deep dive later today!
You can read the unrolled version of this thread here: typefully.com/_patrickogrady/WcxS9hP
Avatar

patrickogrady.xyz

@_patrickogrady

founder @commonwarexyz || previously @avalabs @coinbase @stanford || opinions are my own and will probably change