Skip to content

Conversation

@alex-mysten
Copy link
Contributor

@alex-mysten alex-mysten commented Nov 4, 2025

Description

Merge AccumulatorWriteV1 objects in temporary_store. This allows authenticated events to be indexed correctly in rpc_index and provides accurate transaction_effects.

Test plan

Address Balance and Authenticated Events tests added; they fail without this change.


Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • gRPC:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:

@vercel
Copy link

vercel bot commented Nov 4, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sui-docs Ready Ready Preview Comment Nov 15, 2025 11:50am
2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
multisig-toolkit Ignored Ignored Preview Nov 15, 2025 11:50am
sui-kiosk Ignored Ignored Preview Nov 15, 2025 11:50am

@alex-mysten alex-mysten temporarily deployed to sui-typescript-aws-kms-test-env November 4, 2025 15:27 — with GitHub Actions Inactive
@alex-mysten alex-mysten changed the title Merge AccumulatorEvents in temporary_store so that transaction effect… Merge AccumulatorEvents in temporary_store so that transaction effects are accurate Nov 4, 2025
@alex-mysten alex-mysten force-pushed the steka-aes-event-indexing-fix branch from 3fa273f to 8175d6b Compare November 4, 2025 15:53
@alex-mysten alex-mysten temporarily deployed to sui-typescript-aws-kms-test-env November 4, 2025 15:53 — with GitHub Actions Inactive
@alex-mysten alex-mysten force-pushed the steka-aes-event-indexing-fix branch from 8175d6b to 242bbd6 Compare November 4, 2025 16:03
@alex-mysten alex-mysten marked this pull request as ready for review November 4, 2025 16:04
@alex-mysten alex-mysten temporarily deployed to sui-typescript-aws-kms-test-env November 4, 2025 16:04 — with GitHub Actions Inactive
@alex-mysten alex-mysten temporarily deployed to sui-typescript-aws-kms-test-env November 4, 2025 16:04 — with GitHub Actions Inactive
};
let amount_u64 = amount
.try_into()
.expect("accumulator value overflow: merged amount exceeds u64::MAX");
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, i think this expect could be triggered by malicious code. You can create balance amounts of u64::max (not on a "real" currency, but nevertheless), and if you just do that twice you will overflow.

so we either have to use u128s in effects, or else detect the overflow during execution (at emit_accumulator_event in object_runtime.rs) and abort the transaction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added validation in emit_accumulator_event. I didn't do the merging here because it would have required changing the types in MoveAccumulatorValue and it seemed cleaner this way, happy to revisit this if you have a different opinion.

let mut merge_total = 0u128;
let mut split_total = 0u128;

for event in &self.state.accumulator_events {
Copy link
Contributor

Choose a reason for hiding this comment

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

This gives contracts the ability to cause quadratic execution time.

I'd prefer to track the running total in self.state, which should be simple enough, but if for some reason we can't do that, we should make sure there is a reasonable cap on max accumulator events and enforce it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed, moved to self.state

@alex-mysten alex-mysten force-pushed the steka-aes-event-indexing-fix branch from 10ea44d to b3eba0e Compare November 12, 2025 18:47
@alex-mysten alex-mysten temporarily deployed to sui-typescript-aws-kms-test-env November 12, 2025 18:47 — with GitHub Actions Inactive
//> 1: test::large_balance::create_holder();
//> TransferObjects([Result(0), Result(1)], Input(0))

//# run test::large_balance::send_large_balance --args object(2,0) @A 18446744073709551614 --sender A
Copy link
Contributor

Choose a reason for hiding this comment

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

before this, we should have a case that sends two large transfers in a single PTB, to test that it causes a move abort

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test added

//> 0: sui::balance::redeem_funds<test::large_balance::MARKER>(Input(0));
//> 1: sui::balance::redeem_funds<test::large_balance::MARKER>(Input(1));
//> 2: sui::balance::join<test::large_balance::MARKER>(Result(0), Result(1));
//> 3: sui::balance::send_funds<test::large_balance::MARKER>(Result(0), Input(2));
Copy link
Contributor

Choose a reason for hiding this comment

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

can we follow this up with a check that we can successfully withdraw the large amounts one at a time? Or do we already have that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test added

match w.operation {
//we validate that these do not overflow in object_runtime
AccumulatorOperation::Merge => (merge + v, split),
AccumulatorOperation::Split => (merge, split + v),
Copy link
Contributor

Choose a reason for hiding this comment

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

lets do merge.checked_add(v).expect("validated in object runtime")

(Or you can wrap the code with the checked_arithmetic! { ... } macro to rewrite it automatically)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used checked_add :)

Copy link
Contributor

@mystenmark mystenmark left a comment

Choose a reason for hiding this comment

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

approved with some small nits. thanks!

@alex-mysten alex-mysten force-pushed the steka-aes-event-indexing-fix branch from 068e6e2 to bfb71dd Compare November 15, 2025 11:48
@alex-mysten alex-mysten temporarily deployed to sui-typescript-aws-kms-test-env November 15, 2025 11:48 — with GitHub Actions Inactive
@alex-mysten alex-mysten merged commit 76f4ce9 into main Nov 17, 2025
56 checks passed
@alex-mysten alex-mysten deleted the steka-aes-event-indexing-fix branch November 17, 2025 17:36
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