Skip to content

Halve gas used by SafetyChecker#210

Merged
K-Ho merged 1 commit intoethereum-optimism:masterfrom
geohot:safetychecker_gas
Aug 11, 2020
Merged

Halve gas used by SafetyChecker#210
K-Ho merged 1 commit intoethereum-optimism:masterfrom
geohot:safetychecker_gas

Conversation

@geohot
Copy link
Contributor

@geohot geohot commented Aug 11, 2020

  • Replace ops array with a uint256
  • Replace 2 ** op with 1 << op
  • Add a fast outer opcode check to the list of if statements

Running tests now (they pass), shouldn't change any functionality, and uses about 40% of previous gas. There's more possible, but this is the low hanging fruit, closes #209

Copy link
Contributor

@K-Ho K-Ho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Curious about your thoughts w.r.t gas savings by removing all of the "seenJump" logic

// we are now inside unreachable code until we hit a JUMPDEST!
insideUnreachableCode = true;
// STOP or REVERT or INVALID or RETURN (see safety checker docs in wiki for more info)
} else if (op == 0x00 || op == 0xfd || op == 0xfe || op == 0xf3) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be cheaper to also do an opBit & mask != 0 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it's diminishing returns since it's already gated outside.

// JUMP
} else if (op == 0x56) {
// We can now reach all JUMPDESTs
seenJUMP = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that I think about it, we can just assume that we've seen a JUMP. I doubt we'll ever have a case where we reach a halting opcode before seeing a JUMP (no need to update this in this PR, but curious about your thoughts)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meh, personally I'd remove this logic. It's safer the other way, never allow something you don't expect.

Comment on lines +110 to +111
if (!seenJUMP) {
return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See JUMP comment above

@K-Ho K-Ho merged commit 7f98970 into ethereum-optimism:master Aug 11, 2020
protolambda added a commit to protolambda/optimism that referenced this pull request May 1, 2022
…lete_code_v2

ref impl: Source and Driver Cleanup
Lredhdx pushed a commit to node-real/combo-optimism that referenced this pull request Jun 17, 2024
bap2pecs pushed a commit to babylonlabs-io/optimism that referenced this pull request Jul 31, 2024
theochap pushed a commit that referenced this pull request Dec 10, 2025
* feat(client): `StatelessL2BlockExecutor`

Implements the `StatelessL2BlockExecutor`, capable of executing
`L2PayloadAttributes` and returning the block header + receipts.

The `StatelessL2BlockExecutor` is backed by the `TrieDB` in the
`kona-mpt` crate, fetching necessary data from the initial state root as
well as the starting parent block hash.

* fix(client): Trie fixes, etc.

x

trim test files

* big block testin'

* checkpoint: big block works

* checkpoint

dep reordering

* cleanups

* more tests
Zena-park added a commit to tokamak-network/optimism that referenced this pull request Dec 30, 2025
theochap pushed a commit that referenced this pull request Jan 15, 2026
### Description

Introduces a meta crate like `alloy` that re-exports all `op-alloy-*`
crates behind respective feature flags.
emhane pushed a commit that referenced this pull request Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reduce gas usage of SafetyChecker

2 participants