(script: Script, optimisations: string[][])
| 240 | } |
| 241 | |
| 242 | function 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 | |
| 268 | interface ReplaceOpsResult { |
| 269 | script: Script; |
no test coverage detected