Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Implementation of SLOTNUM support in the solidity syntax, inline assembly and yul. - #16881

#16881
Open
rodiazet wants to merge 1 commit into
developargotorg/solidity:developfrom
slotnumargotorg/solidity:slotnumCopy head branch name to clipboard
Open

Implementation of SLOTNUM support in the solidity syntax, inline assembly and yul.#16881
rodiazet wants to merge 1 commit into
developargotorg/solidity:developfrom
slotnumargotorg/solidity:slotnumCopy head branch name to clipboard

Conversation

@rodiazet

Copy link
Copy Markdown
Contributor

Description

This PR implements support for SLOTNUM opcode in the EVM.
Introduces:

  • new member slotnum in the block global variable on solidity language level
  • builtin slotnum() function in yul and inline assembly
  • reservs slotnum identifier in the yul and inline assembly starting from amsterdam fork.

AI Disclosure

  • No AI tools were used

Claude Code, Anthropic's CLI for Claude (running on the Sonnet 5 model).

@matheusaaguiar matheusaaguiar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, but I guess we have to fix/circunvent some tests (at least for now)
test_antl_grammar.sh needs to skip slotnum_osaka_function.sol for chk_antlr_grammar to pass.
We can also add a test case in test/libsolidity/ViewPureChecker.cpp and syntaxTests/constants/initialization/block_tx_msg_property.sol (although I guess they depend on restricting the evm version).

Comment thread docs/cheatsheet.rst
- ``block.gaslimit`` (``uint``): current block gaslimit
- ``block.number`` (``uint``): current block number
- ``block.prevrandao`` (``uint``): random number provided by the beacon chain (``EVM >= Paris``) (see `EIP-4399 <https://eips.ethereum.org/EIPS/eip-4399>`_ )
- ``block.slotnum`` (``uint``): current beacon chain slot number (``EVM >= Amsterdam``) (see `EIP-7843 <https://eips.ethereum.org/EIPS/eip-7843>`_ )

@cameel cameel Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The EIP guarantees that the returned value fits in uint64 (because that's how it's stored in the state), so I think we can give the builtin that type.

Comment thread libsolidity/ast/Types.cpp
{"basefee", TypeProvider::uint256()},
{"blobbasefee", TypeProvider::uint256()}
{"blobbasefee", TypeProvider::uint256()},
{"slotnum", TypeProvider::uint256()}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
{"slotnum", TypeProvider::uint256()}
{"slotnum", TypeProvider::uint256()},

Comment on lines +135 to +140
// TODO remove this in 0.9.0. We allow creating functions or identifiers in Yul with the name
// slotnum for VMs before amsterdam.
auto slotNumException = [&](evmasm::Instruction _instr) -> bool
{
return _instr == evmasm::Instruction::SLOTNUM && !_evmVersion.hasSlotNum();
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please remember to add the opcode to #14770.

}
}
// ====
// EVMVersion: <=osaka

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

IMO it would be slightly better do do this when possible:

Suggested change
// EVMVersion: <=osaka
// EVMVersion: <amsterdam

because it will make the test show up when you search for "Amsterdam". And it makes it unnecessary to know what the exact order of versions where - what's important is pre/post Amsterdam.

Same for test names.

@cameel

cameel commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

I updated our guide to cover new opcodes with a high-level builtin based on our past PRs. I did not find anything missing, but please double check: https://notes.argot.org/@solidity-new-opcode-guide#Special-case-Opcodes-with-a-high-level-Solidity-builtin. Especially the Yul part and test coverage.

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.