solidity
solidity copied to clipboard
Support EIP-712 typehash in `type`
Abstract
Let's add support of type(State).typehash
for structs, returning bytes32
hashed stringed structure.
Motivation
EIP-712 type hashes are pretty popular among smart contract of different companies. I believe it makes sense to support it on Solidity language layer.
Specification
bytes32 constant public STATE_TYPEHASH = keccak256(
"State("
"uint256 nonce,"
"uint256 totalSpent,"
"uint256 totalRefunded"
")"
);
=>
struct State {
uint256 nonce;
uint256 totalSpent;
uint256 totalRefunded;
}
bytes32 constant public STATE_TYPEHASH = type(State).typehash;
Backwards Compatibility
Not sure
I really like that idea. I feel like instead of calling it State
, the semantics Topic
would be nicer. Also, I would like to add a further request for commonly known type hashes such as the one for permit
.
Instead of doing the following (or the approach in the feature request above):
bytes32 private constant _PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
one could simply query the type hash like the following without importing the EIP-2612
interface itself (i.e. Permit
is already built-in):
bytes32 private constant _PERMIT_TYPEHASH = type(Permit).typehash
This would require restricting the namespace for type
but I feel that it's becoming less error-prone like that due to common mistakes made such as the usage of uint
alias in the hash.
@pcaversaccio type(X)
is already type-sensitive: https://docs.soliditylang.org/en/v0.8.19/units-and-global-variables.html
@k06a We discussed this in the call. We're fine with proceeding here. Would appreciate if you can lead the implementation, we can give some pointers on missing things, and review it.
@hrkrshnn great, thanks!
What do you think of adding runtime function to compute hash of the exact struct entity:
State memory state;
type(State).hashStruct(state);
@k06a I like it. Can you open a new issue for it?
@hrkrshnn done: https://github.com/ethereum/solidity/issues/14208
This issue has been marked as stale due to inactivity for the last 90 days. It will be automatically closed in 7 days.
This is still relevant.
Wen merge @hrkrshnn? 😁
Apologies @k06a, I've been heads down on @spearbit lately. I'll find some time on the weekend to review this.
up up up :-)
this will be a game-changer.
This issue has been marked as stale due to inactivity for the last 90 days. It will be automatically closed in 7 days.
This is still relevant. Don't close.
Would love to see this!
+1
@hrkrshnn status?
Sorry @pegahcarter. I'm heads down on @cantinaxyz and @spearbit and won't be able to spend time on this.
This issue has been marked as stale due to inactivity for the last 90 days. It will be automatically closed in 7 days.
I guess this is still relevant, so don't close.
I think we just need someone to champion the dev.
This issue has been marked as stale due to inactivity for the last 90 days. It will be automatically closed in 7 days.
I guess this is still relevant, so don't close.
@hrkrshnn how about now? :pray: