# \[Deprecation feedback\] Disallowing internal function pointers in storage

**URL:** <https://forum.soliditylang.org/t/deprecation-feedback-disallowing-internal-function-pointers-in-storage/3228>\
**Category:** Feedback\
**Created:** [January 15, 2025, 6:26pm UTC](https://forum.soliditylang.org/t/deprecation-feedback-disallowing-internal-function-pointers-in-storage/3228 "2025-01-15T18:26:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cameel](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/cameel/32/34_2.png) [@cameel](https://forum.soliditylang.org/u/cameel)\
**Post date:** [January 15, 2025, 6:26pm UTC](https://forum.soliditylang.org/t/deprecation-feedback-disallowing-internal-function-pointers-in-storage/3228/1 "2025-01-15T18:26:05Z")

</div>

A [recently reported issue](https://github.com/ethereum/solidity/issues/15716) brought our attention to the fact that compiler’s guarantees about the stability of internal function pointers are pretty weak. Such pointers are only valid in the context of a single contract and even then only in a very strict sense - any bytecode change may invalidate them. It will now be documented ([Document internal function pointer stability guarantees by cameel · Pull Request #15721 · ethereum/solidity · GitHub](https://github.com/ethereum/solidity/pull/15721)) and users should be aware of it, but maybe this is not enough.

My suggestion would be to go further and **disallow declaring storage variables of internal function types**. The question is whether anyone thinks this is a bad idea or would be negatively impacted by this? If there are no objections, we’re likely to go ahead with this idea for 0.9.0.

Such types are already considered internal and cannot be passed across contracts (unless masked as something else). Putting them in storage can be safe if done carefully but it also seems like the fact that it has to be considered at all is not obvious to most users and a pretty big gotcha. It will still be possible via inline assembly of course but that will at least make it clearer that something unusual is happening.

---

<div class="post-metadata">

**Author:** ![frangio](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/frangio/32/673_2.png) [@frangio](https://forum.soliditylang.org/u/frangio)\
**Post date:** [January 16, 2025, 11:06am UTC](https://forum.soliditylang.org/t/deprecation-feedback-disallowing-internal-function-pointers-in-storage/3228/2 "2025-01-16T11:06:29Z")

</div>

Definitely agree with deprecating and removing this. It shouldn’t cause any issue, it can be recovered manually if someone needs it, and that’s the way it should’ve been originally.

---

<div class="post-metadata">

**Author:** ![0xth0mas](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/0xth0mas/32/1129_2.png) [@0xth0mas](https://forum.soliditylang.org/u/0xth0mas)\
**Post date:** [January 24, 2025, 3:06am UTC](https://forum.soliditylang.org/t/deprecation-feedback-disallowing-internal-function-pointers-in-storage/3228/3 "2025-01-24T03:06:54Z")

</div>

Would this impact immutable function pointers that are set during contract construction? I’ve found those to be handy when you different ways that something could be handled depending on how a contract is initialized.

---

<div class="post-metadata">

**Author:** ![cameel](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/cameel/32/34_2.png) [@cameel](https://forum.soliditylang.org/u/cameel)\
**Post date:** [January 24, 2025, 3:17am UTC](https://forum.soliditylang.org/t/deprecation-feedback-disallowing-internal-function-pointers-in-storage/3228/4 "2025-01-24T03:17:34Z")

</div>

Immutables seem perfectly safe because they are stored in the contract code so they would be updated along with it. We’d let those be and only disallow putting internal pointers in storage.

Does anyone think we should disallow them in transient storage as well? On the one hand it’s technically possible to update a contract during a transaction, so it has the same problem as storage. On the other, the same could be said about memory and disallowing such pointers in memory seems to me like it would be going too far. So maybe transient storage is fine.

In any case, thanks for pointing out immutables. I actually didn’t think about that use case.

---

<div class="post-metadata">

**Author:** ![0xth0mas](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/0xth0mas/32/1129_2.png) [@0xth0mas](https://forum.soliditylang.org/u/0xth0mas)\
**Post date:** [January 27, 2025, 6:14am UTC](https://forum.soliditylang.org/t/deprecation-feedback-disallowing-internal-function-pointers-in-storage/3228/5 "2025-01-27T06:14:05Z")

</div>

I think transient storage would be fine. Memory would be going too far, we use them in memory because of stack too deep.

---

<div class="post-metadata">

**Author:** ![cameel](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/cameel/32/34_2.png) [@cameel](https://forum.soliditylang.org/u/cameel)\
**Post date:** [January 29, 2025, 4:03pm UTC](https://forum.soliditylang.org/t/deprecation-feedback-disallowing-internal-function-pointers-in-storage/3228/6 "2025-01-29T16:03:45Z")

</div>

We decided to schedule the change for 0.9.0. The compiler will also start issuing a deprecation warning about it in one of the upcoming releases.

> <https://github.com/ethereum/solidity/issues/15794>
>
> Related: #15716, #15721.
> 
> \## Abstract
> 
> Disallow using internal function types fo…r storage variables.
> 
> \## Motivation
> 
> Compiler's guarantees about the stability of internal function pointers are pretty weak. Such pointers are only valid in the context of a single contract and even then only in a very strict sense - any bytecode change may invalidate them.
> 
> Such types are already considered internal and cannot be passed across contracts (unless masked as something else). Putting them in storage can be safe if done carefully but the fact that it has to be considered at all is not obvious to most users and a pretty big gotcha.
> 
> We recently asked for community feedback in \[\[Deprecation feedback\] Disallowing internal function pointers in storage\](https://forum.soliditylang.org/t/deprecation-feedback-disallowing-internal-function-pointers-in-storage/3228) and the answers we received so far seem in favor of the change.
> 
> \## Specification
> 
> \- The use of an internal function type (\`function() internal\` and its derivatives) should be disallowed for all variables stored in storage and references to storage variables, which includes:
> - contract state variables
> - \`storage\` function parameters/returns
> - \`storage\` local variables
> - members of composite types (structs, arrays, mappings)
> \- Such types should still be allowed in other locations, including transient storage and immutables.
> 
> 
> \## Backwards Compatibility
> 
> The change is breaking. Contracts using such pointers will no longer compile.
> 
> Upgrading an existing contract while keeping the storage layout will still be possible - by replacing the storage variable with an integer and creating a custom dispatch function. The dispatch would simply treat the value as an enumeration and call the internal function corresponding to each value. It will also be possible via inline assembly, though such usage will require referencing any internal function that might be called from outside inline assembly to prevent the compiler from considering it unused and removing it.
