Skip to content

refcell/edge-rs

Repository files navigation

edge-rs

CI License Language EVM Rust Alpha

Important

Edge is alpha software. The compiler is under active development — language features, syntax, and APIs will change without notice. Do not use in production.

edge-rs is a compiler for the Edge language — an EVM-targeted DSL for writing smart contracts with a Rust-like type system.

Install | Examples | Lore | Contributing | License

What is Edge?

Edge is a statically-typed, Rust-inspired language that compiles to EVM bytecode. It gives you EVM-native integer and byte types (u8 through u256, i8 through i256, b1 through b32), along with addr, bool, and bit as first-class primitives. Every variable carries an explicit data location annotation — &s for storage, &t for transient storage, &m for memory, &cd for calldata — so the compiler always knows exactly where your data lives and can enforce that statically. Contracts and ABIs are declared at the language level rather than bolted on. The type system supports traits, generics, and pattern matching over union types, and a comptime keyword lets you run arbitrary code at compile time to generate constants or specialized implementations without runtime cost.

Install

Install the Edge toolchain via edgeup:

curl -fsSL https://raw.githubusercontent.com/refcell/edge-rs/main/etc/install.sh | sh

Or build from source:

cargo install --path bin/edgec

Examples

See the examples/ directory for complete Edge programs. The introductory files cover basic syntax; the lib/ and tokens/ subdirectories contain a set of composable contracts — fixed-point math, ownership primitives, ERC-20/721/4626 — structured the way a real Edge project would be.

Compiling a contract

Pass a source file directly to compile it — edgec prints the bytecode as a hex string to stdout:

# Compile to EVM bytecode (prints hex to stdout)
edgec examples/counter.edge
# 60003560e01c8063d09de08a146100365780632baeceb7146100...

# Write raw bytecode bytes to a file
edgec examples/counter.edge -o counter.bin

# Enable compiler tracing (-v warn, -vv info, -vvv debug, -vvvv trace)
edgec -v examples/expressions.edge

Debugging the pipeline

# Print the token stream
edgec lex examples/counter.edge

# Print the AST
edgec parse examples/counter.edge

# Type-check only (no codegen)
edgec check examples/counter.edge

# Print the contract ABI as JSON
edgec --emit abi examples/counter.edge
# [{"type":"function","name":"increment","inputs":[],"outputs":[],"stateMutability":"view"}, ...]

# Standard JSON I/O (for tool integration — reads from stdin, writes to stdout)
echo '{"language":"Edge","sources":{"counter.edge":{"content":"..."}}}' | edgec standard-json
# {"sources":{"counter.edge":{"id":0}},"contracts":{"counter.edge":{"Counter":{"abi":[...],"evm":{"bytecode":{"object":"604d..."},...}}}}}

Example: counter contract

contract Counter {
    let count: &s u256;

    pub fn increment() {
        let val: u256;
        val = count + 1;
        count = val;
    }

    pub fn get() -> (u256) {
        return count;
    }

    pub fn reset() {
        count = 0;
    }
}
edgec examples/counter.edge
# 60003560e01c8063d09de08a14610036578063...  (127 bytes)

The compiled bytecode includes a selector dispatcher, storage reads/writes via SLOAD/SSTORE, and a revert fallback for unknown selectors — all verified against a live EVM in the integration tests.

More examples

# Arithmetic, comparisons, bitwise ops, operator precedence
edgec examples/expressions.edge         # 329 bytes

# ERC-20 token contract
edgec examples/erc20.edge               # 334 bytes

# Composable library modules
edgec parse examples/lib/math.edge
edgec parse examples/tokens/erc4626.edge

Lore

Edge was conceived by jtriley, an Ethereum developer and EVM language researcher who had spent years studying the design space of smart contract languages. In November 2023 he published "The Edge Programming Language" on his Substack, laying out both a diagnosis and a proposed cure.

The diagnosis was blunt. A 2021 Trail of Bits report found that roughly ninety percent of all deployed EVM smart contracts share at least fifty-six percent of their bytecode with other contracts, a sign that the abstraction mechanisms available to developers were badly broken. Teams were copy-pasting instead of composing. The existing languages either gave you Solidity's implicit compiler decisions and sprawling inheritance graphs, or they gave you Huff's raw opcodes with no type safety at all. Nothing in between let an experienced engineer write genuinely reusable, auditable, low-overhead code without reaching for assembly.

jtriley had spent significant time inside the Huff ecosystem alongside refcell, clabby, and others who were core contributors to huff-rs and the broader huff-language organization. That work — building huffmate, writing optimized contracts directly in opcodes, and pushing up against everything Huff could not express — gave the group a precise understanding of where the abstraction floor needed to be and what it felt like to bump into a language ceiling on production code.

jtriley had also written extensively about this gap, comparing Huff and Yul, cataloguing the ways Solidity quietly allocates memory as if garbage collection exists when it does not, and documenting how its type system makes it hard to transfer assets without inline assembly. His conclusion was that the field had become trapped in what he called status quo ossification: new languages kept arriving as Solidity lookalikes chasing gas efficiency, without offering anything fundamentally new.

Edge was his attempt to start from first principles. The goal was not to replace Solidity for beginners but to give experienced teams a language that combined the granularity of Huff with the type system and compile-time execution of a high-level language. That combination, jtriley argued, would unlock constructs that no existing smart contract language could express at all — type-checked SSTORE2 implementations, in-memory hash maps, compressed ABI encoders, elliptic curve types, nested virtual machines with zero stack overhead. The key insight was that explicit data location annotations for all seven EVM storage areas, paired with parametric polymorphism and a trait system, would let the type checker enforce correctness that developers currently had to maintain by hand or discover through audit.

jtriley presented Edge at Solidity Summit 2023 alongside contributors from other EVM language projects, and the specification has been available at edge-specification.vercel.app since the announcement, and is hosted here at edge.refcell.org. edge-rs is the Rust implementation of that compiler.

Contributing

All contributions are welcome. Open an issue or pull request on GitHub.

License

This project is licensed under the MIT License.

About

Edge is a high level, strongly statically typed, multi-paradigm domain specific language for the Ethereum Virtual Machine (EVM) built in Rust.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors