Skip to main content
for correctly returning only the 4bytes or custom error selector which is stored left padded in 0 slot of memory the offset should change from 0x00 to 0x1c
Source Link
function f() external {
    // revert MyError();
    bytes4 errorSelector = this.MyError.selector;
    assembly {
        mstore(0, errorSelector)
        revert(00x1c, 40x04)
    }
}

function f() external {
    // revert MyErrorWithValue(555);
    bytes4 errorSelector = this.MyErrorWithValue.selector;
    assembly {
        mstore(0, errorSelector)
        mstore(4, 555)
        revert(00x1c, 0x24)
    }
}

function h() external {
    // revert MyErrorWithValues(555, 666);
    bytes4 errorSelector = this.MyErrorWithTwoValues.selector;
    assembly {
        let ptr := mload(0x40)
        mstore(ptr, errorSelector)
        mstore(add(ptr, 0x04), 555)
        mstore(add(ptr, 0x24), 666)
        revert(add(ptr, 0x1c), 0x44)
    }
}
function f() external {
    // revert MyError();
    bytes4 errorSelector = this.MyError.selector;
    assembly {
        mstore(0, errorSelector)
        revert(0, 4)
    }
}

function f() external {
    // revert MyErrorWithValue(555);
    bytes4 errorSelector = this.MyErrorWithValue.selector;
    assembly {
        mstore(0, errorSelector)
        mstore(4, 555)
        revert(0, 0x24)
    }
}

function h() external {
    // revert MyErrorWithValues(555, 666);
    bytes4 errorSelector = this.MyErrorWithTwoValues.selector;
    assembly {
        let ptr := mload(0x40)
        mstore(ptr, errorSelector)
        mstore(add(ptr, 0x04), 555)
        mstore(add(ptr, 0x24), 666)
        revert(ptr, 0x44)
    }
}
function f() external {
    // revert MyError();
    bytes4 errorSelector = this.MyError.selector;
    assembly {
        mstore(0, errorSelector)
        revert(0x1c, 0x04)
    }
}

function f() external {
    // revert MyErrorWithValue(555);
    bytes4 errorSelector = this.MyErrorWithValue.selector;
    assembly {
        mstore(0, errorSelector)
        mstore(4, 555)
        revert(0x1c, 0x24)
    }
}

function h() external {
    // revert MyErrorWithValues(555, 666);
    bytes4 errorSelector = this.MyErrorWithTwoValues.selector;
    assembly {
        let ptr := mload(0x40)
        mstore(ptr, errorSelector)
        mstore(add(ptr, 0x04), 555)
        mstore(add(ptr, 0x24), 666)
        revert(add(ptr, 0x1c), 0x44)
    }
}
added 62 characters in body
Source Link
k06a
  • 3.1k
  • 2
  • 22
  • 35
let ptr := mload(0x40) // Get free memory pointer
mstore(ptr, 0x08c379a00x08c379a000000000000000000000000000000000000000000000000000000000000000) // Selector for method Error(string)
mstore(add(ptr, 0x04), 0x20) // String offset
mstore(add(ptr, 0x24), 30) // Revert reason length
mstore(add(ptr, 0x44), "Amount to raise smaller than 0")
revert(ptr, 0x64) // Revert data length is 4 bytes for selector and 3 slots of 0x20 bytes
function f() external {
    // revert MyError();
    bytes4 errorSelector = this.MyError.selector;
    assembly {
        mstore(0, errorSelector)
        revert(0, 4)
    }
}

function f() external {
    // revert MyErrorWithValue(555);
    bytes4 errorSelector = this.MyErrorWithValue.selector;
    assembly {
        mstore(0, errorSelector)
        mstore(4, 555)
        revert(0, 0x24)
    }
}

function h() external {
    // revert MyErrorWithValues(555, 666);
    bytes4 errorSelector = this.MyErrorWithTwoValues.selector;
    assembly {
        let ptr := mload(0x40)
        mstore(ptr, errorSelector)
        mstore(add(ptr, 0x04), 555)
        mstore(add(ptr, 0x24), 666)
        revert(0ptr, 0x44)
    }
}
let ptr := mload(0x40) // Get free memory pointer
mstore(ptr, 0x08c379a0) // Selector for method Error(string)
mstore(add(ptr, 0x04), 0x20) // String offset
mstore(add(ptr, 0x24), 30) // Revert reason length
mstore(add(ptr, 0x44), "Amount to raise smaller than 0")
revert(ptr, 0x64) // Revert data length is 4 bytes for selector and 3 slots of 0x20 bytes
function f() external {
    // revert MyError();
    bytes4 errorSelector = this.MyError.selector;
    assembly {
        mstore(0, errorSelector)
        revert(0, 4)
    }
}

function f() external {
    // revert MyErrorWithValue(555);
    bytes4 errorSelector = this.MyErrorWithValue.selector;
    assembly {
        mstore(0, errorSelector)
        mstore(4, 555)
        revert(0, 0x24)
    }
}

function h() external {
    // revert MyErrorWithValues(555, 666);
    bytes4 errorSelector = this.MyErrorWithTwoValues.selector;
    assembly {
        let ptr := mload(0x40)
        mstore(ptr, errorSelector)
        mstore(add(ptr, 0x04), 555)
        mstore(add(ptr, 0x24), 666)
        revert(0, 0x44)
    }
}
let ptr := mload(0x40) // Get free memory pointer
mstore(ptr, 0x08c379a000000000000000000000000000000000000000000000000000000000000000) // Selector for method Error(string)
mstore(add(ptr, 0x04), 0x20) // String offset
mstore(add(ptr, 0x24), 30) // Revert reason length
mstore(add(ptr, 0x44), "Amount to raise smaller than 0")
revert(ptr, 0x64) // Revert data length is 4 bytes for selector and 3 slots of 0x20 bytes
function f() external {
    // revert MyError();
    bytes4 errorSelector = this.MyError.selector;
    assembly {
        mstore(0, errorSelector)
        revert(0, 4)
    }
}

function f() external {
    // revert MyErrorWithValue(555);
    bytes4 errorSelector = this.MyErrorWithValue.selector;
    assembly {
        mstore(0, errorSelector)
        mstore(4, 555)
        revert(0, 0x24)
    }
}

function h() external {
    // revert MyErrorWithValues(555, 666);
    bytes4 errorSelector = this.MyErrorWithTwoValues.selector;
    assembly {
        let ptr := mload(0x40)
        mstore(ptr, errorSelector)
        mstore(add(ptr, 0x04), 555)
        mstore(add(ptr, 0x24), 666)
        revert(ptr, 0x44)
    }
}
added 77 characters in body
Source Link
k06a
  • 3.1k
  • 2
  • 22
  • 35
let ptr := mload(0x40) // Get free memory pointer
mstore(ptr, 0x08c379a0) // Selector for method Error(string)
mstore(add(ptr, 0x04), 0x20) // String offset
mstore(add(ptr, 0x24), 30) // Revert reason length
mstore(add(ptr, 0x44), "Amount to raise smaller than 0")
revert(ptr, 0x64) // Revert data length is 4 bytes for selector and 3 slots of 0x20 bytes
contract Foo {
    error MyError();
    error MyErrorWithValue(uint256);
    error MyErrorWithTwoValues(uint256, uint256);

    function f() external {
        revert MyError();
    }

    function g() external {
        revert MyErrorWithValue(555);
    }

    function h() external {
        revert MyErrorWithValueMyErrorWithTwoValues(555, 666);
    }
}
function f() external {
    // revert MyError();
    bytes4 errorSelector = this.MyError.selector;
    assembly {
        mstore(0, errorSelector)
        revert(0, 4)
    }
}

function f() external {
    // revert MyErrorWithValue(555);
    bytes4 errorSelector = this.MyErrorWithValue.selector;
    assembly {
        mstore(0, errorSelector)
        mstore(4, 555)
        revert(0, 0x24)
    }
}

function h() external {
    // revert MyErrorWithValueMyErrorWithValues(555, 666);
    bytes4 errorSelector = this.MyErrorWithTwoValues.selector;
    assembly {
        let ptr := mload(0x40)
        mstore(ptr, errorSelector)
        mstore(add(ptr, 0x04), 555)
        mstore(add(ptr, 0x24), 666)
        revert(0, 0x44)
    }
}
let ptr := mload(0x40) // Get free memory pointer
mstore(ptr, 0x08c379a0) // Selector for method Error(string)
mstore(add(ptr, 0x04), 0x20) // String offset
mstore(add(ptr, 0x24), 30) // Revert reason length
mstore(add(ptr, 0x44), "Amount to raise smaller than 0")
revert(ptr, 0x64)
contract Foo {
    error MyError();
    error MyErrorWithValue(uint256);
    error MyErrorWithTwoValues(uint256, uint256);

    function f() external {
        revert MyError();
    }

    function g() external {
        revert MyErrorWithValue(555);
    }

    function h() external {
        revert MyErrorWithValue(555, 666);
    }
}
function f() external {
    // revert MyError();
    bytes4 errorSelector = this.MyError.selector;
    assembly {
        mstore(0, errorSelector)
        revert(0, 4)
    }
}

function f() external {
    // revert MyErrorWithValue(555);
    bytes4 errorSelector = this.MyErrorWithValue.selector;
    assembly {
        mstore(0, errorSelector)
        mstore(4, 555)
        revert(0, 0x24)
    }
}

function h() external {
    // revert MyErrorWithValue(555, 666);
    bytes4 errorSelector = this.MyErrorWithTwoValues.selector;
    assembly {
        let ptr := mload(0x40)
        mstore(ptr, errorSelector)
        mstore(add(ptr, 0x04), 555)
        mstore(add(ptr, 0x24), 666)
        revert(0, 0x44)
    }
}
let ptr := mload(0x40) // Get free memory pointer
mstore(ptr, 0x08c379a0) // Selector for method Error(string)
mstore(add(ptr, 0x04), 0x20) // String offset
mstore(add(ptr, 0x24), 30) // Revert reason length
mstore(add(ptr, 0x44), "Amount to raise smaller than 0")
revert(ptr, 0x64) // Revert data length is 4 bytes for selector and 3 slots of 0x20 bytes
contract Foo {
    error MyError();
    error MyErrorWithValue(uint256);
    error MyErrorWithTwoValues(uint256, uint256);

    function f() external {
        revert MyError();
    }

    function g() external {
        revert MyErrorWithValue(555);
    }

    function h() external {
        revert MyErrorWithTwoValues(555, 666);
    }
}
function f() external {
    // revert MyError();
    bytes4 errorSelector = this.MyError.selector;
    assembly {
        mstore(0, errorSelector)
        revert(0, 4)
    }
}

function f() external {
    // revert MyErrorWithValue(555);
    bytes4 errorSelector = this.MyErrorWithValue.selector;
    assembly {
        mstore(0, errorSelector)
        mstore(4, 555)
        revert(0, 0x24)
    }
}

function h() external {
    // revert MyErrorWithValues(555, 666);
    bytes4 errorSelector = this.MyErrorWithTwoValues.selector;
    assembly {
        let ptr := mload(0x40)
        mstore(ptr, errorSelector)
        mstore(add(ptr, 0x04), 555)
        mstore(add(ptr, 0x24), 666)
        revert(0, 0x44)
    }
}
Source Link
k06a
  • 3.1k
  • 2
  • 22
  • 35
Loading