{"id":41940847,"url":"https://github.com/playmint/lallafa","last_synced_at":"2026-01-25T18:37:35.439Z","repository":{"id":45390375,"uuid":"513504486","full_name":"playmint/lallafa","owner":"playmint","description":"An EVM gas profiling tool written in Typescript.","archived":false,"fork":false,"pushed_at":"2022-09-01T11:19:03.000Z","size":337,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-18T02:27:16.441Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/playmint.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-13T12:02:25.000Z","updated_at":"2023-05-30T16:05:16.000Z","dependencies_parsed_at":"2022-08-20T13:31:06.969Z","dependency_job_id":null,"html_url":"https://github.com/playmint/lallafa","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/playmint/lallafa","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/playmint%2Flallafa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/playmint%2Flallafa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/playmint%2Flallafa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/playmint%2Flallafa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/playmint","download_url":"https://codeload.github.com/playmint/lallafa/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/playmint%2Flallafa/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28756442,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T16:32:25.380Z","status":"ssl_error","status_checked_at":"2026-01-25T16:32:09.189Z","response_time":113,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-25T18:37:35.345Z","updated_at":"2026-01-25T18:37:35.432Z","avatar_url":"https://github.com/playmint.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://raw.githubusercontent.com/playmint/lallafa/main/lallafa.jfif\" width=\"300\" height=\"300\"/\u003e\n\n[![NPM Package](https://img.shields.io/npm/v/@playmint/lallafa.svg?style=flat-square)](https://www.npmjs.com/package/@playmint/lallafa)\n---\n# Lallafa\nAn EVM gas profiling tool written in Typescript.\n\n## Installation\n`npm install --save-dev @playmint/lallafa`\n\n## How it works\nLallafa produces a gas usage report by ingesting a debug trace, along with some compiler input and output. It outputs profiling data which is collated at both the instruction level, and the line-of-code level.\n\n## How to use\nTo profile a transaction, use `profile`:\n```ts\nfunction profile(trace: DebugTrace, isDeploymentTransaction: boolean, address: string, contracts: ContractInfoMap)\n```\n* trace - a debug trace generated by a node using `debug_traceTransaction`\n* isDeploymentTransaction - is the tx the deployment of the contract, determines which bytecode the profiler will use\n* address - address of the contract where the transaction originated, needed for properly profiling re-entrant calls\n* contracts - map of `address` =\u003e `ContractInfo`\n```ts\ntype ContractInfo = {\n    // standard input JSON\n    input: CompilerInput;\n\n    // standard output JSON\n    output?: CompilerOutput;\n\n    // if output is omitted, Lallafa will attempt to compile the contract from input. If you do this\n    // then solcVersion needs to be defined\n    solcVersion?: string;\n\n    // name of source file which contains the contract definition\n    sourceName: string;\n\n    // name of contract within the source file\n    contractName: string;\n};\n```\n\n`profile` returns a `Profile` object, which maps contract address to an object containing an instruction profile and a source profile:\n```ts\ntype Profile = {\n    [address: string]: {\n        instructionsProfile: InstructionProfile[];\n        sourcesProfile: SourcesProfile;\n    }\n};\n\ntype InstructionProfile = {\n    // gas spent\n    gas: number;\n    // bytecode hex string \n    bytecode: string;\n    // op, arg if any, jumpdest name if relevant\n    asm: string;\n    // program counter\n    pc: number;\n    // opcode as string, e.g. ISZERO, PUSH1, etc\n    op: string;\n    // id of source this instruction was generated from\n    sourceId: number;\n    sourceRangeStart: number;\n    sourceRangeLength: number;\n    // line of code where this source range starts (0 being the first line)\n    sourceLine: number;\n};\n\ntype SourcesProfile = {\n    [sourceId: number]: {\n        name: string;\n        content: string;\n        lines: {\n            // gas spent\n            gas: number;\n            text: string;\n            // instructions generated from this line of code\n            instructions: InstructionProfile[]\n        }[];\n    }\n};\n```\nYou might choose to visualise profiles in a bespoke way, but you can use `instructionsProfileToString` and `sourcesProfileToString` to quickly do so.\n\n## Example\nCheck out the [test](https://github.com/playmint/lallafa/tree/main/test) project for detailed examples.\n\nHere's a way to profile a simple contract\nStorage.sol:\n```solidity\n//SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.0;\n\ncontract Storage {\n    uint256 _value;\n\n    function setValue(uint256 value) public {\n        _value = value;\n    }\n}\n```\nprofileStorage.ts:\n```ts\nimport hre from \"hardhat\";\nimport { Storage__factory } from \"../typechain-types\";\nimport fs from \"fs\";\nimport { profile, sourcesProfileToString, instructionsProfileToString, ContractInfoMap } from \"../../src\";\n\n\nasync function main() {\n    const storageFactory = new Storage__factory((await hre.ethers.getSigners())[0]);\n    const storage = await storageFactory.deploy();\n    const tx = await (await storage.setValue(42)).wait();\n    const debugTrace = await hre.ethers.provider.send(\"debug_traceTransaction\",\n        [tx.transactionHash, {\n            \"disableStack\": true,\n            \"disableMemory\": true,\n            \"disableStorage\": true\n        }]);\n\n    const buildInfo = await hre.artifacts.getBuildInfo(\"contracts/Storage.sol:Storage\");\n    if (!buildInfo) {\n        throw new Error(\"couldn't find build info\");\n    }\n\n    const contracts: ContractInfoMap = {}\n    contracts[storage.address] = {\n        input: buildInfo.input,\n        output: buildInfo.output,\n        sourceName: \"contracts/Storage.sol\",\n        contractName: \"Storage\"\n    };\n\n    // or if you want Lallafa to compile from input\n    /*\n    contracts[storage.address] = {\n        input: buildInfo.input,\n        solcVersion: buildInfo.solcLongVersion,\n        sourceName: \"contracts/Storage.sol\",\n        contractName: \"Storage\"\n    };\n    */\n\n    const result = await profile(\n        debugTrace,\n        false, // isDeployment\n        storage.address,\n        contracts);\n\n    fs.writeFileSync(\"sources_profile.txt\", sourcesProfileToString(result));\n    fs.writeFileSync(\"instruction_profile.txt\", instructionsProfileToString(result));\n}\n\nmain().catch(e =\u003e console.error(e));\n```\nThis script outputs profiles of both the source code and the asm instructions to show what these both look like.\nsources_profile.txt:\n```\n// 5FBDB2315678AFECB367F032D93F642F64180AA3\n============================================\n\n// contracts/Storage.sol\n\nGas   |\n---------------------------------------------------------------------------------------------------------------------------------------\n97    | //SPDX-License-Identifier: UNLICENSED\n0     | pragma solidity ^0.8.0;\n0     | \n0     | contract Storage {\n0     |     uint256 _value;\n0     | \n68    |     function setValue(uint256 value) public {\n22114 |         _value = value;\n0     |     }\n0     | }\n0     | \n\n// #utility.yul\n\nGas   |\n---------------------------------------------------------------------------------------------------------------------------------------\n0     | {\n0     | \n0     |     function allocate_unbounded() -\u003e memPtr {\n0     |         memPtr := mload(64)\n0     |     }\n0     | \n0     |     function revert_error_dbdddcbe895c83990c08b3492a0e83918d802a52331272ac6fdb6a7c4aea3b1b() {\n0     |         revert(0, 0)\n0     |     }\n0     | \n0     |     function revert_error_c1322bf8034eace5e0b5c7295db60986aa89aae5e0ea0873e4689e076861a5db() {\n0     |         revert(0, 0)\n0     |     }\n0     | \n20    |     function cleanup_t_uint256(value) -\u003e cleaned {\n8     |         cleaned := value\n0     |     }\n0     | \n11    |     function validator_revert_t_uint256(value) {\n38    |         if iszero(eq(value, cleanup_t_uint256(value))) { revert(0, 0) }\n0     |     }\n0     | \n22    |     function abi_decode_t_uint256(offset, end) -\u003e value {\n11    |         value := calldataload(offset)\n18    |         validator_revert_t_uint256(value)\n0     |     }\n0     | \n22    |     function abi_decode_tuple_t_uint256(headStart, dataEnd) -\u003e value0 {\n32    |         if slt(sub(dataEnd, headStart), 32) { revert_error_dbdddcbe895c83990c08b3492a0e83918d802a52331272ac6fdb6a7c4aea3b1b() }\n0     | \n2     |         {\n0     | \n3     |             let offset := 0\n0     | \n32    |             value0 := abi_decode_t_uint256(add(headStart, offset), dataEnd)\n0     |         }\n0     | \n0     |     }\n0     | \n0     | }\n0     | \n\n\n```\ninstructions_profile.txt:\n```\n// 5FBDB2315678AFECB367F032D93F642F64180AA3\n============================================\n\nGas   | PC | Asm                                                                                          | Bytecode\n------------------------------------------------------------------------------------------------------------------------\n3     | 0  | PUSH1 0x80                                                                                   | 0x6080\n3     | 2  | PUSH1 0x40                                                                                   | 0x6040\n12    | 4  | MSTORE                                                                                       | 0x52\n2     | 5  | CALLVALUE                                                                                    | 0x34\n3     | 6  | DUP1                                                                                         | 0x80\n3     | 7  | ISZERO                                                                                       | 0x15\n3     | 8  | PUSH1 0xF                                                                                    | 0x600F\n10    | A  | JUMPI [in]                                                                                   | 0x57\n0     | B  | PUSH1 0x0                                                                                    | 0x6000\n0     | D  | DUP1                                                                                         | 0x80\n0     | E  | REVERT                                                                                       | 0xFD\n1     | F  | JUMPDEST                                                                                     | 0x5B\n2     | 10 | POP                                                                                          | 0x50\n3     | 11 | PUSH1 0x4                                                                                    | 0x6004\n2     | 13 | CALLDATASIZE                                                                                 | 0x36\n3     | 14 | LT                                                                                           | 0x10\n3     | 15 | PUSH1 0x28                                                                                   | 0x6028\n10    | 17 | JUMPI [in]                                                                                   | 0x57\n3     | 18 | PUSH1 0x0                                                                                    | 0x6000\n3     | 1A | CALLDATALOAD                                                                                 | 0x35\n3     | 1B | PUSH1 0xE0                                                                                   | 0x60E0\n3     | 1D | SHR                                                                                          | 0x1C\n3     | 1E | DUP1                                                                                         | 0x80\n3     | 1F | PUSH4 0x55241077                                                                             | 0x6355241077\n3     | 24 | EQ                                                                                           | 0x14\n3     | 25 | PUSH1 0x2D [setValue_uint256_0]                                                              | 0x602D\n10    | 27 | JUMPI [in]                                                                                   | 0x57\n0     | 28 | JUMPDEST                                                                                     | 0x5B\n0     | 29 | PUSH1 0x0                                                                                    | 0x6000\n0     | 2B | DUP1                                                                                         | 0x80\n0     | 2C | REVERT                                                                                       | 0xFD\n1     | 2D | JUMPDEST [setValue_uint256_0]                                                                | 0x5B\n3     | 2E | PUSH1 0x43                                                                                   | 0x6043\n3     | 30 | PUSH1 0x4                                                                                    | 0x6004\n3     | 32 | DUP1                                                                                         | 0x80\n2     | 33 | CALLDATASIZE                                                                                 | 0x36\n3     | 34 | SUB                                                                                          | 0x03\n3     | 35 | DUP2                                                                                         | 0x81\n3     | 36 | ADD                                                                                          | 0x01\n3     | 37 | SWAP1                                                                                        | 0x90\n3     | 38 | PUSH1 0x3F                                                                                   | 0x603F\n3     | 3A | SWAP2                                                                                        | 0x91\n3     | 3B | SWAP1                                                                                        | 0x90\n3     | 3C | PUSH1 0x85 [abi_decode_tuple_t_uint256_0]                                                    | 0x6085\n8     | 3E | JUMP [in]                                                                                    | 0x56\n1     | 3F | JUMPDEST [setValue_uint256_1]                                                                | 0x5B\n3     | 40 | PUSH1 0x45 [setValue_uint256_3]                                                              | 0x6045\n8     | 42 | JUMP [in]                                                                                    | 0x56\n1     | 43 | JUMPDEST [setValue_uint256_2]                                                                | 0x5B\n0     | 44 | STOP                                                                                         | 0x00\n1     | 45 | JUMPDEST [setValue_uint256_3]                                                                | 0x5B\n3     | 46 | DUP1                                                                                         | 0x80\n3     | 47 | PUSH1 0x0                                                                                    | 0x6000\n3     | 49 | DUP2                                                                                         | 0x81\n3     | 4A | SWAP1                                                                                        | 0x90\n22100 | 4B | SSTORE                                                                                       | 0x55\n2     | 4C | POP                                                                                          | 0x50\n2     | 4D | POP                                                                                          | 0x50\n8     | 4E | JUMP [out]                                                                                   | 0x56\n0     | 4F | JUMPDEST [revert_error_dbdddcbe895c83990c08b3492a0e83918d802a52331272ac6fdb6a7c4aea3b1b_0]   | 0x5B\n0     | 50 | PUSH1 0x0                                                                                    | 0x6000\n0     | 52 | DUP1                                                                                         | 0x80\n0     | 53 | REVERT                                                                                       | 0xFD\n1     | 54 | JUMPDEST [cleanup_t_uint256_0]                                                               | 0x5B\n3     | 55 | PUSH1 0x0                                                                                    | 0x6000\n3     | 57 | DUP2                                                                                         | 0x81\n3     | 58 | SWAP1                                                                                        | 0x90\n2     | 59 | POP                                                                                          | 0x50\n3     | 5A | SWAP2                                                                                        | 0x91\n3     | 5B | SWAP1                                                                                        | 0x90\n2     | 5C | POP                                                                                          | 0x50\n8     | 5D | JUMP [out]                                                                                   | 0x56\n1     | 5E | JUMPDEST [validator_revert_t_uint256_0]                                                      | 0x5B\n3     | 5F | PUSH1 0x65                                                                                   | 0x6065\n3     | 61 | DUP2                                                                                         | 0x81\n3     | 62 | PUSH1 0x54 [cleanup_t_uint256_0]                                                             | 0x6054\n8     | 64 | JUMP [in]                                                                                    | 0x56\n1     | 65 | JUMPDEST [validator_revert_t_uint256_1]                                                      | 0x5B\n3     | 66 | DUP2                                                                                         | 0x81\n3     | 67 | EQ                                                                                           | 0x14\n3     | 68 | PUSH1 0x6F [validator_revert_t_uint256_2]                                                    | 0x606F\n10    | 6A | JUMPI [in]                                                                                   | 0x57\n0     | 6B | PUSH1 0x0                                                                                    | 0x6000\n0     | 6D | DUP1                                                                                         | 0x80\n0     | 6E | REVERT                                                                                       | 0xFD\n1     | 6F | JUMPDEST [validator_revert_t_uint256_2]                                                      | 0x5B\n2     | 70 | POP                                                                                          | 0x50\n8     | 71 | JUMP [out]                                                                                   | 0x56\n1     | 72 | JUMPDEST [abi_decode_t_uint256_0]                                                            | 0x5B\n3     | 73 | PUSH1 0x0                                                                                    | 0x6000\n3     | 75 | DUP2                                                                                         | 0x81\n3     | 76 | CALLDATALOAD                                                                                 | 0x35\n3     | 77 | SWAP1                                                                                        | 0x90\n2     | 78 | POP                                                                                          | 0x50\n3     | 79 | PUSH1 0x7F                                                                                   | 0x607F\n3     | 7B | DUP2                                                                                         | 0x81\n3     | 7C | PUSH1 0x5E [validator_revert_t_uint256_0]                                                    | 0x605E\n8     | 7E | JUMP [in]                                                                                    | 0x56\n1     | 7F | JUMPDEST [abi_decode_t_uint256_1]                                                            | 0x5B\n3     | 80 | SWAP3                                                                                        | 0x92\n3     | 81 | SWAP2                                                                                        | 0x91\n2     | 82 | POP                                                                                          | 0x50\n2     | 83 | POP                                                                                          | 0x50\n8     | 84 | JUMP [out]                                                                                   | 0x56\n1     | 85 | JUMPDEST [abi_decode_tuple_t_uint256_0]                                                      | 0x5B\n3     | 86 | PUSH1 0x0                                                                                    | 0x6000\n3     | 88 | PUSH1 0x20                                                                                   | 0x6020\n3     | 8A | DUP3                                                                                         | 0x82\n3     | 8B | DUP5                                                                                         | 0x84\n3     | 8C | SUB                                                                                          | 0x03\n3     | 8D | SLT                                                                                          | 0x12\n3     | 8E | ISZERO                                                                                       | 0x15\n3     | 8F | PUSH1 0x98 [abi_decode_tuple_t_uint256_2]                                                    | 0x6098\n10    | 91 | JUMPI [in]                                                                                   | 0x57\n0     | 92 | PUSH1 0x97                                                                                   | 0x6097\n0     | 94 | PUSH1 0x4F [revert_error_dbdddcbe895c83990c08b3492a0e83918d802a52331272ac6fdb6a7c4aea3b1b_0] | 0x604F\n0     | 96 | JUMP [in]                                                                                    | 0x56\n0     | 97 | JUMPDEST [abi_decode_tuple_t_uint256_1]                                                      | 0x5B\n1     | 98 | JUMPDEST [abi_decode_tuple_t_uint256_2]                                                      | 0x5B\n3     | 99 | PUSH1 0x0                                                                                    | 0x6000\n3     | 9B | PUSH1 0xA4                                                                                   | 0x60A4\n3     | 9D | DUP5                                                                                         | 0x84\n3     | 9E | DUP3                                                                                         | 0x82\n3     | 9F | DUP6                                                                                         | 0x85\n3     | A0 | ADD                                                                                          | 0x01\n3     | A1 | PUSH1 0x72 [abi_decode_t_uint256_0]                                                          | 0x6072\n8     | A3 | JUMP [in]                                                                                    | 0x56\n1     | A4 | JUMPDEST [abi_decode_tuple_t_uint256_3]                                                      | 0x5B\n3     | A5 | SWAP2                                                                                        | 0x91\n2     | A6 | POP                                                                                          | 0x50\n2     | A7 | POP                                                                                          | 0x50\n3     | A8 | SWAP3                                                                                        | 0x92\n3     | A9 | SWAP2                                                                                        | 0x91\n2     | AA | POP                                                                                          | 0x50\n2     | AB | POP                                                                                          | 0x50\n8     | AC | JUMP [out]                                                                                   | 0x56\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplaymint%2Flallafa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplaymint%2Flallafa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplaymint%2Flallafa/lists"}