Skip to content

Instantly share code, notes, and snippets.

View drgorillamd's full-sized avatar

Dr. GoNoGo [Gorilla_md] drgorillamd

View GitHub Profile
@drgorillamd
drgorillamd / A.sol
Created February 28, 2024 08:09
internal function pointer
// SPDX-License-Identifier: GPL-3.0
// no optimization
pragma solidity 0.8.19;
contract A {
event Log(string bleh);
// Pass an arbitrary bytecode offset, then make it a fn pointer and call it
function callme(bytes32 _offset) external {
@drgorillamd
drgorillamd / test.sol
Created March 17, 2023 08:35
Quick gas comparison between multiple ways to access struct elements stored in a single word
pragma solidity 0.8.16;
// optim 200 runs
contract Test { //27038
struct StructA {
uint128 _a;
uint128 _b;
}
StructA structA;

Keybase proof

I hereby claim:

  • I am drgorillamd on github.
  • I am drgorilla_md (https://keybase.io/drgorilla_md) on keybase.
  • I have a public key ASDSuXEe25NwE38lIIjbDUrB4KvUupKF6LcnYkEcqyCoWQo

To claim this, I am signing this object:

@drgorillamd
drgorillamd / test.sol
Created April 28, 2022 13:59
Cost difference of delegatecall with returned value or mutex
pragma solidity 0.8.7;
interface IE {
function setN() external;
}
contract D {
uint public n;
uint private temp;
@drgorillamd
drgorillamd / craft.js
Created January 19, 2022 10:03
Craft tx
const ethers = require('ethers');
const { Interface } = require('ethers/lib/utils');
const contractAddress = '';
const key = '';
const RPC_SERVER = '';
async function main () {
try {
const provider = new ethers.providers.JsonRpcProvider(RPC_SERVER);
@drgorillamd
drgorillamd / destroy.sol
Created December 8, 2021 13:23
'selfdestruct but still working'
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract Caller {
uint256 flag = 0;
event InsideBeforeDelegate();
event InsideAfterDelegate();
event OutsideAfterAllWtf();
@drgorillamd
drgorillamd / test.sol
Created November 13, 2021 14:29
decompose bytes32,bytes32,bytes16 to address
pragma solidity ^0.8.0;
contract Test {
function a(bytes32 c, bytes32 d, bytes16 e) external view returns(address[4] memory res) {
assembly {
//address will take the right-end 20 bytes -> starting at 0, need to add 8 bytes of padding (already 4 from the function sig) => shift right 64bits
mstore(res, shr(64, calldataload(0))) //res[0] res==keccak256(0)==0 here (slot0)
mstore(add(res, 32), calldataload(12)) // we want to have the offset 12 bytes before the begining of the address -> 4+20 are just before, then -12 = 12
mstore(add(res, 64), calldataload(32))
@drgorillamd
drgorillamd / tryHard.sol
Created November 12, 2021 20:40
delegatecall & custom error
pragma solidity "0.8.7";
contract CallMeAndIRevert {
error ErrorA(); // 0x5283ed77
error ErrorB(); // 0x8a25c831
function triggerErrorAorB() external {
if(block.timestamp % 2 == 0) revert ErrorA();
else revert ErrorB();
}
}