* Compares the executable sections of the deployed and compiled bytecode, * ignoring differences in metadata, library link references, immutable * variables, and call protection placeholders. * * This is necessary because deployed bytecode contains dynamically inserted * values (e.g.
(compilerOutputBytecode: CompilerOutputBytecode)
| 91 | * equivalent, `false` otherwise. |
| 92 | */ |
| 93 | public compare(compilerOutputBytecode: CompilerOutputBytecode): boolean { |
| 94 | const unlinkedExecutableSection = inferExecutableSection( |
| 95 | compilerOutputBytecode.object, |
| 96 | ); |
| 97 | |
| 98 | // If the lengths differ, the bytecodes cannot match, so we can return early |
| 99 | if (this.executableSection.length !== unlinkedExecutableSection.length) { |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | const normalizedBytecode = nullifyBytecodeOffsets( |
| 104 | this.executableSection, |
| 105 | compilerOutputBytecode, |
| 106 | ); |
| 107 | |
| 108 | const normalizedUnlinkedBytecode = nullifyBytecodeOffsets( |
| 109 | unlinkedExecutableSection, |
| 110 | compilerOutputBytecode, |
| 111 | ); |
| 112 | |
| 113 | return normalizedBytecode === normalizedUnlinkedBytecode; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /** |
no test coverage detected