Skip to content

Instantly share code, notes, and snippets.

View ylv-io's full-sized avatar
🤑
Building Internet Money

Igor Yalovoy ylv-io

🤑
Building Internet Money
View GitHub Profile
@ylv-io
ylv-io / read-storage.sol
Created July 2, 2023 18:27
External Storage Read
function extsload(bytes32 slot) external view returns (bytes32 value) {
/// @solidity memory-safe-assembly
assembly {
value := sload(slot)
}
}
function extsload(bytes32 startSlot, uint256 nSlots) external view returns (bytes memory) {
bytes memory value = new bytes(32 * nSlots);
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.1;
/**
* @title NoMevProxy
* @dev Invokes a staticcall to an address from OFAC list to block MEV
*/
contract NoMevProxy {
address immutable implementation;
@ylv-io
ylv-io / ShutUpAndTakeMyMoney.sol
Created August 8, 2022 12:40
Force a smart contract to receive ETH
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.1;
/**
* @title ShutUpAndTakeMyMoney
* @dev Force target to accept msg.value amount of ETH
* https://docs.soliditylang.org/en/v0.8.13/introduction-to-smart-contracts.html?highlight=selfdestruct#deactivate-and-self-destruct
*/
contract ShutUpAndTakeMyMoney {
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v4.3/contracts/access/Ownable.sol";
pragma solidity 0.8.0;
contract StorageBug is Ownable {
function write() onlyOwner external {
uint256[] storage arr;
arr.push(1);
}
/**
* Can't await on transactionSend because it will never resolve due to
* automine disabled. Save a promise instead and resolve it later.
* Should set gasLimit on txs because default gasLimit is blockGasLimit.
* promise = signer.sendTransaction({
* to: signer.address,
* value: 1,
* });
* const txReceipt = await promise;
* @param {func} Lambda to run within the same block.
const { expect } = require('chai');
const { ethers } = require('hardhat');
const { ONE_DAY_IN_SECONDS } = require('../../utils/constants');
const { increaseTime, getTimestamp, mineInBlock } = require('./test-helpers');
describe('Test Helpers', function () {
beforeEach(async () => {});
it.only('can mine multiple transactions within the same block', async function () {
@ylv-io
ylv-io / test-helpers.js
Created April 20, 2021 17:08
HardHat Test Helpers
const { ethers } = require('hardhat');
/**
* Advance blockchain time by value. Has a random chance to deviate by 1 second.
* Consider this during tests. Use `closeTo`.
* @param {number} value - Amount of time to advance time by.
*/
async function increaseTime(value) {
if (!ethers.BigNumber.isBigNumber(value)) {
value = ethers.BigNumber.from(value);
pragma solidity ^0.5.0;
contract Fomo3d {
address public winner;
bool public gameover;
function win(address contender) public {
winner = contender;
}
}
(![] + [])[+[]] +
(![] + [])[+!+[]] +
([![]] + [][[]])[+!+[] + [+[]]] +
(![] + [])[!+[] + !+[]];
import { cache } from './patch';
const stub = sinon.stub(cache, 'lib');