Get the beneficiary address receiving block rewards and transaction fees
This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.
Overview
Opcode:0x41Introduced: Frontier (EVM genesis)COINBASE retrieves the address of the block beneficiary - the account that receives the block reward and transaction fees for the current block. This is typically the miner’s address (pre-merge) or validator’s address (post-merge).
Specification
Stack Input:
(none)
Stack Output:
coinbase_address (as u256)
Gas Cost: 2 (GasQuickStep)Operation:
stack.push(block.coinbase as u256)
Behavior
COINBASE pushes the 20-byte beneficiary address onto the stack as a 256-bit unsigned integer. The address is right-aligned (lower-order bytes):
// Execute COINBASEcoinbase(frame);const coinbaseU256 = frame.stack[0];// Convert u256 back to addressconst addressBytes = new Uint8Array(20);for (let i = 0; i < 20; i++) { addressBytes[19 - i] = Number((coinbaseU256 >> BigInt(i * 8)) & 0xFFn);}console.log(addressBytes); // Original 20-byte address
Compare with Current Address
import { address } from '@tevm/voltaire/evm/context';// Get coinbasecoinbase(frame);const coinbaseAddr = frame.stack[0];// Get current contract addressaddress(frame);const currentAddr = frame.stack[0];// Check if contract is coinbaseconst isCoinbase = coinbaseAddr === currentAddr;
Gas Cost
Cost: 2 gas (GasQuickStep)COINBASE is one of the cheapest operations, sharing the GasQuickStep tier with:
TIMESTAMP (0x42)
NUMBER (0x43)
DIFFICULTY (0x44)
GASLIMIT (0x45)
CHAINID (0x46)
Comparison:
COINBASE: 2 gas
SELFBALANCE: 5 gas
BLOCKHASH: 20 gas
BALANCE (cold): 2600 gas
Common Usage
Miner Tipping
contract MinerTip { // Send tip directly to block producer function tipMiner() external payable { require(msg.value > 0, "No tip sent"); payable(block.coinbase).transfer(msg.value); }}
Coinbase Verification
contract OnlyMiner { modifier onlyMiner() { require(msg.sender == block.coinbase, "Only miner can call"); _; } function privilegedOperation() external onlyMiner { // Only callable by block producer }}
Flashbots/MEV Protection
contract AntiMEV { // Ensure transaction is included by specific validator function protectedSwap(address expectedCoinbase) external { require(block.coinbase == expectedCoinbase, "Wrong validator"); // Execute swap }}
Block Producer Allowlist
contract ValidatorGated { mapping(address => bool) public approvedValidators; modifier onlyApprovedValidator() { require(approvedValidators[block.coinbase], "Validator not approved"); _; } function sensitiveOperation() external onlyApprovedValidator { // Only execute if produced by approved validator }}
// Coinbase = Miner's addresscontract MinerReward { // Miners could redirect rewards function() external payable { // Miner can set coinbase to this contract // to receive rewards + fees here }}
Characteristics:
Miner can set coinbase to any address
Often set to mining pool contract
Can change between blocks
Post-Merge (PoS)
// Coinbase = Validator's fee recipientcontract ValidatorOperator { mapping(address => address) public feeRecipients; // Validators configure their fee recipient function setFeeRecipient(address recipient) external { feeRecipients[msg.sender] = recipient; }}
Characteristics:
Set by validator client configuration
Typically validator’s withdrawal address
More predictable than PoW mining pools
Security Considerations
Centralization Risk
Relying on block.coinbase for access control creates centralization:
// RISKY: Single point of failurecontract CentralizedControl { function privilegedAction() external { require(msg.sender == block.coinbase, "Only validator"); // Critical operation controlled by single validator }}
Mitigation:
Use multi-signature or DAO governance instead of validator-gated logic.
Validator Collusion
Validators can coordinate to manipulate coinbase-dependent logic:
// VULNERABLE: Validators can coordinatecontract CoinbaseDependent { mapping(address => uint256) public validatorScores; function rewardValidator() external { validatorScores[block.coinbase] += 1; }}
contract MEVAware { // Pay validators to include transaction function urgentSwap() external payable { uint256 validatorBribe = msg.value / 10; // 10% to validator payable(block.coinbase).transfer(validatorBribe); // Execute swap with remaining value }}
Coinbase Replay Attacks
Be careful with coinbase-based authentication across chains:
// VULNERABLE: Validator could exist on multiple chainscontract CrossChainVulnerable { function authenticate() external view returns (bool) { return msg.sender == block.coinbase; // Same validator on different chain! }}// SAFE: Include chain IDcontract CrossChainSafe { function authenticate(uint256 expectedChain) external view returns (bool) { require(block.chainid == expectedChain, "Wrong chain"); return msg.sender == block.coinbase; }}
Implementation
TypeScript
/** * COINBASE opcode (0x41) - Get block coinbase address */export function coinbase(frame: FrameType): EvmError | null { // Consume gas (GasQuickStep = 2) frame.gasRemaining -= 2n; if (frame.gasRemaining < 0n) { frame.gasRemaining = 0n; return { type: "OutOfGas" }; } // Convert 20-byte address to u256 const coinbaseAddr = frame.evm.blockContext.block_coinbase; let coinbaseU256 = 0n; for (let i = 0; i < 20; i++) { coinbaseU256 = (coinbaseU256 << 8n) | BigInt(coinbaseAddr[i]); } // Push to stack if (frame.stack.length >= 1024) return { type: "StackOverflow" }; frame.stack.push(coinbaseU256); frame.pc += 1; return null;}
Edge Cases
Zero Address Coinbase
// Coinbase set to 0x0000...0000const frame = createFrame({ blockContext: { block_coinbase: new Uint8Array(20) // All zeros }});coinbase(frame);console.log(frame.stack); // [0n]