• This repository has been archived on 28/Feb/2022
  • Stars
    star
    173
  • Rank 213,205 (Top 5 %)
  • Language Nearley
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

➕ A low-level, highly efficient extension to Yul, an intermediate language for the Ethereum Virtual Machine.

Yul+

Node.js CI npm version

A low-level, highly efficient extension to Yul, an intermediate smart-contract language for the Ethereum Virtual Machine.

Try it Now!

Features

  • All existing Yul features
  • Memory structures (mstruct)
  • Enums (enum)
  • Constants (const)
  • Ethereum standard ABI signature/topic generation (sig"function ...", topic"event ...)
  • Booleans (true, false)
  • Safe math (over/under flow protection for addition, subtraction, multiplication)
  • Injected methods (mslice and require)

Coming Soon

  • Static typing
  • CLI support

Installing

npm install yulp

Building From Source

npm install
npm run build
npm test

Library Usage

Code Example

const yulp = require('../index');
const source = yulp.compile(`

object "SimpleStore" {
  code {
    datacopy(0, dataoffset("Runtime"), datasize("Runtime"))
    return(0, datasize("Runtime"))
  }
  object "Runtime" {
    code {
      calldatacopy(0, 0, 36) // write calldata to memory

      mstruct StoreCalldata( // Custom addressable calldata structure
        sig: 4,
        val: 32
      )

      switch StoreCalldata.sig(0) // select signature from memory (at position 0)

      case sig"function store(uint256 val)" { // new signature method
        sstore(0, StoreCalldata.val(0)) // sstore calldata value
        log2(0, 0, topic"event Store(uint256 value)", StoreCalldata.val(0))
      }

      case sig"function get() returns (uint256)" {
        mstore(100, sload(0))
        return (100, 32)
      }
    }
  }
}

`);

console.log(yulp.print(source.results));

Enums

Here we have a fully featured enum identifier which acts as a constant.

object "contract" {
  code {
    enum Colors (
      Red,
      Blue,
      Green
    )

    log1(0, 0, Colors.Green) // logs 2 as a topic
  }
}

Constants

const will define a let variable value that cannot be re-assigned.

object "contract" {
  code {
    const firstVar := 0xaa
    const someOther := 1
  }
}

Memory Slice

mslice(position, length) will return a 1-32 byte value from memory.

object "contract" {
  code {
    mstore(30, 0xaaaa)

    log1(0, 0, mslice(30, 2)) // will log 0xaaaa
  }
}

Booleans

true and false are added and equate to values 0x01 and 0x00.

object "contract" {
  code {
    mstore(30, true)

    log1(0, 0, mload(30)) // will log 0x01
  }
}

Multi mstore sugar

mstore can now be used as a proxy method

object "contract" {
  code {
    mstore(30, 1, 2, 3, 4)

    /*
    mstore(30, 1)
    mstore(add(30, 32), 2)
    mstore(add(30, 64), 3)
    mstore(add(30, 96), 4)
    */
  }
}

Comparison Methods

lte, gte, neq can now be used.

if and(lte(1, 10), gte(5, 2)) {
  let k := neq(0, 1)
}

MAX_UINT

MAX_UINT literal is now available (i.e. uint(-1))

if lt(v, MAX_UINT) {
  let k := 1
}

Ethereum Standard ABI Signature and Topic Generation

sig" [ method abi ] " will equate to a 4 byte method signature hex value

topic" [ event abi definition ] " will equate to the 32 byte topic hash

object "contract" {
  code {
    const storeSig := sig"function store(uint256 val)"
    const eventSig := topic"event Store (uint256 indexed val)"

    log1(0, 0, storeSig) // will log 0x6057361d

    log1(0, 0, eventSig) // will log 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
  }
}

Memory Structures

Memory structures enable better handling of pre-existing in-memory structures.

mstruct Identifier ( [ property, ... ] )

A structure property is defined by an identifier and length specifier (i.e. blockProducer:32) where the identifier is blockProducer and the length is 32 bytes.

In-memory array like structures are defined using a name.length property, followed by a name:[array item size] property.

Note, mstruct properties allow for data chunk sizes up to 32 bytes only.

Inheritance

object "Utils" {
  code {
    const Size := 1

    function someMethod() -> {}
  }
}

object "SimpleStore" is "Utils" {
  code {
    mstore(0, Size)
    someMethod()
  }
}

Imports

We now support basic file system usage, we don't support local path resolution just yet.

The fs object is simply supplied at compile: yulp.compile(source, fs).

import "./Utils.yulp"

object "SimpleStore" is "Utils" {
  ...
}

Error Reporting

A new experimental (post v0.0.7) feature is the error"some message" literal.

This simply utf8 encodes the message to bytes, keccak256 hashes it and returns the first 4 bytes as an error identifier.

The compiler will return an errors property ({ [4 byte idenfitier]: [error message], ... }).

object "contract" {
  code {
    // example structure in memory of a BlockHeader starting at mem. position 400
    mstore(400, 0xaa) // block producer
    mstore(432, 0xbb) // previous block hash
    mstore(464, 0xcc) // block height
    mstore(496, 0x03) // length of anotherArray (i.e. 3 array items)
    mstore(554, 0xaaaabbbbcccc) // array with 3 elements, 0xaaaa, 0xbbbb, 0xcccc
    mstore(560, 0xdd) // Ethereum block number
    mstore(592, 0x01) // transaction roots array length
    mstore(652, 0xffffffff) // transaction roots, one 4 byte item 0xffffffff

    mstruct BlockHeader (
      blockProducer: 32,
      previousBlockHash: 32,
      blockHeight: 32,
      anotherArray.length: 32,
      anotherArray: [2],
      ethereumBlockNumber: 32,
      roots.length: 32,
      roots: [4]
    )

    BlockHeader.blockProducer(400) // will return 0xaa
    BlockHeader.blockProducer.size() // will return 32

    BlockHeader.blockHeight(400) // will return block height 0xcc
    BlockHeader.blockHeight.offset(400) // will return pos + length
    BlockHeader.blockHeight.position(400) // will return pos
    BlockHeader.blockHeight.size() // 32
    BlockHeader.blockHeight.index() // 2
    BlockHeader.blockHeight.keccak256(500) // keccak256 hash the block height

    BlockHeader.anotherArray(400, 2) // will return anotherArray item 0xcccc

    BlockHeader.size(400) // will return the size of the entire struct
    BlockHeader.offset(400) // will return entire offset position of the struct pos + length
    BlockHeader.keccak256(400) // keccak256 hash the entire block header
  }
}

Helping Out

There is always a lot of work to do, and will have many rules to maintain. So please help out in any way that you can:

  • Improve documentation.
  • Chime in on any open issue or pull request.
  • Open new issues about your ideas for making yulp better, and pull requests to show us how your idea works.
  • Add new tests to absolutely anything.
  • Create or contribute to ecosystem tools.
  • Spread the word!

We communicate via issues and pull requests.

Donating

Please consider donating if you think Yul+ is helpful to you or that my work is valuable. We are happy if you can help us buy a cup of coffee. ❤️

Or just send us some Dai, USDC or Ether:

Coming Soon

mstruct BasicRecursiveStructures ( // better structure description
  block: BlockHeader,
  root: RootHeader,
  proof: MerkleProof,
  leaf: TransactionLeaf,
  token: 32
)

mstruct SwitchStatements ( // special switch case
  data.switch: 1, // switch 0, 1, 2 for options below
  data: [InputUTXO,InputHTLC,TransactionDeposit]
)

mstruct FixedLengthArrays ( // special switch case
  someArr: (7)[32],
)

More Repositories

1

sway

🌴 Empowering everyone to build reliable and efficient smart contracts.
Rust
61,268
star
2

fuel-core

Rust full node implementation of the Fuel v2 protocol.
Rust
58,563
star
3

fuels-rs

Fuel Network Rust SDK
Rust
41,462
star
4

fuels-ts

Fuel Network Typescript SDK
TypeScript
41,350
star
5

fuel-specs

📝 Specifications for the Fuel protocol and the FuelVM, a blazingly fast blockchain VM.
1,428
star
6

sway-applications

Swaypplications
Rust
1,246
star
7

swayswap

SwaySwap is a blazingly fast DEX built on the fastest modular execution layer: Fuel.
TypeScript
975
star
8

sway-farm

Farm 🍅 on the Fuel network.
TypeScript
957
star
9

fuels-wallet

💳 The official Fuel wallet.
TypeScript
843
star
10

fuel-vm

Fuel v2 interpreter in Rust
Rust
254
star
11

awesome-fuel

A maintained and comprehensive list of awesome Fuel resources!
237
star
12

fuelup

⛽ The Fuel toolchain installer
Rust
195
star
13

fuel-indexer

🗃 The Fuel indexer is a standalone service that can be used to index various components of the Fuel blockchain.
Rust
129
star
14

fuel-bridge

The canonical Fuel bridge mono repo.
TypeScript
125
star
15

sway-libs

Miscellaneous Sway libraries.
Rust
123
star
16

sway-standards

SRC Standards set for the Sway language
Rust
123
star
17

forc-wallet

A forc plugin for managing Fuel wallets.
Rust
90
star
18

fuel.nix

A Nix flake for the Fuel Labs ecosystem.
Nix
87
star
19

fuel-v1-contracts

⚡ The Fuel optimistic rollup in Yul+ for the Ethereum Virtual Machine
JavaScript
84
star
20

fuel-ui

Fuel design system
TypeScript
82
star
21

fuel-js

⚡ All Fuel javascript utilities and implementations.
JavaScript
80
star
22

docs-hub

The documentation hub for Fuel
TypeScript
78
star
23

faucet

The official Fuel faucet
Rust
63
star
24

fuel-explorer

TypeScript
61
star
25

fuel-merkle-sol

A Solidity implementation of binary, sum, and sparse Merkle trees
Solidity
54
star
26

fuels-portal

The user facing portal and Fuel landing page
TypeScript
44
star
27

fuel-docs

📃 Top-level documentation for Fuel
JavaScript
42
star
28

bridge-message-predicates

Predicate for relaying messages from Ethereum to a Fuel contract
Rust
42
star
29

fuels-npm-packs

TypeScript
31
star
30

fuel-block-committer

A standalone service that commits Fuel block data to L1 / DA
Rust
29
star
31

quickstart

TypeScript
27
star
32

sway-playground

🌴▶️ Sway in the browser
TypeScript
26
star
33

fuel-bft

Tendermint consensus in Rust
Rust
24
star
34

authn-sign

✍️ authn-sign - A simplified browser interface for WebAuthn focused on secp256r1 (P-256).
JavaScript
22
star
35

sway-rfcs

RFCs for changes to Sway
22
star
36

intro-to-sway

Learn how to build a marketplace contract with Sway
TypeScript
21
star
37

sway-lib-std

Sway standard library.
Rust
21
star
38

fuel-crypto

Fuel cryptographic primitives.
Rust
20
star
39

sway-nightly-binaries

Fuel v2 full node and Sway toolchain nightly binaries
19
star
40

block-explorer-v2

Block explorer frontend for Fuel.
TypeScript
16
star
41

sway-vscode-plugin

Sway Visual Studio Code plugin
TypeScript
16
star
42

sway-performance-data

Sway performance data
15
star
43

fuel-burner-wallet

🔥 An experimental version of Burner Wallet using the Fuel open-beta.
HTML
15
star
44

bridge-fungible-token

Fuel contract for managing and issuing bridged versions of ERC-20 tokens
Rust
14
star
45

fuel-subgraph

Rust
14
star
46

sway.vim

Vim syntax file for Sway.
Vim Script
13
star
47

sway-lib-core

Sway standard library core primitives.
Rust
12
star
48

infrastructure

Shared infrastructure templates for Fuel services
HCL
12
star
49

fuel-tx

Fuel v2 transaction processing module in Rust.
Rust
12
star
50

github-actions

Reusable Actions workflows
JavaScript
11
star
51

EVM-Wallet-Connector

TypeScript
10
star
52

tree-sitter-sway

C
10
star
53

docs

📝 Documentation for the Fuel v1 tools and services.
CSS
9
star
54

action-fuel-toolchain

🛠️ GitHub Action for `fuelup` commands
TypeScript
9
star
55

sway-vs-solidity

1:1 code examples comparing Sway to Solidity
Solidity
9
star
56

sway-by-example-lib

Library for compiled sway programs
Rust
9
star
57

fuel-graphql-docs

Documentation for the Fuel GraphQL API
TypeScript
9
star
58

fuel-burner-plugin

🔥⚙️ Wallet plugin which connects Fuel network to the Burner architecture.
TypeScript
8
star
59

smt-test-generation

Generate specification compliant test data used for data-driven sparse Merkle tree testing
Go
8
star
60

rfcs

RFCs for changes to Fuel, and standards
Shell
7
star
61

fuel-design-tokens

Design tokens that we are using across Figma and Fuel
JavaScript
7
star
62

fuel-asm

Fuel assembly and opcodes module
Rust
6
star
63

fuel-debugger

Debugger for Fuel v2
Rust
6
star
64

developer-quickstart

scratch space for code behind developer quickstart section in book
TypeScript
6
star
65

fuel-types

Common types for Fuel v2
Rust
6
star
66

hacker-starter-kit

A resource for developers preparing to build on Fuel.
6
star
67

fuel-v2-contracts

The Fuel Solidity smart contract architecture.
TypeScript
5
star
68

fuel-abi-types

Rust
5
star
69

fuel-contributors

An exhaustive list of all Fuel Contributors
5
star
70

fuel-dev-env

Full stack Fuel development environment
Shell
5
star
71

fuel-wasm-examples

WASM examples for Fuel
Rust
5
star
72

reddit-cash

🌕 A Fuel-powered Reddit community tokens build on a Burner Wallet
TypeScript
5
star
73

sway-by-example

Examples of Sway programs
TypeScript
5
star
74

breaking-change-log

Biweekly consolidated breaking change log across the Fuel stack
5
star
75

releasy

Release Automation Tooling
Rust
5
star
76

fuel-merkle

Fuel Merkle trees in Rust.
Rust
5
star
77

fuel-storage

Storage traits for Fuel storage-backed data structures.
Rust
4
star
78

Solana-Wallet-Connector

TypeScript
4
star
79

demo-block-explorer

A bare-bones block explorer that demos the Fuel GraphQL API
TypeScript
4
star
80

typedoc-just-the-docs-theme

TypeScript
4
star
81

devcontainer-features

Features for Github Dev Containers for the Fuel ecosystem
Shell
4
star
82

fuel-low-level

Rust
4
star
83

docs-portal

Fuel's Documentation Portal
TypeScript
4
star
84

fuel-connectors

TypeScript
4
star
85

Pyth-integration

Sway
3
star
86

cargo-toml-lint

A linter for Cargo.toml files
Rust
3
star
87

action-forc

📦 GitHub Action for Sway `forc` command
3
star
88

sway-workshops

A set of example apps for workshops.
3
star
89

fuel-canary-watchtower

Allows for quickly pausing withdrawals if suspicious activity is detected
Rust
2
star
90

ETHDubai-2022-Workshop

Rust
2
star
91

fuel-assets

The official assets metadata on the Fuel Network
2
star
92

sway-by-example-archive

Let's explore how to design, write and test a contract
Rust
2
star
93

bridge-integration-tests

Integration tests for the Fuel Messaging Bridge
TypeScript
2
star
94

forc-explorer

Forc block explorer plugin
Rust
1
star
95

block-explorer-v2-backend

Backend of the block-explorer-v2 project
Shell
1
star
96

.github

1
star
97

sway-std

A mirror repo of sway lang's standard library
Sway
1
star
98

bridge-message-executor

Service for executing predicate based messages on Fuel
Rust
1
star
99

fuel-core-client-ext

Rust
1
star
100

sway-performance-dashboard

Sway performance dashboard
JavaScript
1
star