Skip to content

Instantly share code, notes, and snippets.

@hrkrshnn
Last active October 10, 2022 14:42
Show Gist options
  • Save hrkrshnn/84d2a9686a88ea355749dec2a5987ee9 to your computer and use it in GitHub Desktop.
Save hrkrshnn/84d2a9686a88ea355749dec2a5987ee9 to your computer and use it in GitHub Desktop.
Run by `solc --strict-assembly --optimize --ir-optimized`. Context: https://twitter.com/NoahZinsmeister/status/1499845282598731782 Need to use Yul, since there is no `verbatim` in Solidity's inline assembly.
// UNTESTED!
object "BribeContract" {
code {
let size := datasize("BribeRuntime")
codecopy(0, dataoffset("BribeRuntime"), size)
return(0, size)
}
object "BribeRuntime" {
code {
// Bribe by sending ETH. To try and claim, send a tx without ETH. Assumes that a tx with
// ETH attached is not necessary for claiming
if callvalue() {
stop()
}
// Address that will receive ETH!
let bribe_addr := 0x123
// Add the opcodes along with the inputs (you may add tests for the output as well). If
// any of the opcodes does not exist right now, the execution should revert in an invalid
// state.
verbatim_0i_0o(hex"12345678")
let success := call(gas(), bribe_addr, selfbalance(), 0, 0, 0, 0)
if iszero(success) {
revert(0, 0)
}
stop()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment