-
Notifications
You must be signed in to change notification settings - Fork 5
Opcode count compute limits #91
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5e979f3
implement compute limits for seperate opcode groups
msinkec a2e0736
make opcode limits configurable and simplify model to a simple lookup…
msinkec 74275cf
handle empty config vals, nil param and simplify
msinkec 0cec6ef
merge config vals with default vals and address other issues
msinkec f368921
address PR comments
msinkec 67dbd8a
add zero limit test
msinkec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package arkade | ||
|
|
||
| import "fmt" | ||
|
|
||
| // ComputeLimits maps an opcode to the maximum number of times it may execute | ||
| // during a single input's script evaluation. Opcodes absent from the map are | ||
| // unlimited, matching tapscript's lack of an op-count limit for the cheap | ||
| // opcodes whose per-call cost is negligible. | ||
| type ComputeLimits map[byte]int | ||
|
|
||
| // Validate reports whether every configured limit is non-negative. | ||
| func (c ComputeLimits) Validate() error { | ||
| for op, limit := range c { | ||
| if limit < 0 { | ||
| return fmt.Errorf("compute limit for %s is negative: %d", | ||
| opcodeArray[op].name, limit) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // DefaultComputeLimits returns the canonical per-input execution caps for the | ||
| // heavy opcodes. It returns a fresh map so callers may modify their copy | ||
| // without affecting the engine default. | ||
| func DefaultComputeLimits() ComputeLimits { | ||
| // Aggregate-cost note: this table is deliberately a simple per-opcode | ||
| // lookup, not a grouped or weighted budget. If every listed opcode is pushed | ||
| // to its independent cap, the measured heavy-opcode aggregate is ~37 ms per | ||
| // input on an Apple M4 Pro. That is looser than the ~24 ms grouped design, | ||
| // but keeps the policy easy to read, configure, and reason about for now. | ||
| return ComputeLimits{ | ||
| // Schnorr-class signature verification, ~84 µs each. | ||
| OP_CHECKSIG: 50, | ||
| OP_CHECKSIGVERIFY: 50, | ||
| OP_CHECKSIGADD: 50, | ||
| OP_CHECKSIGFROMSTACK: 50, | ||
| // Elliptic-curve point operations. | ||
| OP_ECADD: 1000, // ~3.7 µs | ||
| OP_ECMUL: 50, // ~84 µs | ||
| OP_ECMULSCALARVERIFY: 50, // ~84 µs | ||
| OP_TWEAKVERIFY: 50, // ~84 µs | ||
| OP_ECPAIRING: 2, // ~2.04 ms at the 16-pair cap | ||
| OP_MODEXP: 64, // ~60 µs at the 64-byte operand cap | ||
| } | ||
| } | ||
|
|
||
| func cloneComputeLimits(c ComputeLimits) ComputeLimits { | ||
| if c == nil { | ||
| return nil | ||
| } | ||
| clone := make(ComputeLimits, len(c)) | ||
| for op, limit := range c { | ||
| clone[op] = limit | ||
| } | ||
| return clone | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.