Skip to content

Instantly share code, notes, and snippets.

View chfast's full-sized avatar

Paweł Bylica chfast

View GitHub Profile
@chfast
chfast / ec_benchmarks
Last active June 20, 2017 14:03
Ethereum precompiled ECADD and ECMUL test cases
ECADD("18b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9063c909c4720840cb5134cb9f59fa749755796819658d32efc0d288198f3726607c2b7f58a84bd6145f00c9c2bc0bb1a187f20ff2c92963a88019e7c6a014eed06614e20c147e940f2d70da3f74c9a17df361706a4485c742bd6788478fa17d7") -> "2243525c5efd4b9c3d3c45ac0ca3fe4dd85e830a4ce6b65fa1eeaee202839703301d1d33be6da8e509df21cc35964723180eed7532537db9ae5e7d48f195c915"
ECADD("2243525c5efd4b9c3d3c45ac0ca3fe4dd85e830a4ce6b65fa1eeaee202839703301d1d33be6da8e509df21cc35964723180eed7532537db9ae5e7d48f195c91518b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9063c909c4720840cb5134cb9f59fa749755796819658d32efc0d288198f37266") -> "2bd3e6d0f3b142924f5ca7b49ce5b9d54c4703d7ae5648e61d02268b1a0a9fb721611ce0a6af85915e2f1d70300909ce2e49dfad4a4619c8390cae66cefdb204"
ECMUL("2bd3e6d0f3b142924f5ca7b49ce5b9d54c4703d7ae5648e61d02268b1a0a9fb721611ce0a6af85915e2f1d70300909ce2e49dfad4a4619c8390cae66cefdb20400000000000000000000000000000000000000000000000011138ce750fa15c2") -> "070a8d6a982153cae4
0xbF5Eaf0B9508c84A1d63553aE304848E3A0D3E71
@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);