Skip to content

Instantly share code, notes, and snippets.

contract ERC165 {
function interfaceID() constant returns (uint)
{
bytes4[] sigs = type(this).signatures;
uint mask = 0;
for (var i = 0; i < sigs.length; i++)
mask ^= uint(sigs[i]);
return mask;
}
}
/*
* STATICCALL Proxy
*
* It expects the input:
* 256 bit - address
* 256 bit - gas
* 256 bit - value
* n bit - calldata to be proxied
*
* And returns the output:
contract HelloWorld {
string name;
uint number;
function HelloWorld(string _name) {
name = _name;
}
function getName() returns (string) {
return name;
@axic
axic / README.md
Created February 10, 2017 01:37
WebAssembly kickstart guide

WebAssembly kickstart guide

Rolling your own compiler

One of the premises of WebAssembly is to support compiling multiple languages to WebAssembly.

C/C++

Building

pragma solidity ^0.4.6;
contract MemcpyTest {
function test(string input) returns (string output) {
uint len = bytes(input).length;
output = new string(len);
uint _input;
uint _output;
assembly {
@axic
axic / Pathing.md
Last active November 17, 2016 21:40

Representing relative paths

In any system where variable length paths can be used to traverse objects the can be a need to reference

  • self
  • peers
  • parent(s)
  • child(ren)

Proposal is to use an array to represent paths:

  • self is an empty array: []
@axic
axic / BytecodeDeployer.sol
Created October 22, 2016 21:04
Deploy bytecode using Solidity
pragma solidity ^0.4.2;
contract BytecodeDeployer {
function test() returns (address) {
return createFromBytecode(0, hex"60006000f3");
}
function createFromBytecode(uint value, bytes bytecode) returns (address result) {
assembly {
let size := mload(bytecode)
result := create(value, add(bytecode, 32), size)
}
@axic
axic / eip150forkcheck.sol
Last active October 15, 2016 00:39
EIP150 fork check in Solidity
contract EIP150ForkCheck {
bool public active = false;
bool public executed = false;
uint public constant fork_block = 42; // FIXME
function update() {
if (block.number < fork_block) {
return;
}
@axic
axic / concept.md
Last active October 13, 2016 10:03
Metered Ethereum State

Metered Ethereum State

Based on the idea of @wanderer, the goal is to have as many processes metered deterministically as possible. Currently (Ethereum Homestead), a lot of processes aren't metered and therefore correct, or incorrect, guesses are made at how much any of these should cost. (See the gas cost table.)

Assume:

  1. Using eWASM
  2. SSTORE, SLOAD, CALL, etc. are callback based
  3. Elevated Contracts are those not residing in the state
@axic
axic / EVMASM.md
Last active April 2, 2024 13:13
EVM Assembly Language

EVM Assembly Language

Motivation

The goal is to specify a syntax for an EVM assembly language, which can be used across various tools.

The format should be human readable, map EVM as closely as possible, allow for comments and refrain from complex syntax.

Specification