Skip to content

Conversation

@charles-cooper
Copy link
Contributor

Summary

  • Implement ASSERT and ASSERT_UNREACHABLE opcode semantics
  • Add execution context types (call_context, tx_context, block_context) to venom_state
  • Implement ~30 environment/calldata/hashing opcodes that compile to EVM

Opcodes Implemented

Assertions:

  • ASSERT: revert if condition is zero
  • ASSERT_UNREACHABLE: halt if condition is non-zero

Environment:

  • CALLER, ADDRESS, CALLVALUE, GAS
  • ORIGIN, GASPRICE, CHAINID
  • COINBASE, TIMESTAMP, NUMBER, PREVRANDAO, GASLIMIT, BASEFEE, BLOBBASEFEE, BLOCKHASH
  • BALANCE, SELFBALANCE

Calldata/Returndata:

  • CALLDATASIZE, CALLDATALOAD, CALLDATACOPY
  • RETURNDATASIZE, RETURNDATACOPY
  • MSIZE

Hashing:

  • SHA3 (Keccak256 on memory region)
  • SHA3_64 (Keccak256 on two words - Vyper optimization)

Not Implemented

External calls (CALL, STATICCALL, DELEGATECALL) are left as "unimplemented opcode" errors for now.

Test plan

  • Holmake builds successfully

🤖 Generated with Claude Code

Implement semantics for many Venom IR opcodes that compile to EVM:

Assertions:
- ASSERT: revert if condition is zero
- ASSERT_UNREACHABLE: halt if condition is non-zero

Environment context (new state fields):
- call_context: caller, address, callvalue, calldata, gas
- tx_context: origin, gasprice, chainid
- block_context: coinbase, timestamp, number, prevrandao, gaslimit,
  basefee, blobbasefee, blockhash

Environment opcodes:
- CALLER, ADDRESS, CALLVALUE, GAS
- ORIGIN, GASPRICE, CHAINID
- COINBASE, TIMESTAMP, NUMBER, PREVRANDAO, GASLIMIT, BASEFEE,
  BLOBBASEFEE, BLOCKHASH
- BALANCE, SELFBALANCE

Calldata/returndata:
- CALLDATASIZE, CALLDATALOAD, CALLDATACOPY
- RETURNDATASIZE, RETURNDATACOPY
- MSIZE

Hashing (using Keccak from HOL4):
- SHA3: Keccak256 on memory region
- SHA3_64: Keccak256 on two words (Vyper optimization)

External calls (CALL, STATICCALL, DELEGATECALL) are left unimplemented
for now - they error out.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
let dest = w2n destOffset in
let mem = s.vs_memory in
let needed = (dest + size) - LENGTH mem in
let expanded = if needed > 0 then mem ++ REPLICATE needed 0w else mem in
Copy link
Member

Choose a reason for hiding this comment

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

we do have expand_memory helpers in verifereum that could possibly be used 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.

I think we should probably just add comments everywhere that verifereum functionality could be used and then do a pass over verifereum to extract helper functions for each opcode, then revisit this code after that pass

Copy link
Member

Choose a reason for hiding this comment

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

I don't think there are that many other opportunities. Maybe if verifereum were refactored too, but I don't want this to bleed into that for now...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

charles-cooper and others added 4 commits December 26, 2025 21:28
Extract the common pattern of expanding memory then writing bytes
into a reusable helper function write_memory_with_expansion.

Refactor CALLDATACOPY and RETURNDATACOPY to use this helper,
reducing code duplication.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@xrchz xrchz merged commit 93bb01b into main Dec 27, 2025
2 checks passed
@xrchz xrchz deleted the assert-unreachable-semantics branch December 27, 2025 19:35
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.

3 participants