Skip to content

Instantly share code, notes, and snippets.

View drgorillamd's full-sized avatar

Simon Something </DrGoNoGo> drgorillamd

View GitHub Profile
@drgorillamd
drgorillamd / test.sol
Created September 2, 2024 15:29
var instantiation once or in a loop?
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;
import {Test, console} from "forge-std/Test.sol";
// Ran 2 tests for test/Counter.t copy 2.sol:VarCreation
// [PASS] test_test1() (gas: 18480)
// [PASS] test_test2() (gas: 18320)
contract VarCreation is Test {
@drgorillamd
drgorillamd / test.sol
Created September 2, 2024 15:19
calldata array length cached or nah?
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;
import {Test, console} from "forge-std/Test.sol";
// Ran 2 tests for test/Counter.t copy.sol:LenCalldata
// [PASS] test_test1() (gas: 15999)
// [PASS] test_test2() (gas: 15979)
contract LenCalldata is Test {
@drgorillamd
drgorillamd / test.sol
Created September 2, 2024 15:13
mapping key creation vs solc
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;
import {Test, console} from "forge-std/Test.sol";
// Ran 6 tests for test/Counter.t.sol:CounterTest
// [PASS] test_test1E2E(uint256) (runs: 258, μ: 31839, ~: 31839)
// [PASS] test_test1Set() (gas: 27750)
// [PASS] test_test1Test() (gas: 28762)
// [PASS] test_test2E2E(uint256) (runs: 258, μ: 31631, ~: 31631)
@drgorillamd
drgorillamd / ctf.sol
Created June 20, 2024 12:58
branchless in assembly in a long forgotten ctf (2y ago?)
// SPDX-License-Identifier: None
pragma solidity ^0.8.17;
import { Test } from "forge-std/Test.sol";
import { Gate, IGuardian } from "../src/Gate.sol";
/**
* @title Answer to the Gate Challenge
*
* @notice The logic summarized is, for every calls to guardian, the following
@drgorillamd
drgorillamd / Nonce.t.sol
Last active June 19, 2024 11:22
contract nonce if revert
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
import {Test} from 'forge-std/Test.sol';
contract DeployRevert {
constructor() {
revert("DeployRevert");
}
}
@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;