Skip to content

Instantly share code, notes, and snippets.

@axic
axic / hello.bf.wast
Last active January 26, 2018 00:48
"Hello World" in Brainf* compiled to eWASM using https://github.com/axic/bf-compiler-webassembly/tree/ewasm
;; "Hello World" in Brainf* compiled to eWASM using https://github.com/axic/bf-compiler-webassembly/tree/ewasm
(module
(func $callDataCopy (import "ethereum" "callDataCopy") (param i32 i32 i32))
(func $return (import "ethereum" "return") (param i32 i32))
(global $writeptr (mut i32) (i32.const 1))
(global $readptr (mut i32) (i32.const 0))
(func $getchar
(result i32)
@axic
axic / dummymetering.wasmhex
Last active January 21, 2018 14:59
Dummy eWASM sentinel contract
0061736d0100000001170560017e006000017f60037f7f7f0060027f7f0060000002580408657468657265756d06757365476173000008657468657265756d0f67657443616c6c4461746153697a65000108657468657265756d0c63616c6c44617461436f7079000208657468657265756d0672657475726e0003030201040503010001071102066d656d6f72790200046d61696e00040a25012301017f1001210042ba022000ad7e42e40080100041004100200010024100200010030b
pragma solidity ^0.4.19;
interface ShenzhenKitties {
function transferKittie(address to, string name) external;
function kittieOwner(string name) external view returns (address);
}
contract KittieEscrow {
ShenzhenKitties constant kittieRegistry = ShenzhenKitties(0x59f710ab6e0D4bafc20B3B86dC1bcC196d5ae16F);
address public beneficiary;
pragma solidity ^0.4.19;
pragma experimental ABIEncoderV2;
contract ShenzhenKitties {
event Registered(string name, address owner);
event Transferred(string name, address from, address to);
mapping (bytes32 => address) kitties;
string[] public kittieNames;
@axic
axic / swarmdemo.js
Created July 15, 2016 16:24
Web3 demo code for Swarm
//
// Needs web3.js from https://github.com/axic/web3.js/tree/swarm
//
var Web3 = require('web3')
var url = require('url')
var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'))
try {
web3.eth.defaultAccount = web3.eth.coinbase
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 {
// the Hypervisor starts an manages "containers"
class PrimeaContainer {
// the constructor is given an instance of the kernel
// https://github.com/primea/js-primea-hypervisor/blob/master/docs/kernel.md
constructor (kernel) {
this.kernel = kernel
}
// this method runs once when the container is initially created. It is given
// a message with a single port, which is a channel to its parent with the
{
let cur_block_number := number()
jumpi(system_sender, eq(caller(), 0xfffffffffffffffffffffffffffffffffffffffe))
// Sender is a regular account - Getting a block
{
let block_number := calldataload(0)
// Abort if block is in future
@axic
axic / blockhash.evmasm
Created May 5, 2017 08:07
EIP96 sample implementation in Assembly
{
// Reject incoming value transfers
jumpi(unpaid, iszero(callvalue()))
invalid
unpaid:
let cur_block_number := number()
jumpi(system_sender, eq(caller(), 0xfffffffffffffffffffffffffffffffffffffffe))
@axic
axic / hello.c
Last active May 4, 2017 14:36
Sample clang compiled webassembly
main() {
char buf[4096] = { 0 };
unsigned long long x = 1;
printf("hello %lld", x);
}