(bytecode: Uint8Array)
| 13 | // consecutive push instructions is replaced by a single push of the run length. |
| 14 | // See: https://gitlab.com/0353F40E/smart-contract-fingerprinting/ |
| 15 | export 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. |
| 24 | function groupByPushRun(opcodes: Op[]): Op[][] { |
no test coverage detected