Skip to content

Instantly share code, notes, and snippets.

View gakonst's full-sized avatar

Georgios Konstantopoulos gakonst

View GitHub Profile
pragma solidity 0.4.18;
contract C {
uint public x;
function cannotBeCalled() external {
x = 42;
}
function canBeCalled() {
x = 31337;
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;
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.18;
contract ForceEther {
bool youWin = false;
function onlyNonZeroBalance() {
require(this.balance > 0);
youWin = true;
}
// 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
@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);
}
@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 / 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

Verifying my identity on Peepeth.com 0x867b5ec95ef7d6cfe460e5ae2b88fc3d10ac9098
@gakonst
gakonst / signed-contract.ts
Created September 30, 2018 14:22
Allows offline signing of a contract instance with web3.js
import Web3 from 'web3'
import { Contract, Account, Signature } from 'web3/types';
// Converts any contract to a signed contract
class SignedContract {
account: Account
contract: Contract
address: string
web3: Web3