MCPcopy Create free account
hub / github.com/ElementsProject/elements / predict_sigops_ratio

Function predict_sigops_ratio

test/functional/feature_taproot.py:1093–1109  ·  view source on GitHub ↗

Predict whether spending fn(n, pubkey) with dummy_size will pass the ratio test.

(n, dummy_size)

Source from the content-addressed store, hash-verified

1091
1092
1093 def predict_sigops_ratio(n, dummy_size):
1094 """Predict whether spending fn(n, pubkey) with dummy_size will pass the ratio test."""
1095 script, sigops = fn(n, pubkey)
1096 # Predict the size of the witness for a given choice of n
1097 stacklen_size = 1
1098 sig_size = 64 + (hashtype != SIGHASH_DEFAULT)
1099 siglen_size = 1
1100 dummylen_size = 1 + 2 * (dummy_size >= 253)
1101 script_size = len(script)
1102 scriptlen_size = 1 + 2 * (script_size >= 253)
1103 control_size = 33 + 32 * merkledepth
1104 controllen_size = 1 + 2 * (control_size >= 253)
1105 annex_size = 0 if annex is None else len(annex)
1106 annexlen_size = 0 if annex is None else 1 + 2 * (annex_size >= 253)
1107 witsize = stacklen_size + sig_size + siglen_size + dummy_size + dummylen_size + script_size + scriptlen_size + control_size + controllen_size + annex_size + annexlen_size
1108 # sigops ratio test
1109 return witsize + 50 >= 50 * sigops
1110 # Make sure n is high enough that with empty dummy, the script is not valid
1111 n = 0
1112 while predict_sigops_ratio(n, 0):

Callers 1

spenders_taproot_activeFunction · 0.85

Calls 1

fnFunction · 0.85

Tested by

no test coverage detected