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

feat: starknet GMP #731

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open

Conversation

ctoyan
Copy link
Contributor

@ctoyan ctoyan commented Dec 18, 2024

Description

This PR consists of:

  • call contract event verification
  • signer rotation event verification
  • starknet specific types and events de/serialisation implementations

Todos

  • Unit tests
  • Manual tests
  • Documentation
  • Connect epics/issues

Steps to Test

You would need the Starknet relayer, in order to manually test, which is not open sourced or deployed yet.
Also we don't have integration or end-to-end tests yet.

Expected Behaviour

Handle GMP messages from other amplifier chains

Other Notes

The FieldElementAndEventIndex PR must be merged to main before this PR manages to compile successfully.

@ctoyan ctoyan requested a review from a team as a code owner December 18, 2024 15:28
@ctoyan ctoyan marked this pull request as draft December 27, 2024 11:25
@ctoyan ctoyan marked this pull request as ready for review January 12, 2025 20:46
ampd/src/handlers/starknet_verify_msg.rs Outdated Show resolved Hide resolved
ampd/src/handlers/starknet_verify_msg.rs Outdated Show resolved Hide resolved
ampd/src/starknet/verifier.rs Outdated Show resolved Hide resolved
ampd/src/starknet/verifier.rs Outdated Show resolved Hide resolved
@@ -0,0 +1,28 @@
[package]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these types only used in ampd? or are they used in contracts as well? If they are only used in ampd, I think they should just live in a folder in ampd, close to where they are used. I see the packages folder as a place for things that are used across the entire repo.

Copy link
Contributor Author

@ctoyan ctoyan Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The StarknetMessage type is used in the multisig-prover. Should we keep it in our fork?
I can move the events and other types in ampd.


I'll use this thread to ask a question. We plan to migrate to using the cainome crate in our relayer. It has an abigen!() macro, which generates starknet types based on the ABI JSON file.

Do you prefer us to import that dependency and to maintain an ABI JSON file, or for us to leave the types in this folder? If we do use cainome - we'll delete all the types apart from StarknetMessage and use the generated ones. Else - we keep the types in this PR and only update if needed (rare to never).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check this commit, in which I moved part of the modules to ampd and renamed starknet-types to starknet-message, keeping it in /packages, because it's used in the prover.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah the prover code should live in your fork, and I'd prefer not to make changes to this repo that only really make sense for your fork. It makes things confusing. Eventually we will refactor ampd as well, so that starknet specific ampd code can also live in your fork as well.

I actually think I prefer the generated types. Can you try that and we see how it looks?

Copy link
Contributor Author

@ctoyan ctoyan Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will require quite a refactor. Is it ok if we leave that for the optimisations phase of the project?

What has to be done to remove the files in the new /types folder:

  • the cainome library will be included as a dependency.
  • the ABI json file of the gateway contract will be added and needs to be kept up to date.
  • we pass that file to the abigen!() macro.
  • it generates a lot of code, including an RPC client for the contract to which the ABI json corresponds (the gateway contract). In ampd we need at most 5% of what it will generate.
  • we substitute the ContractCall, SignersRotated and ByteArray types with the generated ones.
  • remove current implementations and fix all tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit for removing starknet-message

ampd/src/lib.rs Outdated Show resolved Hide resolved
ampd/src/lib.rs Outdated Show resolved Hide resolved
ampd/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines 148 to 152
Some(gateway_event) => {
votes.push(verify_msg(&gateway_event, msg, &source_gateway_address));
}

None => votes.push(Vote::NotFound),
Copy link
Contributor

@cjcobb23 cjcobb23 Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't you just move this logic inside of the above map over unique_msgs? And then just generate the corresponding vote immediately after getting the event. There's no need for the events collection then. This seems a bit uneccessary to iterate twice like this, and to use mutable collections.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense, yes. I mechanically changed the previous one.
It this better? (commit)


let transaction_response = self
.rpc_client
.get_event_by_hash_signers_rotated(verifier_set.message_id.tx_hash.clone())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct me if I'm wrong, but it looks like the event index of the message id is being discarded? So one could put any value there, as long as the tx hash is correct. Is that right? If so, we should change that and also verify the event index

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We reworked it to also accept the message_id and get the event by it's index.
You can check this commit for the change.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed thank you 🙏

ctoyan and others added 5 commits January 29, 2025 17:33
…fier set (#58)

* take into account index on checking for events in verify verifier set

* remove useless tuple with felt and event; now its only event

* fix functions name for verifier set and verify contract call

* return None on verify verifier set, if something went wrong / remove result and some errors that applied to prev scenario

* simplify logic of verify verifier set
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.

3 participants