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

commitBatch and receiveBatch optimizations #40

Merged
merged 7 commits into from
Oct 11, 2024

Conversation

goran-ethernal
Copy link
Collaborator

@goran-ethernal goran-ethernal commented Oct 9, 2024

This PR optimizes the commitBatch function on BridgeStorage contract, so that it doesn't use all the gas in block, since it saved the entire bridge messages contained in a batch. Now the function will receive a signed batch that contains:

struct SignedBridgeMessageBatch {
    bytes32 rootHash; // Merkle Tree root hash gotten from createing a merkle tree of all messages in a batch
    uint256 startId; // ID of first message in batch
    uint256 endId; // ID of last message in batch
    uint256 sourceChainId; // chain id of origin
    uint256 destinationChainId; // chain id of destination
    uint256[2] signature; // aggregated signature of signed batch
    bytes bitmap; // bitmap needed to verify the signature
}

Since the SignedBridgeMessageBatch now uses simple and fixed types, gas consumption dropped significantly, since we are not storing messages on the contract.

This PR also changes the receiveBatch function on Gateway contract, which the relayer will call to execute the batch. The function will now receive the list of brigde messages, signature and bitmap, and it will calculate the merkle tree root hash from messages, and check it against the signature.

@goran-ethernal goran-ethernal marked this pull request as ready for review October 11, 2024 07:10
contracts/lib/Merkle.sol Outdated Show resolved Hide resolved
docs/lib/Merkle.md Outdated Show resolved Hide resolved
@goran-ethernal goran-ethernal merged commit 8158051 into feat/bridge Oct 11, 2024
7 checks passed
@goran-ethernal goran-ethernal deleted the optimizations branch October 11, 2024 07:47
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.

4 participants