---
eip: 3
label: EIP-3
title: Addition of CALLDEPTH opcode
status: Withdrawn
type: Standards Track
category: Core
created: 2015-11-19
official: https://eips.ethereum.org/EIPS/eip-3
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3.md
canonical: https://eips.huatuo.xyz/eip-3/
lang: en
tldr: A withdrawn 2015 proposal for a CALLDEPTH opcode that would tell a contract how much call-stack depth was left, as a cheap defence against call-stack attacks.
tags: [evm, opcode, security, core, withdrawn]
---

# EIP-3: Addition of CALLDEPTH opcode

> This is a proposal to add a new opcode, CALLDEPTH. The CALLDEPTH opcode would return the remaining available call stack depth.

**TL;DR:** A withdrawn 2015 proposal for a CALLDEPTH opcode that would tell a contract how much call-stack depth was left, as a cheap defence against call-stack attacks.

## What problem does it solve?

In early Ethereum, contracts could only call each other 1024 levels deep (the spec text cites 256, but the limit was 1024). Once that limit was reached, any further `CALL` simply failed.

This enabled a **call-stack attack**. An attacker first builds up a deep chain of calls, for example with recursion, and then calls the victim contract. Every call the victim makes from there fails. If the victim does not check whether its calls succeeded, it may carry on as if they had worked. The spec gives an example: a contract that calls `B` and `C` and then pays a reward to its caller. The attacker makes both inner calls fail and still collects the reward.

Developers had two defences: always check return values, or probe the depth on purpose by making test calls. The probing approach existed as a library, but it cost a lot of gas. EIP-3 proposed a direct, cheap answer.

## How it works

The proposal is a single new opcode:

- `CALLDEPTH` pushes the **remaining** call-stack depth onto the stack.
- A value of `0` means the stack is exhausted and no further calls can succeed.

The EVM already tracks the current depth and the limit internally. The opcode would only expose that number to contract code. The spec does not assign an opcode byte or a gas cost.

## Sample code

Illustrative pseudocode only. `CALLDEPTH` was never added to the EVM, so this does not compile.

```solidity
// Hypothetical: refuse to run if too little call depth remains
function payout() external {
    // calldepth() would wrap the proposed CALLDEPTH opcode
    require(calldepth() >= 2, "not enough call depth for B and C");
    B.doWork();
    C.doWork();
    payable(msg.sender).transfer(reward);
}
```

The defence that actually works today is to check every call's result:

```solidity
(bool ok, ) = address(b).call(data);
require(ok, "call to B failed");
```

## Things to know

- **This proposal is Withdrawn and was never implemented.** The EVM has no `CALLDEPTH` opcode.
- The attack was later made impractical in another way. [EIP-150](/eip-150/) (Tangerine Whistle) changed calls so a caller can forward at most 63/64 of its remaining gas. Reaching a depth of 1024 now takes far more gas than any block contains.
- Checking the success flag of low-level calls is still essential. Solidity's high-level calls revert automatically on failure, and [EIP-140](/eip-140/) `REVERT` makes failures easier to report.
- Do not confuse the *call stack* (nested message calls) with the EVM's *data stack* of 1024 words. They are separate limits.


---

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