MCPcopy Index your code
hub / github.com/CashScript/cashscript / computeBytecodePattern

Function computeBytecodePattern

packages/utils/src/fingerprint.ts:15–21  ·  view source on GitHub ↗
(bytecode: Uint8Array)

Source from the content-addressed store, hash-verified

13// consecutive push instructions is replaced by a single push of the run length.
14// See: https://gitlab.com/0353F40E/smart-contract-fingerprinting/
15export function computeBytecodePattern(bytecode: Uint8Array): Uint8Array {
16 const opcodes = decodeAuthenticationInstructions(bytecode).map((instruction) => instruction.opcode);
17 const chunks = groupByPushRun(opcodes).map((run) => (
18 isPushOpcode(run[0]) ? encodePushCount(run.length) : Uint8Array.from(run)
19 ));
20 return flattenBinArray(chunks);
21}
22
23// Split opcodes into consecutive runs that are either all pushes or all non-pushes.
24function groupByPushRun(opcodes: Op[]): Op[][] {

Callers 2

Calls 3

groupByPushRunFunction · 0.85
isPushOpcodeFunction · 0.85
encodePushCountFunction · 0.85

Tested by

no test coverage detected