Yul Builtins Reference

This chapter lists all Yul builtin functions supported by solx and how each is lowered to LLVM IR for the EVM backend.

Lowering Strategies

Yul builtins are lowered through one of three strategies:

  • Direct LLVM IR: the builtin maps to native LLVM integer or memory operations on i256.
  • LLVM intrinsic: the builtin maps to an llvm.evm.* intrinsic that the EVM backend expands to opcodes.
  • Address space access: the builtin maps to a load or store in a typed LLVM address space (see EVM Instructions: Address Space Model).

Arithmetic

BuiltinLoweringNotes
addDirect LLVM IRadd i256
subDirect LLVM IRsub i256
mulDirect LLVM IRmul i256
divDirect LLVM IRUnsigned; returns 0 when divisor is 0
sdivDirect LLVM IRSigned; returns 0 when divisor is 0
modDirect LLVM IRUnsigned; returns 0 when divisor is 0
smodDirect LLVM IRSigned; returns 0 when divisor is 0
addmodIntrinsic llvm.evm.addmod(x + y) % m without intermediate overflow
mulmodIntrinsic llvm.evm.mulmod(x * y) % m without intermediate overflow
expIntrinsic llvm.evm.expExponentiation
signextendIntrinsic llvm.evm.signextendSign extend from bit (i*8+7)

Comparison

BuiltinLoweringNotes
ltDirect LLVM IRUnsigned less-than
gtDirect LLVM IRUnsigned greater-than
sltDirect LLVM IRSigned less-than
sgtDirect LLVM IRSigned greater-than
eqDirect LLVM IREquality
iszeroDirect LLVM IRCheck if zero

Bitwise

BuiltinLoweringNotes
andDirect LLVM IRBitwise AND
orDirect LLVM IRBitwise OR
xorDirect LLVM IRBitwise XOR
notDirect LLVM IRBitwise NOT
shlDirect LLVM IRShift left; shift >= 256 yields 0
shrDirect LLVM IRLogical shift right; shift >= 256 yields 0
sarDirect LLVM IRArithmetic shift right; shift >= 256 yields sign-extended value
byteIntrinsic llvm.evm.byteExtract nth byte
clzIntrinsic llvm.ctlzCount leading zeros (requires Osaka EVM version)

Hashing

BuiltinLoweringNotes
keccak256Intrinsic llvm.evm.sha3Keccak-256 over memory range

Memory

BuiltinLoweringNotes
mloadAddress space 1 loadLoad 32 bytes from heap memory
mstoreAddress space 1 storeStore 32 bytes to heap memory
mstore8Intrinsic llvm.evm.mstore8Store single byte to memory
mcopymemcpy in address space 1EIP-5656 memory copy
msizeIntrinsic llvm.evm.msizeHighest accessed memory index

Storage

BuiltinLoweringNotes
sloadAddress space 5 loadLoad from persistent storage
sstoreAddress space 5 storeStore to persistent storage
tloadAddress space 6 loadLoad from transient storage (EIP-1153)
tstoreAddress space 6 storeStore to transient storage (EIP-1153)

Immutables

BuiltinLoweringNotes
loadimmutableIntrinsic llvm.evm.loadimmutableLoad immutable value with metadata identifier
setimmutableSpecialSet immutable value during deployment

Call Data and Return Data

BuiltinLoweringNotes
calldataloadAddress space 2 loadLoad 32 bytes from calldata
calldatasizeIntrinsic llvm.evm.calldatasizeSize of calldata
calldatacopymemcpy from address space 2 to 1Copy calldata to memory
returndatasizeIntrinsic llvm.evm.returndatasizeSize of return data
returndatacopymemcpy from address space 3 to 1Copy return data to memory

Code Operations

BuiltinLoweringNotes
codesizeIntrinsic llvm.evm.codesizeCurrent contract code size
codecopymemcpy from address space 4 to 1Copy code to memory
extcodesizeIntrinsic llvm.evm.extcodesizeExternal contract code size
extcodecopyIntrinsic llvm.evm.extcodecopyCopy external code to memory
extcodehashIntrinsic llvm.evm.extcodehashHash of external contract code

Object and Data Operations

BuiltinLoweringNotes
datasizeIntrinsic llvm.evm.datasizeSize of a named data object
dataoffsetIntrinsic llvm.evm.dataoffsetOffset of a named data object
datacopySame as codecopyCopy data to memory

These builtins are used by deploy stubs to reference embedded runtime and dependency objects. See Binary Layout for details.

Event Logging

BuiltinLoweringNotes
log0Intrinsic llvm.evm.log0Log with 0 topics
log1Intrinsic llvm.evm.log1Log with 1 topic
log2Intrinsic llvm.evm.log2Log with 2 topics
log3Intrinsic llvm.evm.log3Log with 3 topics
log4Intrinsic llvm.evm.log4Log with 4 topics

Contract Calls

BuiltinLoweringNotes
callIntrinsic llvm.evm.callCall with value transfer
delegatecallIntrinsic llvm.evm.delegatecallCall preserving caller and callvalue
staticcallIntrinsic llvm.evm.staticcallRead-only call

Note: callcode is rejected at compile time. Use delegatecall instead.

Contract Creation

BuiltinLoweringNotes
createIntrinsic llvm.evm.createCreate new contract
create2Intrinsic llvm.evm.create2Create at deterministic address

Control Flow

BuiltinLoweringNotes
returnIntrinsic llvm.evm.returnReturn data from execution
revertIntrinsic llvm.evm.revertRevert with return data
stopIntrinsic llvm.evm.stopStop execution
invalidIntrinsic llvm.evm.invalidInvalid instruction (consumes all gas)

Note: selfdestruct is rejected at compile time (deprecated by EIP-6049).

Block and Transaction Context

BuiltinLoweringNotes
addressIntrinsic llvm.evm.addressCurrent contract address
callerIntrinsic llvm.evm.callerMessage sender
callvalueIntrinsic llvm.evm.callvalueWei sent with call
gasIntrinsic llvm.evm.gasRemaining gas
gaspriceIntrinsic llvm.evm.gaspriceGas price of transaction
balanceIntrinsic llvm.evm.balanceBalance of address
selfbalanceIntrinsic llvm.evm.selfbalanceCurrent contract balance
originIntrinsic llvm.evm.originTransaction sender

Block Information

BuiltinLoweringNotes
blockhashIntrinsic llvm.evm.blockhashHash of given block
numberIntrinsic llvm.evm.numberCurrent block number
timestampIntrinsic llvm.evm.timestampBlock timestamp
coinbaseIntrinsic llvm.evm.coinbaseBlock beneficiary
difficultyIntrinsic llvm.evm.difficultyBlock difficulty (pre-merge)
prevrandaoIntrinsic llvm.evm.difficultyPrevious RANDAO value (EIP-4399, reuses difficulty)
gaslimitIntrinsic llvm.evm.gaslimitBlock gas limit
chainidIntrinsic llvm.evm.chainidChain ID (EIP-1344)
basefeeIntrinsic llvm.evm.basefeeBase fee per gas (EIP-1559)
blobhashRejected at compile timeVersioned hash of transaction's i-th blob (EIP-4844)
blobbasefeeRejected at compile timeCurrent block's blob base fee (EIP-7516/EIP-4844)

Note: blobhash and blobbasefee are not yet supported and will produce a compile error.

Special and Meta

BuiltinLoweringNotes
popOptimized awayNo code generated
linkersymbolIntrinsic llvm.evm.linkersymbolLibrary linker placeholder
memoryguardSpecialReserves a memory region; used by solx to configure the spill area for stack-too-deep mitigation