Skip to content

Instantly share code, notes, and snippets.

View pcaversaccio's full-sized avatar
πŸ’―
Percent Commitment

sudo rm -rf --no-preserve-root / pcaversaccio

πŸ’―
Percent Commitment
View GitHub Profile
@pcaversaccio
pcaversaccio / README.md
Last active June 16, 2025 09:56
A step-by-step guide to deploy a 1-out-of-1 Safe `1.4.1` contract via `CreateX`.

Safe 1.4.1 Deployment via CreateX

Special thanks go to Richard Meissner for feedback and review.

Important

This approach requires a deep understanding of how the Safe contracts and CreateX mechanisms work. The recommended way to deploy a Safe contract remains through the SafeProxyFactory contract.

We will deploy a 1-out-of-1 1.4.1 Safe contract via CreateX.

setup Function

@pcaversaccio
pcaversaccio / recoverooor.vy
Last active June 3, 2025 13:33
Multi-Token Recovery Contract
# pragma version ~=0.4.2
# pragma nonreentrancy off
"""
@title Multi-Token Recovery Contract
@custom:contract-name recoverooor
@license GNU Affero General Public License v3.0 only
@author pcaversaccio
@notice These functions support (batch) recovery of both native assets
and tokens across any standard (e.g., ERC-20, ERC-721, ERC-1155).
When using EIP-7702 (https://eips.ethereum.org/EIPS/eip-7702),
@pcaversaccio
pcaversaccio / patch_safe_hashes.sh
Created April 30, 2025 17:56
Patch `safe_hashes.sh` script API URLs.
#!/usr/bin/env bash
##########################################
# Patch `safe_hashes.sh` Script API URLs #
##########################################
# @license GNU Affero General Public License v3.0 only
# @author pcaversaccio
# This Bash script modifies the default `safe_hashes.sh` script by
@pcaversaccio
pcaversaccio / block_hash_oracle.vy
Last active May 8, 2025 15:53
Historical block hashes oracle Vyper contract.
# pragma version ~=0.4.1
"""
@title Historical Block Hashes Oracle
@custom:contract-name block_hash_oracle
@license GNU Affero General Public License v3.0 only
@author pcaversaccio
@notice The contract function `block_hash` can be used to access the
historical block hashes beyond the default 256-block limit.
We use the EIP-2935 (https://eips.ethereum.org/EIPS/eip-2935)
history contract, which maintains a ring buffer of the last
@pcaversaccio
pcaversaccio / jsonify.sh
Last active April 30, 2025 18:58
A Bash wrapper to save the output of `./safe_hashes.sh` as a JSON file.
#!/usr/bin/env bash
while [[ "$#" -gt 0 ]]; do
case $1 in
--network)
network="$2"
shift
;;
--address)
address="$2"
@pcaversaccio
pcaversaccio / createx.vy
Last active March 28, 2025 23:05
`CREATE`, `CREATE2`, and `CREATE3` Vyper utility functions.
# pragma version ~=0.4.2
"""
@title `CREATE`, `CREATE2`, and `CREATE3` Utility Functions
@license GNU Affero General Public License v3.0 only
@author pcaversaccio
"""
PROXY_CHILD_BYTECODE: constant(Bytes[16]) = x"67363d3d37363d34f03d5260086018f3"
@pcaversaccio
pcaversaccio / Reentrancy.md
Last active March 13, 2025 14:03
Reentrancy for Solidity built-in functions `transfer` and `send`.

Reentrancy for Solidity Built-in Functions transfer and send

I only show this here for transfer, but it also applies to send.

// SPDX-License-Identifier: WTFPL
pragma solidity 0.8.29;

contract Victim {
    mapping(address account => uint256 balances) public balances;
@pcaversaccio
pcaversaccio / eth_to_tron.py
Created February 22, 2025 12:36
Generate a Tron address from an Ethereum hex address.
import base58
import hashlib
def eth_to_tron(eth_address):
eth_address_bytes = bytes.fromhex(
eth_address[2:] if eth_address.startswith("0x") else eth_address
)
tron_address_bytes = b"\x41" + eth_address_bytes
checksum = hashlib.sha256(hashlib.sha256(tron_address_bytes).digest()).digest()[:4]
@pcaversaccio
pcaversaccio / transform.py
Last active February 22, 2025 12:37
Generate a Tron address from `bytes` input.
import hashlib
def base58_encode(data: bytes) -> str:
alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
value = int.from_bytes(data, "big")
result = []
while value:
value, remainder = divmod(value, 58)
@pcaversaccio
pcaversaccio / erc4626_fees_mock.vy
Last active July 15, 2024 08:37
An illustrative `erc4626_fees` module reference implementation. I have coded this in ~30mins. It's completely untested code, so please be careful!
# pragma version ~=0.4.0rc5
"""
@title `erc4626_fees` Module Reference Implementation
@custom:contract-name erc4626_fees_mock
@license GNU Affero General Public License v3.0 only
@author pcaversaccio
@custom:security I have coded this in ~30mins. It's completely
untested code, so please be careful!
"""