Skip to content
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

Add deployment-specific prefix to message hashing #274

Open
wants to merge 20 commits into
base: release/v0.1.0
Choose a base branch
from

Conversation

Hyodar
Copy link
Contributor

@Hyodar Hyodar commented Jul 4, 2024

Current Behavior

Currently, messages are hashed as keccak256(prefix || digest), prefix being a message name used to avoid collisions with other messages - both in terms of internal messages and also other protocols'.

However, if we are to be completely resistant to collisions, separate deployments should also be considered. As EIP712 has specific chain ID and verifier contract specifications, something similar, though not exactly the same, is needed here. Otherwise, we can have collisions with different deployments of the protocol. Of course, that would be avoidable in the current state by changing the message names on the other deployment and, considering BLS keys should differ between them, this is not an issue at the current stage. Also, the collision wouldn't be impactful.

Either way, this is something that should be changed soon because it affects the messaging protocol formats. So, the sooner the better.

New Behavior

We can't properly use something as EIP712, as already discussed in #104, because our messages are actually meant to be verified cross-chain by different contracts. At the same time, changing constant message prefixes per deployment is not that interesting of a solution. It could be if we had a Solidity preprocessor though.

What we can do instead is introducing a deployment-specific member to our prefix. So, with this we now have a messagingPrefix member which is set up in the SFFLTaskManager contract and SFFLRegistryRollup contracts as immutable (can be changed in upgrades, which would already be needed anyway in case of a messaging protocol change) and we use a type hash structure for it through SFFLMessagingPrefix(string version,address taskManager,uint256 chainId).

Breaking Changes

This is a breaking change and requires coordination for upgrades. The reason for that is nodes, as contracts, hash messages, and these hash functions must be the same. We could make a compatibility layer, but it'd require operators to track contract upgrades, so it's some added complexity.

It also requires contract upgrades!

@Hyodar Hyodar marked this pull request as ready for review July 23, 2024 02:03
@Hyodar Hyodar changed the base branch from main to release/v0.1.0 July 23, 2024 14:06
@Hyodar Hyodar self-assigned this Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant