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 / 4e2b890ab80095ee8fe286920b86039c.json
Last active September 27, 2022 19:29
Hardhat build artifact for BatchDistributor.
{"id":"4e2b890ab80095ee8fe286920b86039c","_format":"hh-sol-build-info-1","solcVersion":"0.8.17","solcLongVersion":"0.8.17+commit.8df45f5f","input":{"language":"Solidity","sources":{"contracts/BatchDistributor.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity 0.8.17;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\n\n/**\n * @dev Error that occurs when transferring ether has failed.\n * @param emitter The contract that emits the error.\n */\nerror EtherTransferFail(address emitter);\n\n/**\n * @title Native and ERC-20 Token Batch Distributor\n * @author Apps with love AG, [email protected]\n * @notice Helper smart contract for batch sending both\n * native and ERC-20 tokens.\n * @dev Since we use nested struct objects, we rely on the ABI coder v2.\n * The ABI coder v2 is activated by default since Solidity `v0.8.0`.\n * @custom:security-contact [email protected]\n */\n\ncontract BatchDistributor {\n us
@pcaversaccio
pcaversaccio / Storage.sol
Created September 29, 2022 14:34
Struct writing (memory vs. storage) comparison.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
contract Storage {
struct SomeStruct {
uint16 a;
uint16 b;
uint16 c;
uint16 d;
}
@pcaversaccio
pcaversaccio / ReturnBombExample.sol
Last active January 7, 2025 16:03
This is a returnbomb attack example.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
/**
* @title Returnbomb attack example
* @author pcaversaccio
*/
contract Evil {
uint256 public counter;
@pcaversaccio
pcaversaccio / 0x732e9b5f59C9A442Db18F7D57Dd2BBFC804281CB.txt
Last active September 17, 2023 14:00
Decompiled contract 0x732e9b5f59C9A442Db18F7D57Dd2BBFC804281CB. I used the Dedaub Decompiler (https://library.dedaub.com/decompile).
// Decompiled by library.dedaub.com
// 2022.11.28 11:00 UTC
// Data structures and variables inferred from the use of storage instructions
uint256 owner_0_0_19; // STORAGE[0x0] bytes 0 to 19
uint256 owner_1_0_19; // STORAGE[0x1] bytes 0 to 19
function () public payable {
revert();
@pcaversaccio
pcaversaccio / StringEncodingReturnData.sol
Created December 16, 2022 16:04
A simple Solidity PoC contract to showcase how revert strings are ABI encoded.
// SPDX-License-Identifier: WTFPL
pragma solidity 0.8.17;
/**
* @dev A simple contract that reverts.
*/
contract Revert {
function revertWithoutReason() external pure {
// solhint-disable-next-line reason-string
revert();
@pcaversaccio
pcaversaccio / AddressHashing.sol
Last active December 23, 2022 05:45
Solidity and 🐍Vyper hashing versions for building an address-based Merkle tree.
/**
* @dev Solidity version for standard pack mode.
*/
function hashAddr(address addr) external pure returns (bytes32) {
/**
* @dev The function `keccak256` hashes `0x000000000000000000000000+addr`.
* Remember that one EVM word is 32 bytes and Ethereum addresses are 20 bytes long.
*/
return keccak256(abi.encode(addr));
}
@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;
}
}
@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 / 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 / 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 {