Skip to content

Instantly share code, notes, and snippets.

View darkerego's full-sized avatar

Darkerego darkerego

View GitHub Profile
@darkerego
darkerego / noRenter.sol
Created January 24, 2025 22:56
Assembly ReenterancyGaurd
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
abstract contract NoReEnter {
uint8 internal mutex;
bytes32 constant internal ERROR_STATE_LOCKED = 0x07b2e09e00000000000000000000000000000000000000000000000000000000;
error StateLocked();
@darkerego
darkerego / Forwarder.sol
Created December 16, 2024 11:47
Obfuscated Forwarder
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract Forwarder {
// admin of the contract
address private immutable owner;
// Some randomness to ensure that each deployment has unique bytecode
bytes32 public immutable entropy = bytes32(keccak256(abi.encode(uint256(uint160(block.timestamp ^ (block.number / block.timestamp))))));
// this key is set at deploy time and never changes
@darkerego
darkerego / ProxyFactory.sol
Created December 11, 2024 21:58 — forked from GNSPS/ProxyFactory.sol
Improved `delegatecall` proxy contract factory (Solidity) [v0.0.5]
/***
* Shoutouts:
*
* Bytecode origin https://www.reddit.com/r/ethereum/comments/6ic49q/any_assembly_programmers_willing_to_write_a/dj5ceuw/
* Modified version of Vitalik's https://www.reddit.com/r/ethereum/comments/6c1jui/delegatecall_forwarders_how_to_save_5098_on/
* Credits to Jorge Izquierdo (@izqui) for coming up with this design here: https://gist.github.com/izqui/7f904443e6d19c1ab52ec7f5ad46b3a8
* Credits to Stefan George (@Georgi87) for inspiration for many of the improvements from Gnosis Safe: https://github.com/gnosis/gnosis-safe-contracts
*
* This version has many improvements over the original @izqui's library like using REVERT instead of THROWing on failed calls.
* It also implements the awesome design pattern for initializing code as seen in Gnosis Safe Factory: https://github.com/gnosis/gnosis-safe-contracts/blob/master/contracts/ProxyFactory.sol
@darkerego
darkerego / mweth.sol
Created December 2, 2024 17:30
Minimalist WETH
// SPDX-License-Identifier: MIT
pragma solidity ^ 0.8.18;
contract MinimalWrappedEther {
address public immutable admin;
uint256 public totalSupply;
uint256 public reservedEther;
string public name;
string public symbol;
@darkerego
darkerego / FlashMintableERC20.sol
Created November 22, 2024 12:16
Flash Mintable Token
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
@darkerego
darkerego / MinimalistERC20.sol
Created November 4, 2024 03:44
A minimalist ERC20 token size optimized for low deployment costs.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
abstract contract MinimalistErc20 {
address public owner;
string public name;
string public symbol;
uint256 public totalSupply;
uint8 immutable public decimals;
mapping (address => uint256) public balanceOf;
#!/bin/bash
# Get the total memory in kilobytes
TOTAL_MEM_KB=$(grep MemTotal /proc/meminfo | awk '{print $2}')
# Calculate half of the total memory
HALF_MEM_KB=$((TOTAL_MEM_KB / 2))
# Convert kilobytes to megabytes (MB)
HALF_MEM_MB=$((HALF_MEM_KB / 1024))
@darkerego
darkerego / test_particle_async_ws.py
Last active February 22, 2025 08:51
Using AsyncWeb3 with trio in python
#!/usr/bin/env python3
import multiprocessing
import os
import dotenv
import trio
import trio_asyncio
from asyncio.log import logger
from web3 import AsyncWeb3, WebSocketProvider
multiprocessing.freeze_support()
dotenv.load_dotenv()
@darkerego
darkerego / simulation.py
Created April 9, 2024 18:55
simulation
import numpy as np
import rebound
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
def add_galactic_potential(sim, mass_distribution):
"""
Simplified function to simulate the galactic potential effect on the simulation.
This function modifies the velocities of particles to simulate a basic galactic potential.
#! /bin/bash
# Modified to run both (redudantly, yes, I know, I am paranoid, you should be too) checks
#
set -eu
# find path to liblzma used by sshd
path="$(ldd $(which sshd) | grep liblzma | grep -o '/[^ ]*')"
echo 'Check one: does it even exist?'
# does it even exist?
if [ "$path" == "" ]