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 / to_checksum_name.py
Last active June 15, 2023 09:10
A Python script that converts a function name into a name convention based on a checksum approach.
from re import sub
from eth_utils import keccak
from caseconverter import camelcase, flatcase, macrocase, pascalcase, snakecase
"""
Biased Assumption: Every single word of an interface function, event or custom error definition,
or anything else contained in an interface definition and used as an identifier, is capitalised
and concatenated with an underscore before running `to_checksum_name`.
Examples: `TRANSFER_FROM`, `BALANCE_OF`, `$I_HATE_PHP`.
@pcaversaccio
pcaversaccio / bootnodes.txt
Last active May 4, 2023 10:52
An overview of the current IPs and locations of the CL bootnodes.
# CL mainnet bootnodes: https://github.com/eth-clients/eth2-networks/blob/master/shared/mainnet/bootstrap_nodes.txt.
### ENR
# Teku team's bootnodes
enr:-KG4QOtcP9X1FbIMOe17QNMKqDxCpm14jcX5tiOE4_TyMrFqbmhPZHK_ZPG2Gxb1GE2xdtodOfx9-cgvNtxnRyHEmC0ghGV0aDKQ9aX9QgAAAAD__________4JpZIJ2NIJpcIQDE8KdiXNlY3AyNTZrMaEDhpehBDbZjM_L9ek699Y7vhUJ-eAdMyQW_Fil522Y0fODdGNwgiMog3VkcIIjKA
enr:-KG4QL-eqFoHy0cI31THvtZjpYUu_Jdw_MO7skQRJxY1g5HTN1A0epPCU6vi0gLGUgrzpU-ygeMSS8ewVxDpKfYmxMMGhGV0aDKQtTA_KgAAAAD__________4JpZIJ2NIJpcIQ2_DUbiXNlY3AyNTZrMaED8GJ2vzUqgL6-KD1xalo1CsmY4X1HaDnyl6Y_WayCo9GDdGNwgiMog3VkcIIjKA
# Prylab team's bootnodes
enr:-Ku4QImhMc1z8yCiNJ1TyUxdcfNucje3BGwEHzodEZUan8PherEo4sF7pPHPSIB1NNuSg5fZy7qFsjmUKs2ea1Whi0EBh2F0dG5ldHOIAAAAAAAAAACEZXRoMpD1pf1CAAAAAP__________gmlkgnY0gmlwhBLf22SJc2VjcDI1NmsxoQOVphkDqal4QzPMksc5wnpuC3gvSC8AfbFOnZY_On34wIN1ZHCCIyg
@pcaversaccio
pcaversaccio / isqrt.ipynb
Last active April 30, 2023 15:42
Example Jupyter Notebook using https://try.vyperlang.org.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pcaversaccio
pcaversaccio / ReadNestedStruct.sol
Created April 24, 2023 16:33
Access nested struct withing Solidity.
// SPDX-License-Identifier: WTFPL
pragma solidity ^0.8.19;
contract NestedStruct {
struct Inside {
address a1;
address a2;
address a3;
}
@pcaversaccio
pcaversaccio / Unreachable.sol
Created April 24, 2023 12:48
Always remember that `address(this).balance` includes also `msg.value` of the current transaction.
// SPDX-License-Identifier: WTFPL
pragma solidity ^0.8.19;
contract TryToReachMe {
constructor() payable {
assert(msg.value == 1 wei);
}
function tryMeBabe(address addr) public payable {
uint256 balance = address(this).balance;
@pcaversaccio
pcaversaccio / Reentrancy.sol
Created April 20, 2023 14:55
A simple Solidity contract that entails a reentrancy attack vector.
// SPDX-License-Identifier: WTFPL
pragma solidity 0.8.19;
contract Victim {
mapping(address => uint256) public balanceOf;
function deposit() external payable {
balanceOf[msg.sender] += msg.value;
}
@pcaversaccio
pcaversaccio / Codesize.sol
Last active April 21, 2023 22:57
A Solidity snippet showing that `CODESIZE` returns the size of the called code (i.e. the implementation contract) when called via `DELEGATECALL`, rather than the size of the delegating contract.
// SPDX-License-Identifier: WTFPL
pragma solidity 0.8.19;
contract A {
/**
* @dev Returns 118 for contract `A`.
*/
function codesize() external pure returns (uint256 code) {
// solhint-disable-next-line no-inline-assembly
assembly {
@pcaversaccio
pcaversaccio / ManaTesting.sol
Created April 15, 2023 10:32
A Solidity contract to estimate the used mana via the `manaleft()` syntax for dedicated function calls.
// SPDX-License-Identifier: WTFPL
pragma solidity ^0.8.19;
contract ManaTesting {
function test_iWeak() public view returns (uint256 manaUsed) {
uint256 startMana = manaleft();
uint256 i = 0;
i++;
manaUsed = startMana - manaleft();
}
@pcaversaccio
pcaversaccio / WERC721.sol
Last active February 10, 2023 15:49
A simple wrapped ERC-721 token. Do not trust this code unless you want to test it in prod.
// SPDX-License-Identifier: WTFPL
pragma solidity 0.8.18;
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
/**
* @dev Error that occurs when an unauthorised transfer is triggered.
@pcaversaccio
pcaversaccio / TxOriginMsgSenderTest.sol
Last active February 8, 2023 15:15
A contract that highlights the difference in behaviour between `CALL` and `DELEGATECALL` in relation to `tx.origin` and `msg.sender`.
// SPDX-License-Identifier: WTPFL
pragma solidity 0.8.18;
contract Called {
function callMe() external view returns (address) {
// solhint-disable-next-line avoid-tx-origin
assert(tx.origin == msg.sender);
return msg.sender;
}
}