-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: MsgToL1
hash computation
#476
Conversation
L1
to L2
message support for L1HandlerTransaction
MsgToL2
and MsgToL1
hash computation
@xJonathanLEI could you try to re-run the action? Or could I do that on my end without adding a new commit? |
e0ea55d
to
3a6bb66
Compare
Rebased and squashed PR. |
I don't like how this impl uses |
Also this impl uses the hasher inefficiently. You shouldn't need to build a buffer to feed the hasher at the end. The hasher takes slices. |
starknet-core/src/types/messaging.rs
Outdated
pub fn parse_msg_to_l2(&self) -> MsgToL2 { | ||
// TODO: is that necessary? As the sequencer | ||
// itself is the one firing this kind of transaction? | ||
assert!(!self.calldata.is_empty()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assert!
is completely unacceptable. You're assuming that whatever self
instances always come from a trusted source, which is not true. As a library, you cannot decide this for your users. Only invariants can be checked with panic in a library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, thank you for pointing this out.
The Based on the official docs, it's not padded (no wrapping wiith I'm holding off adding the L2->L1 hashing until this is resolved. Maybe @amanusk can shed some light on this. |
If we take the code from Starknet Core Contract, the function consumeMessageFromL2(uint256 fromAddress, uint256[] calldata payload)
external
override
returns (bytes32)
{
bytes32 msgHash = keccak256(
abi.encodePacked(fromAddress, uint256(msg.sender), payload.length, payload)
);
require(l2ToL1Messages()[msgHash] > 0, "INVALID_MESSAGE_TO_CONSUME");
emit ConsumedMessageToL1(fromAddress, msg.sender, payload);
l2ToL1Messages()[msgHash] -= 1;
return msgHash;
} |
It was a suggestion to perhaps have user not bothering for conversion. But as you mentioned, as a library, being as agnostic as we can is far better. |
MsgToL2
and MsgToL1
hash computationMsgToL1
hash computation
Please rebase instead of merging. |
How do you know the user wants |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Related to #448.
As suggested in the issue, this is the responsibility of
L1HandlerTransaction
to expose it's message that can be parsed from it's content.The use of
EthAddress
solve the issue concern about a proper type to handle thefrom_address
field.Also, this PR includes the computation of
MsgToL1
, which is very practical in some scenarios when testing auto-consume of messages on L1.