solidity
solidity copied to clipboard
WIP: add support for transient storage in the solidity
EIP-1153 is now live on mainnet since DenCun, a week ago. The community shows a lot of interrest for transient storage, yet it is not nativelly supported by solidity. A quick search did not bring any ongoing effort to add that support.
EIP-1153 states that:
Language support could be added in relatively easy way. For example, in Solidity, a qualifier transient can be introduced (similar to the existing qualifiers memory and storage, and Java’s own transient keyword with a similar meaning). Since the addressing scheme of TSTORE and TLOAD is the same as for SSTORE and SLOAD, code generation routines that exist for storage variables, can be easily generalised to also support transient storage.
Its unfortunatrlly not that easy ... but come on, I'm sure as a community we can do this!
Note: this is very early ... No where near ready ... Probably not doing things the right way ... but at least its something. I'l try to work on that. Anyone if free to comment on this, or start another effort (based or not on this).
My analysis so far
transient is both a "Mutation" and a "Location"
- its a mutation because you should be able to declare a variable as "transient", just like you would mark it as "constant" or "immutable"
contract Test {
uint256 constant public A = 1;
uint256 immutable public B;
uint256 transient internal C;
///...
}
Note that this mutation applies to non-value type (struct, string, array, even mapping!)
contract Test {
mapping(address => mapping(address => uint256)) transient internal _temporaryAllowances;
///...
}
- transient is also (and mostly) a storage location. In that regard it behaves very similarly to Storage (same slot derivation and everything), but code generation needs to replace
sload
/sstore
withtload
/tstore
contract Test {
struct MyStruct { ... };
mapping(address => MyStruct) transient internal _temporaryDetails;
///...
function something(...) public {
MyStruct transient ref = _temporaryDetails[msg.sender];
//...
}
}
TODO
- [x] informal tests (objective is to compile uniswap-v4-core with transient enabled, and run tests)
- https://github.com/Uniswap/v4-core/pull/541
- [ ] formal tests
- [ ] review
- [ ] 🚀
Thank you for your contribution to the Solidity compiler! A team member will follow up shortly.
If you haven't read our contributing guidelines and our review checklist before, please do it now, this makes the reviewing process and accepting your contribution smoother.
If you have any questions or need our help, feel free to post them in the PR or talk to us directly on the #solidity-dev channel on Matrix.
Great initiative!
I think it should also allow declaring function arguments as transient, e.g. someFn (uint transient num)
like with storage
.
Great initiative!
I think it should also allow declaring function arguments as transient, e.g.
someFn (uint transient num)
like withstorage
.
Yes, AFAIK
- everywhere
storage
ormemory
is allowed,transient
should also be allowed (that is the location part).- function args
- function returns
- non-value-type declaration
- everywhere
constant
ofimmutable
is allowed,transient
should also be allowed (that is the mutation part)- that is basically state
variable
- unlike the other two, that only apply to value-type,
transient
should also apply to non value type (structs, arrays, mappings)
- that is basically state
WIP:
- [x] ~~Current version affects the optimizer, and transient operation get removed~~
- [x] ~~Bad resolution of mapping types~~
- [x] ~~Public getters to transiant variables are not using tload as they should~~
- [ ] Figure out the mess in YulUtilFunctions. Is everything needed/used ? What is the best way of adding transient support?
@Amxx thank you for your effort!
Hey @Amxx!
Thanks so much for putting in the time and effort in understanding the compiler and putting this PR together. We appreciate you for taking this crucial first step and helping the team gauge the community's interest for high-level language support for transient storage.
We just posted a discussion thread on our forum as our public response to recognise the current community interest and efforts around support for transient storage and share the challenges around implementation discussed with you during the previous language design call. Our post also outlines the next steps that the team will be working on to further the progress in this area. You can check out the catch-all issue to stay updated.
Cheers!
Interesting fact, that @1inch team started using transient
keyword in Solidity in Dec 2023: 1inch/solidity-utils/.../BySig.sol#L50
Can't wait to uncomment transient
data location.
Hey @Amxx ! I would like to assist in this build. Please let me know if you need any help or have any tasks for me!
Hey all!
Appreciate your interest in supporting us with the implementation of the transient storage feature at the language-level. Especially, thanks to @Amxx for the discussions around it and representing the community's interest to help us understand what is needed.
We have begun the implementation and you can keep an eye on what is merged and what is being worked on currently in this catch-all issue for transient storage. Hence, I will be closing this draft PR. :)