Skip to content
This repository has been archived by the owner on Jan 17, 2022. It is now read-only.

Use linear time algorithm to inject stack height metering #170

Merged
merged 1 commit into from
Sep 7, 2021

Conversation

athei
Copy link
Member

@athei athei commented Sep 7, 2021

The current algorithm to inject the preamble and postamble for call instructions has quadratic complexity:

O(number_call_instructions_in_function * number_instructions_in_function)

This is because the splice function needs to copy around the Vec of instructions for every call instruction. A function can consist of only calls. This was evident when experimenting with different benchmarks. This PR replaces this by a linear algorithm. The benchmark in question went from 20secs to 1sec runtime.

Please note that leaving this unfixed is a DoS vector when the stack height metering is applied to untrusted code.

Copy link
Contributor

@pepyakin pepyakin left a comment

Choose a reason for hiding this comment

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

This looks sensible.

@athei athei merged commit 2293760 into master Sep 7, 2021
@athei athei deleted the at-fix-stack-height-complexity branch September 7, 2021 15:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants