MCPcopy Create free account
hub / github.com/CashScript/cashscript / replaceOpsOld

Function replaceOpsOld

packages/utils/src/script.ts:242–266  ·  view source on GitHub ↗
(script: Script, optimisations: string[][])

Source from the content-addressed store, hash-verified

240}
241
242function replaceOpsOld(script: Script, optimisations: string[][]): Script {
243 let asm = scriptToAsm(script);
244
245 // Apply all optimisations in the cashproof file
246 optimisations.forEach(([pattern, replacement]) => {
247 asm = asm.replace(new RegExp(pattern, 'g'), replacement);
248 });
249
250 // Add optimisations that are not compatible with CashProof
251 // CashProof can't prove OP_IF without parameters
252 asm = asm.replace(/OP_NOT OP_IF/g, 'OP_NOTIF');
253 // CashProof can't prove OP_CHECKMULTISIG without specifying N
254 asm = asm.replace(/OP_CHECKMULTISIG OP_VERIFY/g, 'OP_CHECKMULTISIGVERIFY');
255 // CashProof can't prove bitwise operators
256 asm = asm.replace(/OP_SWAP OP_AND/g, 'OP_AND');
257 asm = asm.replace(/OP_SWAP OP_OR/g, 'OP_OR');
258 asm = asm.replace(/OP_SWAP OP_XOR/g, 'OP_XOR');
259 asm = asm.replace(/OP_DUP OP_AND/g, '');
260 asm = asm.replace(/OP_DUP OP_OR/g, '');
261
262 // Remove any double spaces as a result of opcode removal
263 asm = asm.replace(/\s+/g, ' ').trim();
264
265 return asmToScript(asm);
266}
267
268interface ReplaceOpsResult {
269 script: Script;

Callers 1

optimiseBytecodeOldFunction · 0.85

Calls 2

scriptToAsmFunction · 0.85
asmToScriptFunction · 0.85

Tested by

no test coverage detected