Skip to content

Instantly share code, notes, and snippets.

@chfast
chfast / Lottery.sol
Last active February 10, 2016 18:33
contract Lottery {
uint constant public maturity = 10; // blocks
address public owner;
uint public ownerDeposit; // golem account for commissions
function Lottery() {
owner = msg.sender;
}
@chfast
chfast / shrink.ll
Created March 23, 2016 11:00
Shrinking arithmetic in LLVM
define i128 @test_shrink_add_1(i128 %a, i128 %b) {
%small_a = trunc i128 %a to i64
%small_b = trunc i128 %b to i64
%big_a = zext i64 %small_a to i128
%big_b = zext i64 %small_b to i128
%r = add i128 %big_a, %big_b
ret i128 %r
}
@chfast
chfast / hash.cpp
Created August 16, 2016 20:19
Benchmark passing structs by value
#include "hash.hpp"
size_t rehash1_by_value(hash256 h) {
size_t s = 0;
for (auto c : h.bytes)
s ^= c + 0x9e3779b9 + (s<<6) + (s>>2);
return s;
}
size_t rehash1_by_ref(hash256 const& h) {
,
"loop-mul" : {
"callcreates" : [
],
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "0x4e20",
"currentGasLimit" : "0x174876e800",
"currentNumber" : "0x270f",
"currentTimestamp" : "0x01"
@chfast
chfast / switch.c
Last active November 18, 2016 15:55
LLVM switch for EVM
void f1(void);
void f2(void);
void f3(void);
void f4(void);
void f5(void);
void f6(void);
void f7(void);
void f8(void);
def decode_instruction(code, PC):
pass
def next_pc(instruction):
pass
class Subroutine:
begin
end
blocks = {}
@chfast
chfast / validate.c
Last active December 6, 2016 16:48
EVM Static Jumps and Stack Limitations
code[code_size] contains code to validate
frame_size[code_size] is filled with -1
validated_subs = Set()
subs_validation_queue = FIFO()
validate()
{
// Validate the "main" subroutine
validate_subroutine(0, 0, 0)
Test Case "stZeroCallsTest":
ℹ 15:11:40.553|testeth ZeroValue_CALL
EVM 15:11:40.567|testeth
STACK
MEMORY
STORAGE
EVM 15:11:40.567|testeth < 0 : @b94f5374… : #1 : 0 : GAS : 54712 : -2 : 0x32 >
EVM 15:11:40.567|testeth
STACK
  1. Extend BEGINSUB specification with third parameter max_frame_size -- the maximum size of the stack frame the subroutine is allowed to use.

  2. In the Validity section, after condition 6 add new conditions:

    6a. For JUMPSUB and JUMPSUBV the frame size + the max_frame_size of the BEGINSUB(s) to jump to is not greater than 1024.

    6b. The frame size is not greater than the max_frame_size of the enclosing subroutine.

  3. In the Validating subroutines section, after

@chfast
chfast / 0x7d559708572b8e4b5d982fc2ee543db6cbba974d7562a59e45ad959a48bfcc14.json
Created January 30, 2017 22:15
geth vmtrace of 0x7d559708572b8e4b5d982fc2ee543db6cbba974d7562a59e45ad959a48bfcc14 transaction
{
gas: 28964,
returnValue: "",
structLogs: [{
depth: 1,
error: null,
gas: 228725,
gasCost: 3,
memory: null,
op: "PUSH1",