Skip to content

Instantly share code, notes, and snippets.

@hrkrshnn
hrkrshnn / manage.sh
Created January 2, 2016 04:21
Manages pdfs
# Create directories
for char in {A..Z}; do
mkdir -p $char
done
# Move file according to Alphabetical order
for char in {A..Z}; do
mv $char*.pdf $char
done
@hrkrshnn
hrkrshnn / onlySideEffects.org
Last active June 19, 2020 14:43
List of yul instructions and some semantic information
InstructionAddArgsRetSideEffectsGas
STOP000trueZero
KECCAK256021trueSpecial
CALLDATACOPY030trueVeryLow
CODECOPY030trueVeryLow
EXTCODECOPY040trueExtCode
RETURNDATACOPY030trueVeryLow
MLOAD011trueVeryLow
MSTORE020trueVeryLow
@hrkrshnn
hrkrshnn / contract.sol
Last active June 29, 2020 16:26
LoopInvariantCodeMotion
contract Arraysum {
uint256[] values;
function sumArray() public view returns(uint) {
uint sum = 0;
for(uint i = 0; i < values.length; i++)
sum += values[i];
}
======= /tmp/deposit.sol:DepositContract =======
Developer Documentation
{
"kind": "dev",
"methods":
{
"deposit(bytes,bytes,bytes,bytes32)":
{
"params":
diff -u /tmp/abiOptold.yul /tmp/abiOpt.yul
--- /tmp/abiOptold.yul 2020-07-16 17:42:12.321040915 +0530
+++ /tmp/abiOpt.yul 2020-07-16 17:41:26.225218259 +0530
@@ -35,9 +35,9 @@
case 0x19da7652 {
if callvalue() { revert(_2, _2) }
let param, param_1, param_2, param_3 := abi_decode_tuple_t_array$_t_uint256_$30_memory_ptrt_array$_t_string_memory_ptr_$dyn_memory_ptrt_uint16t_address(_1, calldatasize())
- let ret_1, ret_2 := fun_f6_120(param, param_1, param_2, param_3)
+ let vloc__114_mpos, vloc__117_mpos := fun_f6_120()
let memPos_1 := allocateMemory(_2)
diff -u /tmp/abiOpt.yul /tmp/new.yul
--- /tmp/abiOpt.yul 2020-07-16 17:41:26.225218259 +0530
+++ /tmp/new.yul 2020-07-22 15:29:25.538743429 +0530
@@ -34,38 +34,38 @@
}
case 0x19da7652 {
if callvalue() { revert(_2, _2) }
- let param, param_1, param_2, param_3 := abi_decode_tuple_t_array$_t_uint256_$30_memory_ptrt_array$_t_string_memory_ptr_$dyn_memory_ptrt_uint16t_address(_1, calldatasize())
+ abi_decode_tuple_t_array$_t_uint256_$30_memory_ptrt_array$_t_string_memory_ptr_$dyn_memory_ptrt_uint16t_address(_1, calldatasize())
let vloc__114_mpos, vloc__117_mpos := fun_f6_120()
@hrkrshnn
hrkrshnn / exp.org
Last active July 24, 2020 14:42
Usage of non-trivial exponentation in aragonOS argent-contracts augur-core colonyNetwork openzeppelin-contracts safe-contracts synthetix uniswap-v2-core util-contracts
codefile
uint _newParentSkillNumber = _parentSkillNumber - 2**i;colonyNetwork/contracts/colonyNetwork/ColonyNetwork.sol
uint x = mul(10**sub(36, daysOpen), sub(864000, mul(9,r))) / 864000;colonyNetwork/contracts/colonyNetwork/ColonyNetworkAuction.sol
bytes32 shifted = bytes32(uint256(uint256(2) ** uint256(role)));colonyNetwork/contracts/common/DomainRoles.sol
by
@hrkrshnn
hrkrshnn / writeup.org
Last active July 31, 2020 09:30
Dealing a card on ethereum

Problem

Alice and Bob wants to deal one card to each other in a trustless way.

Data

An encoding of the deck

52 integers are fixed in the contract that represent 52 cards in the deck. Call this uint[52] deck

N

A large number.

Secrets for Alice and Bob

Optimized IR:
/*******************************************************
* WARNING *
* Solidity to Yul compilation is still EXPERIMENTAL *
* It can result in LOSS OF FUNDS or worse *
* !USE AT YOUR OWN RISK! *
*******************************************************/
object "DexConstraintPoly_10" {
code {
Optimized IR:
/*******************************************************
,* WARNING *
,* Solidity to Yul compilation is still EXPERIMENTAL *
,* It can result in LOSS OF FUNDS or worse *
,* !USE AT YOUR OWN RISK! *
,*******************************************************/
object "C_164" {
code {