Skip to content

Instantly share code, notes, and snippets.

View chfast's full-sized avatar

Paweł Bylica chfast

View GitHub Profile
@chfast
chfast / u256_global_const.cpp
Created March 17, 2017 09:24
Compare global constant boost::multiprecision
#include <boost/multiprecision/cpp_int.hpp>
using u256 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>;
namespace
{
u256 const lowMask256 = 0xffffffffffffffff;
auto const lowMaskNative = 0xffffffffffffffff;
}
@chfast
chfast / Dinder.sol
Last active March 6, 2017 11:13
Dinder - Decentralized Tinder
pragma solidity ^0.4.9;
contract Dinder {
mapping(address => mapping(address => bool)) connections;
mapping(address => int) thumbUps;
function thumbUp(address a) {
if (connections[a][msg.sender]) throw;
connections[a][msg.sender] = true;
thumbUps[a] += 1;
@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",
  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

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
@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)
def decode_instruction(code, PC):
pass
def next_pc(instruction):
pass
class Subroutine:
begin
end
blocks = {}
@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);
,
"loop-mul" : {
"callcreates" : [
],
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "0x4e20",
"currentGasLimit" : "0x174876e800",
"currentNumber" : "0x270f",
"currentTimestamp" : "0x01"
@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) {