Skip to content

Instantly share code, notes, and snippets.

@axic
axic / FRONTENDS.md
Last active July 1, 2023 09:03
LLVM Frontends

LLVM on the high level could be separated into:

    1. Core (operations which work on the LLVM IR AST)
    1. Optimisers
    1. Backends/targets - these generate the instructions for a given CPU (i.e. x86, ARM, WebAssembly, etc.)

There are many projects creating frontends for LLVM, which are actual compilers outputting LLVM IR.

Some of these include:

  • clang (C and C++)
  • llgo (Go)
@axic
axic / EWASMTest.wast
Last active August 2, 2016 08:23
Solidity eWASM compiled code
;; Contract: EWASMTest
(module
(import $calldatacopy "ethereum" "calldatacopy" (param i32 i32 i32))
(import $sstore "ethereum" "sstore" (param i32 i32))
(import $return "ethereum" "return" (param i32))
(memory 1 1)
(export "memory" memory)
(export "main" $main)
(func $main
(call_import $calldatacopy (i32.const 0) (i32.const 0) (i32.const 4))
@axic
axic / eth_interface.md
Created August 4, 2016 18:05
EEI v0.1

Block

  • blockHash -> getBlockHash
  • coinbase -> getCoinbase
  • difficulty -> getDifficulty
  • gasLimit -> getBlockGasLimit
  • number -> getBlockNumber
  • timestamp -> getBlockTimestamp

Tx

  • gasPrice -> getTxGasPrice
@axic
axic / keybase.md
Created August 8, 2016 00:15
Trying out keybase.io...

Keybase proof

I hereby claim:

  • I am axic on github.
  • I am axic (https://keybase.io/axic) on keybase.
  • I have a public key ASCAJvumCmc0vRQ86molQyK9QLq7BifAMHzWUqwcGplOZQo

To claim this, I am signing this object:

Determining eWASM gas costs

Alex Beregszaszi, August 2016

The goal of this document is to describe the process of determining gas costs for eWASM instructions.

Each WASM opcode is assigned an appropriate Intel IA-32 (x86) opcode (or a series of opcodes). These opcodes have a fixed cycle count (called latency by Intel). We are selecting one specific CPU model from the Haswell architecture

// (words * 3 + words ^ 2 / 512) - (allocated_words * 3 + allocated_words ^ 2 / 512)
var memsize = 1
var current = 0
while (true) {
var a = (memsize * 3) + (memsize ^ 2 / 512)
var b = ((memsize - 1) * 3) + ((memsize - 1) ^ 2 / 512)
current += (a - b)
@axic
axic / standardaccount.sol
Last active June 19, 2022 20:26
EIP101 Standard Account code in Solidity
//
// Implementation of the standard account contract as per EIP101 (Cryptocurrency
// abstraction). See: https://github.com/ethereum/EIPs/issues/28
//
// Written by Alex Beregszaszi, use under the MIT license.
//
contract StandardAccount {
uint256 nextSequence = 1;
{
"nonce": "0x000000000000006601",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x655741534d2074657374206e6574776f726b2030",
"gasLimit": "0x8000000",
"difficulty": "0x100000",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0",
"alloc": { }
@axic
axic / deployer.wast
Last active August 25, 2016 02:53
Standard eWASM deployer code.
;;
;; Standard eWASM deployer code.
;;
;; We keep the to-be-deployed contract as a memory segment and simply return it.
;;
(module
(memory 1
(segment 0 "\10\00\00\00") ;; Here comes the size of the code in LSB
(segment 4 "Hello World CODE") ;; Here comes the code as a escaped hex string
@axic
axic / creatorcontract.md
Last active August 30, 2016 19:51
Creator Contract abstraction

This is a follow up to ethereum/EIPs#86 with the intent of moving more logic to contract abstractions.

Motivation

Replace the special CREATE opcode and the special case of external transactions, which cause a contract to be deployed, with a contract.

Abstract

The creator contract (at address TBD) takes bytecode to be deployed as the input and returns 20 bytes output consisting of the 160-bit contract address.