---
eip: 2542
label: EIP-2542
title: New opcodes TXGASLIMIT and CALLGASLIMIT
status: Withdrawn
type: Standards Track
category: Core
created: 2020-02-29
official: https://eips.ethereum.org/EIPS/eip-2542
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2542.md
canonical: https://eips.huatuo.xyz/eip-2542/
lang: en
tldr: A withdrawn proposal for TXGASLIMIT and CALLGASLIMIT opcodes, which would have let contracts read the gas limit of the whole transaction and of the current call frame for exact gas accounting.
tags: [evm, opcodes, gas, meta-transactions, core]
---

# EIP-2542: New opcodes TXGASLIMIT and CALLGASLIMIT

> A mechanism to allow smart contracts to access information on gas limits for the current transaction and execution frame.

**TL;DR:** A withdrawn proposal for TXGASLIMIT and CALLGASLIMIT opcodes, which would have let contracts read the gas limit of the whole transaction and of the current call frame for exact gas accounting.

## What problem does it solve?

Relayers, meta-transaction forwarders and account abstraction systems often need to know exactly how much gas a transaction has used so they can charge or reimburse the right amount. The EVM only exposes:

- `GASLIMIT` (`0x45`) – the **block** gas limit, which contracts rarely care about.
- `GAS` (`0x5a`, `gasleft()`) – the gas **remaining**, not the amount you started with.

So contracts approximate. A common trick is to call `gasleft()` on the first line and subtract later, but that misses intrinsic costs (the 21,000 base, calldata bytes) and whatever Solidity spent copying calldata before your first line ran. Another use case is enforcing a gas limit that a user signed in a meta-transaction: `gasleft()` is dynamic and cannot be compared with a signed value.

## How it works

The proposal adds two opcodes, each costing 2 gas (the same as `GASLIMIT`):

| Opcode | Byte | Pushes |
| --- | --- | --- |
| `TXGASLIMIT` | `0x5c` | The gas limit signed into the transaction (`startgas`) |
| `CALLGASLIMIT` | `0x5d` | The gas given to the current frame, after the [EIP-150](/eip-150/) "all but one 64th" rule |

It also suggests renaming `GASLIMIT` to `BLOCKGASLIMIT` to avoid confusion. Nothing else in the EVM changes, so existing contracts are unaffected.

The authors stress that these values should be used as information about the execution environment, not as the core of a security mechanism.

## Sample code

Pseudo-Solidity from the proposal's rationale. `msg.gasLimit` and `tx.gasLimit` were never added to Solidity, so this does **not** compile:

```solidity
// Illustrative only: would map to CALLGASLIMIT / TXGASLIMIT
function keepTrackOfGas() public {
    // ... work ...
    uint256 gasUsed = msg.gasLimit - gasleft();   // CALLGASLIMIT - GAS
}

function verifyGasLimit(uint256 desiredGasLimit /*, signature ... */) public {
    // the user signed desiredGasLimit; check the relayer honoured it
    require(tx.gasLimit == desiredGasLimit, "gas limit not authorized"); // TXGASLIMIT
}
```

What developers do today instead (approximate):

```solidity
function relayed(bytes calldata data) external {
    uint256 start = gasleft();          // misses intrinsic + calldata cost
    // ... execute ...
    uint256 used = start - gasleft() + 21_000 + OVERHEAD_ESTIMATE;
}
```

## Things to know

- **Status: Withdrawn.** The withdrawal reason given is "Superseded by [EIP-8141](/eip-8141/)" (Frame Transaction), which is itself still a Draft.
- Opcode bytes `0x5c` and `0x5d` were later assigned to other instructions (`TLOAD`/`TSTORE` in [EIP-1153](/eip-1153/)), so these numbers are no longer available.
- Gas introspection is controversial: some core developers prefer that contracts not depend on gas values at all, so that gas costs can be repriced freely.
- For relayed calls today, see [ERC-2771](/eip-2771/) (trusted forwarders) and [ERC-4337](/eip-4337/), which handle gas accounting at the bundler/EntryPoint level.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-2542
