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 / 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!
"""
@pcaversaccio
pcaversaccio / GUIDELINES.md
Last active March 16, 2024 10:34
Guide to get started with Vyper modules.

🐍 How to get started with Vyper modules

1. Create a new, clean testing directory test

mkdir test
cd test

2. Set up pyenv

# pragma version ^0.3.10
"""
@title P256 Signature Verification Function
@custom:contract-name P256Verifier
@license GNU Affero General Public License v3.0 only
@author pcaversaccio
@notice The `verify` function can be used to natively (currently
only supported on Polygon Mumbai test network) verify a
P256 (a.k.a. secp256r1 elliptic curve) signature. For more
technical details, please refer to EIP-7212:
// SPDX-License-Identifier: MIT
// File: @openzeppelin/contracts/math/SafeMath.sol
// Original license: SPDX_License_Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
@pcaversaccio
pcaversaccio / README.md
Last active November 18, 2023 16:52
Set up the vast.ai instance with profanity2 (https://github.com/1inch/profanity2).

Setup

Update Linux

sudo apt update && sudo apt upgrade

Install build-essential Packages

@pcaversaccio
pcaversaccio / compute_create2_address_zksync.vy
Last active May 15, 2024 07:19
Calculate the `CREATE2` address on zkSync using Vyper.
# @version ^0.3.10
_CREATE2_PREFIX: constant(bytes32) = 0x2020dba91b30cc0006188af794c2fb30dd8520db7e2c088b7fc7c103c00ca494
@external
@pure
def compute_create2_address_zksync(salt: bytes32, bytecode_hash: bytes32, deployer: address, input: Bytes[4_096]=b"") -> address:
constructor_input_hash: bytes32 = keccak256(input)
@pcaversaccio
pcaversaccio / ERC2098.vy
Created July 17, 2023 15:41
A Vyper utility function that transforms a standard signature into an EIP-2098 (https://eips.ethereum.org/EIPS/eip-2098) compliant signature.
# @version ^0.3.9
@internal
@pure
def _to_2098_format(signature: Bytes[65]) -> Bytes[64]:
"""
@dev Transforms a standard signature into an EIP-2098
(https://eips.ethereum.org/EIPS/eip-2098) compliant
signature.
@param signature The secp256k1 64/65-bytes signature.