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

[Solana][NONEVM-1028] Deduplicate accounts in execution #477

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

Conversation

PabloMansanet
Copy link
Contributor

No description provided.

@PabloMansanet PabloMansanet requested a review from a team as a code owner January 21, 2025 10:16
Copy link
Contributor

@agusaldasoro agusaldasoro left a comment

Choose a reason for hiding this comment

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

We need to ensure that the hash of the message is the same offchain and onchain. Saving space for those values in the extra args message means that the offchain code will need to hash the message with those values in, and then remove them to send the message through the contract. Then the program will need to do the same but the other way out, adding them on the hash.
If you feel that the saved space is worth it we could do this change, but if not it feels like a possible UX concern of the protocol, as all the nodes will need to sign a message with those values in, but then the message sent through is different.

@agusaldasoro agusaldasoro self-requested a review January 21, 2025 15:56
@PabloMansanet
Copy link
Contributor Author

CC @aalu1418 after our sync discussion yesterday on how to proceed with this 🙂

@PabloMansanet PabloMansanet force-pushed the deduplicate_accounts branch 3 times, most recently from 741a4fc to 614f00b Compare January 23, 2025 09:39
Copy link
Contributor

@agusaldasoro agusaldasoro left a comment

Choose a reason for hiding this comment

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

Let's keep the serialization of the accounts inside the hash, with this change the hash values should remain the same.

Can you add a test validating that when sending different accounts in remaining accounts to the ones in the hash then execution fails? So that way we can check that there is no override of the accounts

@PabloMansanet PabloMansanet force-pushed the deduplicate_accounts branch 3 times, most recently from 66d5e3b to 5772fce Compare January 24, 2025 15:35
Copy link
Contributor

@agusaldasoro agusaldasoro left a comment

Choose a reason for hiding this comment

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

Excelent work!

Can we add tests (as I don't think we have that already covered) for:

  • Sending the correct accounts but a wrong bitmap for writable
  • Hashing some accounts different than the ones sent in the transaction

Comment on lines +466 to +467
sender: execution_report.message.sender.clone(),
data: execution_report.message.data.clone(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you need that here? Does it help with the memory usage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's just because moving the verify_merkle_root later in the function causes a borrow of a partially moved value: without the clone, part of execution_report would've moved out here.

&execution_report.message.logic_receiver,
ctx.remaining_accounts.is_empty(),
) {
let hashed_leaf = if should_execute_messaging(ctx.remaining_accounts, token_indexes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

token_indices: &[u8],
) -> bool {
// The first entry in the accounts corresponds to a token, which means there is no logic receiver
let only_tokens = token_indices.first().map(|i| *i == 0).unwrap_or_default();
Copy link
Contributor

Choose a reason for hiding this comment

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

does the unwrap_or_default defaults to false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep it does! So if there are no token indices, this would be false.

Remove unneeded field

Rework test comment

Update test hash

deduplicate logic receiver

Fix execution check

Address review comments

Hash accounts separately

Fix more tests

Don't hash token accounts

[CCIP-4938] Use map instead of slice in token price observations and outcome (#498)

* check number of observed timestamps is at least 2f+1

* Change token price processor to observe feed tokens as a map instead of slice

Using maps instead of slices make it sure that no duplicates can be added.

Apply comment suggestions

Co-authored-by: Agustina Aldasoro <[email protected]>
@PabloMansanet
Copy link
Contributor Author

@agusaldasoro addressed your review comments and added the tests you mentioned, PTAL when you have a moment :)

Copy link

Metric deduplicate_accounts main
Coverage 76.4% 76.4%

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.

2 participants