{"id":27103919,"url":"https://github.com/victorzhang2014/solidity-log3","last_synced_at":"2026-04-30T09:38:43.744Z","repository":{"id":164399233,"uuid":"639845008","full_name":"VictorZhang2014/solidity-log3","owner":"VictorZhang2014","description":"The Usage of log1,log2,log3 and log4 in Solidity based-on Yul Assembly Language","archived":false,"fork":false,"pushed_at":"2023-05-18T06:43:25.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-06T17:36:23.564Z","etag":null,"topics":["assembly","assembly-language","log1","log2","log3","log4","solidity","yul"],"latest_commit_sha":null,"homepage":"","language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VictorZhang2014.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-12T11:02:50.000Z","updated_at":"2023-05-15T09:57:14.000Z","dependencies_parsed_at":"2024-03-22T09:16:43.005Z","dependency_job_id":null,"html_url":"https://github.com/VictorZhang2014/solidity-log3","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/VictorZhang2014/solidity-log3","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorZhang2014%2Fsolidity-log3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorZhang2014%2Fsolidity-log3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorZhang2014%2Fsolidity-log3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorZhang2014%2Fsolidity-log3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VictorZhang2014","download_url":"https://codeload.github.com/VictorZhang2014/solidity-log3/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorZhang2014%2Fsolidity-log3/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32460781,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T22:27:22.272Z","status":"online","status_checked_at":"2026-04-30T02:00:05.929Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["assembly","assembly-language","log1","log2","log3","log4","solidity","yul"],"created_at":"2025-04-06T17:29:50.468Z","updated_at":"2026-04-30T09:38:43.739Z","avatar_url":"https://github.com/VictorZhang2014.png","language":"Solidity","funding_links":[],"categories":[],"sub_categories":[],"readme":"# The Usage of log1,log2,log3 and log4 in Solidity\n\u003cbr/\u003e\n\n#### Deployed Contract for testing: [0x2b1437da111b553cb1384d8d290b08820fd188eb](https://mumbai.polygonscan.com/address/0x2b1437da111b553cb1384d8d290b08820fd188eb)\n\u003cbr/\u003e\n\n#### Test Case for `log1` for emitting an event without any parameters\n```\t\nevent Fire();\n\nfunction test1(string memory n) external { \n  emit Fire();\n  \n  bytes32 e = keccak256(abi.encodePacked(n)); \n  assembly {   \n    log1(0x0, 0x0, e)    \n  }\n}\n```\nTransaction on Polygon mumbai network: https://mumbai.polygonscan.com/tx/0x0a7da0136ddd431aad5a90a4babcec709f62963b61df3f3341b5f54037b18bb0#eventlog\n\u003cbr/\u003e\n\n#### Test Case for for `log2` for emitting an event with one indexed parameter\n```\t\nevent Fire(int256 indexed t1);\n\nfunction test2(string memory n, int256 t1) external {  \n  emit Fire(t1);\n  \n  bytes32 e = keccak256(abi.encodePacked(n)); \n  assembly {   \n    log2(0x0, 0x0, e, t1)    \n  }\n}\n```\nTransaction on Polygon mumbai network: https://mumbai.polygonscan.com/tx/0xc1480bd039b41f6b59fccd4031a7f5951061472201af78aeaafee7b74c2cda74#eventlog\n\u003cbr/\u003e\n\n#### Test Case for `log3` for emitting an event with two indexed parameters\n```\t\nevent Fire(address indexed t1, uint256 indexed t2);\n\nfunction test8(string memory n, address t1, uint256 t2) external { \n  emit Fire(t1, t2);\n  \n  bytes32 e = keccak256(abi.encodePacked(n));  \n  assembly {   \n    log3(0x0, 0x0, e, t1, t2)    \n  }\n}\n```\nTransaction on Polygon mumbai network: https://mumbai.polygonscan.com/tx/0x10bf33dcd46cc6cda1e8315a5e2e735e73567cdc05841b51758847db9421e3b0#eventlog\n\u003cbr/\u003e\n\n#### Test Case for `log4` for emitting an event with three indexed parameters\n```\t\nevent Fire(address indexed t1, uint256 indexed t2, bool indexed t3, int128 abc);\n\nfunction test10(string memory n, address t1, uint256 t2, bool t3, int128 abc) external { \n  emit Fire(t1, t2, t3, abc);\n  \n  bytes32 e = keccak256(abi.encodePacked(n));   \n  assembly {   \n    let p := add(0x0, 0x20)\n      mstore(p, abc) \n      log4(p, 0x20, e, t1, t2, t3)    \n    }\n} \n```\nTransaction on Polygon mumbai network: https://mumbai.polygonscan.com/tx/0x98813736f2e60e3559837ee33278ea86990e557a0216fe91ca6c559354a86071#eventlog\n\u003cbr/\u003e\n\n#### Test Case for `log4` with dynamic and non-indexed parameters, plus three indexed parameters\n```\t\nevent Fire(address indexed t1, uint256 indexed t2, bool indexed t3, uint256 abc);\n\nfunction test11(string memory n, address t1, uint256 t2, bool t3, bytes memory data) external { \n  emit Fire(t1, t2, t3, abi.decode(data, (uint256)));\n    \n  bytes32 e = keccak256(abi.encodePacked(n));   \n  assembly {   \n    let p := add(data, 0x20)\n    let s := mload(data) \n    log4(p, s, e, t1, t2, t3)    \n  }\n}  \n```\nTransaction on Polygon mumbai network: https://mumbai.polygonscan.com/tx/0x68cd6ab903e450c8d566eb80800aeec759f31b853823c4ee2fa359e13435c5f9#eventlog\n\u003cbr/\u003e\n\n#### General Encapsulation for the four log functions\nMore details and invokation example, please check the source code here: [SolidityLogTest.sol](https://github.com/VictorZhang2014/solidity-log3/blob/main/SolidityLogTest.sol)\n```\nfunction exudeLog(uint i, bytes32 eventSig, bytes32 topic1, bytes32  topic2, bytes32 topic3, bytes memory data) public {\n  assembly { \n\t\t let p := add(data, 0x20)\n\t\t let s := mload(data) \n\t\t    if eq(i, 0x1) {\n          log1(p, s, eventSig)  \n\t\t    } \n\t\t    if eq(i, 0x2) {\n\t\t\t    log2(p, s, eventSig, topic1)  \n\t\t    } \n\t\t    if eq(i, 0x3) {\n\t\t\t    log3(p, s, eventSig, topic1, topic2)  \n\t\t    }\n\t\t    if eq(i, 0x4) {\n\t\t\t    log4(p, s, eventSig, topic1, topic2, topic3)  \n\t\t    }\n\t\t}\n} \n\nfunction getEventSig(string memory eventSigStr) public pure returns (bytes32) {\n  return keccak256(abi.encodePacked(eventSigStr));\n}\n```\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n\n# Solidity的日志内置函数log1、log2、log3 和 log4的使用\n\u003cbr/\u003e\n\n#### 对`log1`函数的测试，无参数\n```\t\nevent Fire();\n\nfunction test1(string memory n) external { \n  emit Fire();\n  \n  bytes32 e = keccak256(abi.encodePacked(n)); \n  assembly {   \n    log1(0x0, 0x0, e)    \n  }\n}\n```\n查看交易Polygon mumbai: https://mumbai.polygonscan.com/tx/0x0a7da0136ddd431aad5a90a4babcec709f62963b61df3f3341b5f54037b18bb0#eventlog\n\u003cbr/\u003e\n\n#### 对`log2`的测试，有一个indexed的参数 \n```\t\nevent Fire(int256 indexed t1);\n\nfunction test2(string memory n, int256 t1) external {  \n  emit Fire(t1);\n  \n  bytes32 e = keccak256(abi.encodePacked(n)); \n  assembly {   \n    log2(0x0, 0x0, e, t1)    \n  }\n}\n```\n查看交易Polygon mumbai: https://mumbai.polygonscan.com/tx/0xc1480bd039b41f6b59fccd4031a7f5951061472201af78aeaafee7b74c2cda74#eventlog\n\u003cbr/\u003e\n\n#### 对`log3`的测试，有两个indexed的参数\n```\t\nevent Fire(address indexed t1, uint256 indexed t2);\n\nfunction test8(string memory n, address t1, uint256 t2) external { \n  emit Fire(t1, t2);\n  \n  bytes32 e = keccak256(abi.encodePacked(n));  \n  assembly {   \n    log3(0x0, 0x0, e, t1, t2)    \n  }\n}\n```\n查看交易Polygon mumbai: https://mumbai.polygonscan.com/tx/0x10bf33dcd46cc6cda1e8315a5e2e735e73567cdc05841b51758847db9421e3b0#eventlog\n\u003cbr/\u003e\n\n#### 对`log4`的测试，有三个indexed的参数\n```\t\nevent Fire(address indexed t1, uint256 indexed t2, bool indexed t3, int128 abc);\n\nfunction test10(string memory n, address t1, uint256 t2, bool t3, int128 abc) external { \n  emit Fire(t1, t2, t3, abc);\n  \n  bytes32 e = keccak256(abi.encodePacked(n));   \n  assembly {   \n    let p := add(0x0, 0x20)\n      mstore(p, abc) \n      log4(p, 0x20, e, t1, t2, t3)    \n    }\n} \n```\n查看交易Polygon mumbai: https://mumbai.polygonscan.com/tx/0x98813736f2e60e3559837ee33278ea86990e557a0216fe91ca6c559354a86071#eventlog\n\u003cbr/\u003e\n\n#### 对`log4`的测试，动态data的参数，传入动态长度字节数据\n```\t\nevent Fire(address indexed t1, uint256 indexed t2, bool indexed t3, uint256 abc);\n\nfunction test11(string memory n, address t1, uint256 t2, bool t3, bytes memory data) external { \n  emit Fire(t1, t2, t3, abi.decode(data, (uint256)));\n    \n  bytes32 e = keccak256(abi.encodePacked(n));   \n  assembly {   \n    let p := add(data, 0x20)\n    let s := mload(data) \n    log4(p, s, e, t1, t2, t3)    \n  }\n}  \n```\n查看交易示例Polygon mumbai: https://mumbai.polygonscan.com/tx/0x68cd6ab903e450c8d566eb80800aeec759f31b853823c4ee2fa359e13435c5f9#eventlog\n\u003cbr/\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictorzhang2014%2Fsolidity-log3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvictorzhang2014%2Fsolidity-log3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictorzhang2014%2Fsolidity-log3/lists"}