Skip to content

Instantly share code, notes, and snippets.

@axic
axic / sha256.sol
Created September 18, 2016 14:42
Fake SHA256 in Solidity
contract SHA256 {
/* SHA-224 and SHA-256 constants for 64 rounds. These words represent
* the first 32 bits of the fractional parts of the cube
* roots of the first 64 prime numbers. */
uint[64] rounds;
function SHA256() {
rounds[0] = 0x428a2f98;
rounds[1] = 0x71374491;
@axic
axic / 640.c
Created September 10, 2016 20:55
#include <stdio.h>
#include "secp256k1.h"
int main(int argc, char *argv[]) {
// Convert the mnemonic to seed
const char *mnemonic = "radar blur cabbage chef fix engine embark joy scheme fiction master release";
if (!mnemonic_check(mnemonic))
printf("Invalid mnemonic!");
;; Contract: A
(module
(import $callDataCopy "ethereum" "callDataCopy" (param i32 i32 i32))
(import $storageStore "ethereum" "storageStore" (param i32 i32))
(import $getCallValue "ethereum" "getCallValue" (param i32))
(import $return "ethereum" "return" (param i32))
(memory 1 1)
(export "memory" memory)
(export "main" $main)
(func $main
@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.

@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
{
"nonce": "0x000000000000006601",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x655741534d2074657374206e6574776f726b2030",
"gasLimit": "0x8000000",
"difficulty": "0x100000",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0",
"alloc": { }
@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;
// (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)

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

@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: