Skip to content

Conversation

@linh2931
Copy link
Contributor

Enforce on chain configuration parameter max_sync_call_depth for nested and recursive sync calls. Once the depth is reached, the call is aborted.

Notable things about the two new two tests for the PR:

  1. One test has one function making sync calls to itself recursively, another has two functions on different accounts calling each other recursively. Both tests show sync calls work correctly when max depth is not reached, and calls are aborted when max depth is reached.

  2. The test WASM contracts utilize sender and receiver arguments from sync_call entry point, which demonstrates those two arguments are set correctly.

Resolves #1268

@linh2931 linh2931 requested review from heifner and spoonincode March 27, 2025 21:40
// If the call is initiated from an apply_context (an action), it is the first
// level of a sync call by the action, set the depth to 1.
// Otherwise the call is from another sync call, increment the depth by 1.
const uint32_t depth = dynamic_cast<apply_context*>(this) ? 1 : sync_call_depth + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should refactor to remove this dynamic_cast. Can't you just pass in the depth instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it can be removed because sync_call_depth default initial value is 0. Now the code is cleaner. Thanks.

c37b00d

@linh2931 linh2931 merged commit be05a87 into refactor_apply_context Apr 3, 2025
36 checks passed
@linh2931 linh2931 deleted the enforce_max_call_depth branch April 3, 2025 16:37
@linh2931 linh2931 linked an issue Apr 3, 2025 that may be closed by this pull request
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.

SC: Enforce max_sync_call_depth

3 participants