argotorg / argotorg/solidity

Cannot use word `_offset` in local variable name in inline assembly because of old 0.7.x syntax

Open
#14,589 1 comment 0 reactions 0 assignees View on GitHub
bug :bug: low impact medium effort must have eventually
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
21

Description

## Description

I have the following Solidity code with the inline assembly part that does not compile. See example below.
It always return me the following error:

```
DeclarationError: Identifier not found. Use ".slot" and ".offset" to access storage variables.
--> contracts/Playground.sol:23:24:
|
23 | revert(resultdata_offset, resultdata_size)
| ^^^^^^^^^^^^^^^^^
```

![image](https://github.com/ethereum/solidity/assets/31145285/c41d5693-42a0-43ce-8d1e-72c7dd2ab6a7)

I am wondering if this is normal. As far as I am aware, this is related to the old syntax from v0.7.x, where the suffixes `_slot` and `_offset` were used to access the slot number of a state variable (or its offset position in a storage slot). This was replaced by `.slot` and `.offset`.

https://docs.soliditylang.org/en/v0.8.21/070-breaking-changes.html#inline-assembly

![image](https://github.com/ethereum/solidity/assets/31145285/a07704ea-4208-4417-b8c5-5722b3c83932)

However, in this instance, I am just writing the local variable in assembly in `snake_case` with the word `_offset` and the compiler seems to confuse this with the old syntax. I am not sure if this is a bug or an inaccuracy in the error reported. If the two words `_slot` and `_offset` are not allowed for local variables in inline assembly, it would be useful I guess to mention it somewhere in the docs maybe?

## Environment

- Compiler version: 0.8.21
- Target EVM version (as per compiler settings): default
- Framework/IDE (e.g. Truffle or Remix): Remix

## Steps to Reproduce

```solidity
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.21;

contract Example {

address someAddress = 0xCAfEcAfeCAfECaFeCaFecaFecaFECafECafeCaFe;

bytes4 private constant _SOME_SELECTOR = bytes4(keccak256("hey()"));

function test() public payable {
(bool success, bytes memory result) = someAddress.call(
abi.encodePacked(_SOME_SELECTOR, msg.sender, msg.value)
);

assembly {
// `mload(result)` -> offset in memory where `result.length` is located
// `add(result, 32)` -> offset in memory where `result` data starts
let resultdata_size := mload(result)
let resultdata_offset := add(result, 32)

// if call failed, revert
if eq(success, 0) {
revert(resultdata_offset, resultdata_size)
}

// otherwise return the data returned by the external call
return(resultdata_offset, resultdata_size)
}
}

}
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the contract from the issue with Solidity 0.8.21 and inspect how inline assembly identifiers containing `_offset` are parsed and diagnosed. Compare the error with the documented 0.7.x-to-0.8.x inline assembly syntax change; done means the behavior is corrected or its restriction and rationale are documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
solidity
Domain
blockchain, compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.