Skip to content

Instantly share code, notes, and snippets.

View chfast's full-sized avatar

Paweł Bylica chfast

View GitHub Profile
@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 / 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;
}
contract Timestamping {
mapping(bytes32 => uint256) stamps;
function Timestamping() {
set_stamp("hello world");
}
function set_stamp(bytes32 hash) {
stamps[hash] = block.timestamp;
// Bank Of Deposit
//
// This contract keeps user's ethers in its internal storage. This approach
// allows cheaper batch transfers than series of individual Ethereum
// transactions.
contract BankOfDeposit {
// OPT: solidity additionally hashes the key of the map what in case of
// address is a waste of gas
mapping(address => uint) _balance;
@chfast
chfast / boost-div.cpp
Created September 13, 2015 16:01
boost multiprecision div bug test case
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/version.hpp>
using u256 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>;
int main()
{
std::cout << "Boost " << BOOST_VERSION << std::endl;
Scanning dependencies of target alethzero_automoc
[ 0%] Automatic moc and uic for target alethzero
Generating ui_AlethZero.h
Generating ui_Connect.h
Generating ui_AllAccounts.h
Generating ui_BrainWallet.h
Generating ui_ImportKey.h
Generating ui_NewAccount.h
Generating ui_BlockList.h
Generating ui_ExportState.h
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
@chfast
chfast / bt
Created June 12, 2015 09:28
Assertion `_peer->m_asking == Asking::Nothing' failed
alethzero: /home/chfast/Projects/ethereum/cpp-ethereum/libethereum/EthereumHost.cpp:621: void dev::eth::EthereumHost::continueSync(dev::eth::EthereumPeer*): Assertion `_peer->m_asking == Asking::Nothing' failed.
[New Thread 0x7fff377f5700 (LWP 14688)]
[New Thread 0x7fff2cffc700 (LWP 14690)]
[New Thread 0x7fff36bf4700 (LWP 14689)]
[New Thread 0x7fff457fa700 (LWP 14680)]
[New Thread 0x7fff45ffb700 (LWP 14679)]
[New Thread 0x7fff467fc700 (LWP 14678)]
[New Thread 0x7fff46ffd700 (LWP 14677)]
[New Thread 0x7fff477fe700 (LWP 14676)]
[New Thread 0x7fff47fff700 (LWP 14675)]
@chfast
chfast / context.cpp
Created June 2, 2015 22:33
boost context
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <cstdlib>
#include <cstring>
#include <iostream>
@chfast
chfast / shift.ll
Last active August 29, 2015 14:16
LLVM shift test
; RUN: opt < %s -constprop -S | FileCheck %s
; CHECK-LABEL: shift_undef_65
define void @shift_undef_65(i65* %p) {
%r1 = lshr i65 2, 18446744073709551617
; CHECK: store i65 undef, %p
store i65 %r1, i65* %p
%r2 = ashr i65 4, 18446744073709551617
; CHECK: store i65 undef, %p