{"id":22861593,"url":"https://github.com/dhruv-varshney-developer/inline","last_synced_at":"2026-04-28T20:03:34.937Z","repository":{"id":265599540,"uuid":"895943510","full_name":"Dhruv-Varshney-developer/inline","owner":"Dhruv-Varshney-developer","description":"A Solidity smart contract project demonstrating low-level blockchain programming techniques, including bitwise operations, inline assembly, and string manipulation. ","archived":false,"fork":false,"pushed_at":"2024-11-30T03:40:13.000Z","size":69,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-06T13:17:58.704Z","etag":null,"topics":["blockchain","ethereum","hardhat","inline-assembly","solidity"],"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/Dhruv-Varshney-developer.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":"2024-11-29T08:28:49.000Z","updated_at":"2024-11-30T03:42:08.000Z","dependencies_parsed_at":"2024-11-30T04:25:21.488Z","dependency_job_id":"300fe591-861d-436a-88a9-827e1cc762b6","html_url":"https://github.com/Dhruv-Varshney-developer/inline","commit_stats":null,"previous_names":["dhruv-varshney-developer/inline"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dhruv-Varshney-developer%2Finline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dhruv-Varshney-developer%2Finline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dhruv-Varshney-developer%2Finline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dhruv-Varshney-developer%2Finline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dhruv-Varshney-developer","download_url":"https://codeload.github.com/Dhruv-Varshney-developer/inline/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246443492,"owners_count":20778247,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["blockchain","ethereum","hardhat","inline-assembly","solidity"],"created_at":"2024-12-13T10:09:37.722Z","updated_at":"2026-04-28T20:03:34.869Z","avatar_url":"https://github.com/Dhruv-Varshney-developer.png","language":"Solidity","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Solidity Inline Assembly Practice\n\n## Description\n\nThis project demonstrates the use of inline assembly in Solidity to optimize smart contract operations for reduced gas costs and improved performance. It includes two contracts: `BitWise` and `String`, showcasing practical applications of assembly code for bitwise operations and string manipulations. The project is implemented as a Hardhat-based environment with testing and deployment scripts.\n\n## Features\n\n- **Bitwise Operations:**\n  - `countBitSet` implemented with inline assembly (`countBitSetAsm`) for a 25% reduction in gas costs.\n- **String Manipulation:**\n  - `charAt` implemented with inline assembly for a 50% reduction in gas costs.\n- **Complete Hardhat Setup:**\n  - Deployment and testing scripts included.\n- **Comprehensive Testing:**\n  - Covers edge cases to ensure robustness.\n\n## File Structure\n\n```bash\nsolidity-bitwise-string/\n│\n├── contracts/\n│   └── inline.sol         # Main smart contract with BitWise and String implementations\n│\n├── scripts/\n│   └── deploy.js          # Deployment script for contracts\n│\n├── test/\n│   └── string.js          # Unit tests for String contract\n│\n├── hardhat.config.js      # Hardhat configuration\n├── package.json           # Project dependencies and scripts\n└── README.md              # Project documentation\n\n```\n\n## Smart Contracts\n\n### BitWise Contract\n\nThe `BitWise` contract includes two methods to count the number of bits set in an 8-bit unsigned integer:\n\n- **`countBitSet`**: A simple implementation using loops.\n- **`countBitSetAsm`**: Optimized using inline assembly for a 25% reduction in gas costs.\n\n#### Example Code\n\n```solidity\nfunction countBitSetAsm(uint8 data) public pure returns (uint8 result) {\n    assembly {\n        result := 0\n        for { let i := 0 } lt(i, 8) { i := add(i, 1) } {\n            let bit := and(shr(i, data), 1)\n            if eq(bit, 1) {\n                result := add(result, 1)\n            }\n        }\n    }\n}\n```\n\n## Installation\n\n1. Clone the repository:\n\n```bash\n\ngit clone https://github.com/your-username/solidity-inline-assembly.git\ncd solidity-inline-assembly\n```\n\n2. Install dependencies:\n\n```bash\nnpm install\n```\n\n3. Run tests:\n\n```bash\nnpx hardhat test\n```\n\n4. Deployment:\n\nTo deploy the contracts:\n\n```bash\nnpx hardhat run scripts/deploy.js\n```\n\n## Test Cases\n\n### BitWise Contract\n\n`countBitSetAsm` correctly counts the number of bits set in a `uint8`.\n\n### String Contract\n\nTest cases for `charAt`:\n\n1. `charAt(\"abcdef\", 2)` should return `0x6300`.\n2. `charAt(\"\", 0)` should return `0x0000`.\n3. `charAt(\"george\", 10)` should return `0x0000`.\n\nRun the tests:\n\n```bash\nnpx hardhat test\n```\n\n## Optimization Highlights\n\n- `countBitSetAsm`: Reduced gas usage by **25%** compared to the loop-based implementation.\n- `charAt`: Achieved **50%** reduction in gas costs by leveraging assembly for direct memory manipulation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhruv-varshney-developer%2Finline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdhruv-varshney-developer%2Finline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhruv-varshney-developer%2Finline/lists"}