hiero-ledger / hiero-ledger/hiero-consensus-node

Make `COINBASE` address warm to comply with EIP-3651

Open
#21,335 0 comments 0 reactions 0 assignees View on GitHub
Hedera Smart Contract Service
Dominant language
Java
Stars
406
Forks
226
Avg merge
3d 4h
Merged PRs (30d)
210

Description

The [EIP-3651](https://eips.ethereum.org/EIPS/eip-3651) introduced in Shanghai states that the "COINBASE address shall be warm at the start of transaction execution, in accordance with the actual cost of reading that account."

However, the `COINBASE` address is treated as a cold address (with 2600 gas cost) when it is being called.

For reference, this PR https://github.com/hiero-ledger/hiero-consensus-node/issues/3805 introduced EIP-3651.

### Steps to Reproduce

To demonstrate this, we will use the following contract

```yul
// warm-coinbase.yul
object "Contract" {
code {
datacopy(0, dataoffset("runtime"), datasize("runtime"))
return(0, datasize("runtime"))
}
object "runtime" {
code {
let g0 := gas()
let res := call(0, coinbase(), 0, 0, 0, 0, 0)
let g1 := gas()
sstore(0x3, res)
sstore(0x7, sub(g0, g1))
}
}
}
```

This contract calls the `COINBASE` address, calculates how much gas was used, and saves it in the contract storage alongside the result of the call itself to ensure it was successful. Compile the contract with `solc`

```console
$ solc --strict-assembly --bin warm-coinbase.yul | tail -n 1
6014600b5f3960145ff3fe5a5f808080804181f1905a916003550360075500
```

Deploy the contract into a network, for example using [Foundry's `cast`](https://getfoundry.sh/cast/overview/) to testnet _(use your `$PRIVATE_KEY` for the chosen network)_

```console
$ cast send -v --rpc-url https://testnet.hashio.io/api --private-key $PRIVATE_KEY --gas-limit 100000 --create 6014600b5f3960145ff3fe5a5f808080804181f1905a916003550360075500

[...]
contractAddress 0xB20017bC59515A191c958A08060c1DfE1fd6303a
[...]
```

Here is the deployed contract on hashscan https://hashscan.io/testnet/contract/0.0.6935182/bytecode. Now we need to call the `contractAddress` (no data is necessary)

```console
$ cast send --rpc-url https://testnet.hashio.io/api --private-key $PRIVATE_KEY --gas-limit 200000 0xB20017bC59515A191c958A08060c1DfE1fd6303a

[...]
transactionHash 0x1af5a2169ef606630d824f69eef468ce876c17970fe3afb66e977ae6936e0fc6
[...]
```

We can see the transaction in hashscan https://hashscan.io/testnet/transaction/1759366813.152844205/states. The transaction was successful and the gas used was `2624 = 3*2 + 6*3 + 2600` coming from the following bytecode

```
0x0001: PUSH0 (2)
0x0002: DUP1 (3)
0x0003: DUP1 (3)
0x0004: DUP1 (3)
0x0005: DUP1 (3)
0x0006: COINBASE (2)
0x0007: DUP2 (3)
0x0008: CALL (2600)
0x0009: SWAP1 (3)
0x000a: GAS (2)
```

However, according to EIP-3651 the `CALL` should only cost `100` gas.

Contributor guide

Open the contributing guide

Research direction

Start by reading EIP-3651 and reproducing the reported transaction with the supplied Yul bytecode and gas breakdown. Trace the Java EVM handling of COINBASE and CALL gas accounting, then add regression coverage showing that the COINBASE call uses the warm-address cost of 100 gas.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
blockchain
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.