Skip to content

Instantly share code, notes, and snippets.

View karmacoma-eth's full-sized avatar

karmacoma karmacoma-eth

View GitHub Profile
@karmacoma-eth
karmacoma-eth / sending-ether-cheat-sheet.md
Last active August 22, 2024 17:07
Sending Ether Cheat Sheet

Sending Ether Cheat Sheet

TLDR

🥇 Instead of sending Ether, use the withdrawal pattern

🥈 If you really need to send Ether, use a safe wrapper like OpenZeppelin's Address.sendValue(addr, amount)

🥉 If you really need to send Ether without dependencies, use (bool success, ) = addr.call{value: amount}("")

@hrkrshnn
hrkrshnn / generic.org
Last active April 21, 2024 01:51
Some generic writeup about common gas optimizations, etc.

Upgrade to at least 0.8.4

Using newer compiler versions and the optimizer gives gas optimizations and additional safety checks for free!

The advantages of versions 0.8.* over <0.8.0 are:

  • Safemath by default from 0.8.0 (can be more gas efficient than some library based safemath).
  • Low level inliner from 0.8.2, leads to cheaper runtime gas. Especially relevant when the contract has small functions. For
@karmacoma-eth
karmacoma-eth / quine.etk
Last active March 18, 2023 18:28
EVM quine
# quine.etk
# ⬜ => ⬜
# A quine is a computer program which takes no input and produces a copy of its own source code as its only output.
# 0x80...f3 is the compiled code excluding the push16 instruction (from dup1 to return)
push16 0x8060801b17606f5953600152602136f3
# --- stack ---
dup1 # code code
push1 128 # 128 code code
@karmacoma-eth
karmacoma-eth / rev-calldata-chunks.huff
Created February 23, 2023 18:35
reverse calldata in chunks of 32 bytes
// Reverse bytes received in calldata (abcd -> dcba)
// https://twitter.com/huff_language/status/1583894073487654913
// code length 206
/// @author Philippe Dumonet <[email protected]> -- https://twitter.com/real_philogy/status/1584304102418223104
/// @author karma (@0xkarmacoma) -- https://twitter.com/0xkarmacoma/status/1584239664310779904
/// @author kaden.eth (@0xKaden) -- https://twitter.com/0xKaden/status/1584280521089376256/
#define macro reverse_word() = takes(1) returns(1) {
// [x0]
0x00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff
@emlazzarin
emlazzarin / bonfire_books.md
Last active April 26, 2024 19:18
pmarca's books for understanding The Bonfire Of The Universities
title author link
1 The Captive Mind Czesław Miłosz Amazon
2 Private Truths, Public Lies: The Social Consequences of Preference Falsification Timur Kuran Amazon
3 When Reason Goes on Holiday: Philosophers in Politics Neven Sesardić Amazon
4 Intellectuals and Society Thomas Sowell Amazon
5 Intellectuals: From Marx and Tolsoy to Sartre and Chomsky Paul Johnson Amazon
6 The Making of an American Thinking Class: Intellectuals and Intelligentsia in Puritan Massachusetts Darren Staloff [Amazon](ht