Skip to content

Instantly share code, notes, and snippets.

View mohamedhayibor's full-sized avatar
💭
Crawled out from Burnout, Back to Badass 💪🏾

Void mohamedhayibor

💭
Crawled out from Burnout, Back to Badass 💪🏾
View GitHub Profile
@mohamedhayibor
mohamedhayibor / EIP712.js
Created December 13, 2020 12:20 — forked from ajb413/EIP712.js
Module for creating EIP-712 signatures with Ethers.js as the only dependency. Works in the browser and Node.js (Ethers.js Web3 Provider / JSON RPC Provider).
// Based on https://github.com/ethereum/EIPs/blob/master/assets/eip-712/Example.js
const ethers = require('ethers');
function abiRawEncode(encTypes, encValues) {
const hexStr = ethers.utils.defaultAbiCoder.encode(encTypes, encValues);
return Buffer.from(hexStr.slice(2, hexStr.length), 'hex');
}
function keccak256(arg) {

The most widely used protocols will trend towards governance minimization.

  1. Coz that allows stakeholders (ie programmers...) to depend on a protocol.
  2. That creates a virtuous cycle of adoption allowing otherwise unachievable scale.
  3. Allows to set standards everyone depends on, leads to a synergy greater than the sum of its parts.

Yet Governance is important

Mechanism is an algorithm plus incentives.

A mechanism is a tool that takes inputs from multiple people and uses these inputs as a way to determine things about its participants' values, so as to make some kind of decision people care about.

In a well functioning mechanism, the decision made is both efficient (the best possible outcome given the participant's preferences, and incentive-compatible, meaning that people have the incentive to participate "honestly". Private property is as effective as it is: not because it is a god given right, but because it's credibly neutral mechanism that solves a lot of problems in society, far from all but still a lot.

It's easier to agree that a neutral mechanism treats everyone reasonably fairly than it is to convince a diverse group of people that some particular blacklist of unallowed political viewpoints is correct.

@mohamedhayibor
mohamedhayibor / notes-on-HFT-on-Dexes.md
Created November 7, 2020 14:28
Notes from paper: "High-Frequency Trading on Decentralized On-chain Exchanges" https://arxiv.org/pdf/2009.14021.pdf

Profitable

Our empirical results show that an adversary can achieve an average daily revenue of 3,414 USD.

Double edge sword

However, AMM DEXs also exacerbate malpractices by quoting asset prices in a fully deterministic way, providing relative certainty over the expected price impact of a trade. This enables a frontrunning adversary to perform attacks with predictable outcomes.

The fundamental intuition is that the delay in the time taken for a transaction to execute allows an adversary to profit by exploiting the knowledge of the direction of a price change. The attacks are called sandwich attacks because a victim transaction is sandwiched between adversarial transactions.

  1. Re-create contractless contracts using zksync create2

The best:

const cbor = require('cbor')
const bytecode = '70656e6420696e707574206e6f7465415a54454320617272617920696e646578206973206f7574206f6620626f756e6473a265627a7a7231582011639b922cf661bed862dc70ef7a0a62211ae58261383916450efb20b2fd6a4164736f6c63430005100032'
// last two bytes are 0032, interpreted in hex is 50, so length in hex is 100
// the metadata bytes are the last 100 chars, excluding the last 4 which are the size
const metadata = bytecode.slice(bytecode.length - 104, bytecode.length - 4)
const { solc } = cbor.decode(metadata)
@mohamedhayibor
mohamedhayibor / keyboardFix.md
Created June 12, 2020 08:36
Rapoo keyboard typing wrong characters

Hold ctrl + option + shift

pragma solidity ^0.4.26;
library CheckOverflows {
function add(uint256 n1, uint256 n2) internal pure returns(uint256 n3) {
n3 = n1 + n2;
require(n3 >= n1);
return n3;
}
function sub(uint256 n1, uint256 n2) internal pure returns(uint256) {

Temp notes