Skip to content

Instantly share code, notes, and snippets.

View gakonst's full-sized avatar

Georgios Konstantopoulos gakonst

View GitHub Profile
@gakonst
gakonst / asic.md
Last active April 4, 2018 09:27
Summary and Thoughts on the potential ASIC-Fork

To Fork or not To Fork, that is the question.

Introduction

For the people that have not been following the news, it is now confirmed that Bitmain is selling an Ethereum mining ASIC. This can be potentially harmful for Ethereum's decentralization and thus the community is currently discussing on how this should be approached, potentially through a hard-fork change in the hashing algorithm used to achieve consensus.

There are valid arguments on both sides. I'll refer to bits and pieces I have extracted from my reading and understanding so far. This is where we should discuss with concrete arguments on each case.

My assumption is that full PoS, and not PoW/PoS Casper with epochs, is not close enough to be considered a remedy.

Ideas for the Fork

@gakonst
gakonst / TestGas.solidity
Created March 23, 2018 14:44
Gas Testing for Libraries Public vs Internal
pragma solidity ^0.4.21;
library TestLibPublic {
struct Data {
uint n;
}
function Set(Data storage self, uint a) public {
self.n = a;
}
@gakonst
gakonst / EventTest.js
Last active August 21, 2018 19:21
Examples of event logging in web3.js. Take note that when used with testrpc/ganache, there are various bugs where events don't get fired or get fired twice. More here: https://github.com/trufflesuite/ganache-cli/issues/338. I also prefer using async/await instead of callbacks.
pragma solidity ^0.4.18;
contract EventTest {
event LogEventTest(uint _x);
event LogOtherEventTest(address indexed _sender);
function emitEvent(uint x) public {
LogEventTest(x);
}
// Highest bidder becomes the Leader.
// Vulnerable to DoS attack by an attacker contract which reverts all transactions to it.
contract CallToTheUnknown {
address currentLeader;
uint highestBid;
function() payable {
require(msg.value > highestBid);
require(currentLeader.send(highestBid)); // Refund the old leader, if it fails then revert
pragma solidity 0.4.18;
contract ForceEther {
bool youWin = false;
function onlyNonZeroBalance() {
require(this.balance > 0);
youWin = true;
}
function withdraw(uint _amount) public {
if(balances[msg.sender] >= _amount) {
if(msg.sender.call.value(_amount)()) {
_amount;
}
balances[msg.sender] -= _amount;
}
}
pragma solidity ^0.4.11;
// Credits to OpenZeppelin for this contract taken from the Ethernaut CTF
// https://ethernaut.zeppelin.solutions/level/0x68756ad5e1039e4f3b895cfaa16a3a79a5a73c59
contract Delegate {
address public owner;
function Delegate(address _owner) {
owner = _owner;
pragma solidity 0.4.18;
contract C {
uint public x;
function cannotBeCalled() external {
x = 42;
}
function canBeCalled() {
x = 31337;