]> git.ardis.lu - solc-metadata/commitdiff
Support Vyper in extractCBOR for future use
authorArdis Lu <ardisglu@gmail.com>
Sat, 7 Oct 2023 03:57:35 +0000 (20:57 -0700)
committerArdis Lu <ardisglu@gmail.com>
Sat, 7 Oct 2023 03:57:35 +0000 (20:57 -0700)
index.js

index 0f26a7b4a9ff77f96ec351e10c41c64aece2f6d2..865677b405dcb1b2e3377666d83ad29ffe995a1e 100644 (file)
--- a/index.js
+++ b/index.js
@@ -17,12 +17,13 @@ async function fetchBytecode(address, rpc) {
     .then(obj => obj.result);
 }
 
-function extractCBOR(bytecode) {
+function extractCBOR(bytecode, lang = 'solidity') {
   // The length of the CBOR will always be stored as the last two bytes of the runtime bytecode
   const cborLen = parseInt(bytecode.slice(-4), 16);
 
   // Derive the CBOR by counting backwards from the end (minus the last two bytes)
-  const cbor = bytecode.substring(bytecode.length - 4 - cborLen * 2, bytecode.length - 4);
+  // IMPORTANT: Vyper INCLUDES the last two bytes in the byte length, unlike Solidity!
+  const cbor = bytecode.substring(bytecode.length - (lang === 'solidity' ? 4 : 0) - cborLen * 2, bytecode.length - 4);
 
   // Convert to a byte array for easier use in subsequent processing
   const byteArray = cbor.match(/.{2}/g).map(v => parseInt(v, 16));
This page took 0.0366 seconds and 4 git commands to generate.