From 2b3a3f1a596b0cbfdf223fe08ca38b3804667ab3 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Fri, 6 Oct 2023 20:57:35 -0700 Subject: [PATCH] Support Vyper in extractCBOR for future use --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 0f26a7b..865677b 100644 --- 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)); -- 2.47.3