argotorg / argotorg/solidity

Functions that are generic in the data location of pointer arguments

Open
#13,207 1 comment 2 reactions 0 assignees View on GitHub
high effort high impact language design :rage4: needs design selected for development
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
21

Description

Follow up to https://github.com/ethereum/solidity/issues/869#issuecomment-676517663

In order to write efficient code it's important to make good use of data locations. For example, avoiding unnecessary copies from calldata to memory. Some of the utilities we want to provide in OpenZeppelin Contracts can operate on both memory and calldata values, for example functions for validating merkle proofs. Currently we're forced to write two separate versions with almost no code reuse between them. This increases the opportunity for error for us as library developers, and makes it harder for the user to write efficient code as they have to know not to use the memory version (due to implicit copying).

We would like to be able to write functions that are generic for both memory and calldata. The compiler would emit separate implementations depending on the arguments the function is used with.

I think this deserves its own issue separate from https://github.com/ethereum/solidity/issues/869.

An important question is whether these data location-generic functions should also be usable with storage pointer arguments. Similarly for a potential future [transient storage](https://eips.ethereum.org/EIPS/eip-1153) location. Storage is very different from memory and calldata in the mode of addressing and its interface, so I guess that some functions would only work with memory and calldata. On the other hand, storage and transient storage seem like they will be of the same category, and it should be possible to write a function that is generic in the kind of storage it uses. Some simpler functions may work with all locations if they only use `store` and `load` operations, but this seems less necessary.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing issue #869 and its referenced comment, then inspect the compiler's handling of memory, calldata, and storage pointer arguments. Done means defining and implementing data-location-generic functions that can generate appropriate implementations, while resolving whether storage and transient storage are supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, solidity
Domain
blockchain, compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.