{"id":25146415,"url":"https://github.com/datachainlab/solidity-protobuf","last_synced_at":"2025-04-28T12:25:35.896Z","repository":{"id":37885208,"uuid":"336318082","full_name":"datachainlab/solidity-protobuf","owner":"datachainlab","description":"A generator of protobuf encoders compliant with ADR-27 (This is a fork of https://github.com/nutsfinance/solidity-protobuf)","archived":false,"fork":false,"pushed_at":"2024-02-14T08:04:08.000Z","size":4915,"stargazers_count":20,"open_issues_count":9,"forks_count":13,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-30T09:31:38.327Z","etag":null,"topics":["cosmos","cosmos-sdk","ethereum","protocol-buffers","solidity"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/datachainlab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2021-02-05T15:56:24.000Z","updated_at":"2024-11-20T03:19:13.000Z","dependencies_parsed_at":"2023-01-21T12:31:53.580Z","dependency_job_id":"db646644-d4af-4245-bbf5-a3f5eed720db","html_url":"https://github.com/datachainlab/solidity-protobuf","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datachainlab%2Fsolidity-protobuf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datachainlab%2Fsolidity-protobuf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datachainlab%2Fsolidity-protobuf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datachainlab%2Fsolidity-protobuf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/datachainlab","download_url":"https://codeload.github.com/datachainlab/solidity-protobuf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251312377,"owners_count":21569222,"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":["cosmos","cosmos-sdk","ethereum","protocol-buffers","solidity"],"created_at":"2025-02-08T20:18:24.795Z","updated_at":"2025-04-28T12:25:35.850Z","avatar_url":"https://github.com/datachainlab.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eProtoSolGenerator\u003c/h1\u003e\n\nProtoSolGenerator is a protocol buffer client generator for Solidity. Its main purpose is to allow Ethereum developers to define custom data structure using protocol buffer, and generates Solidity stubs for data serialization and deserialization.\n\nProtoSolGenerator is inspired by [pb3sol](https://raw.githubusercontent.com/umegaya/pb3sol) with optimization on performance, flexibility and usability. We initial testing shows that the gas cost is reduced by 2/3 compared to the original Solidity implementation.\n\n\u003ch2 align=\"center\"\u003eIntroduction\u003c/h2\u003e\n\nProtocol buffer is a language-neutral, platform-neutral, extensible way of serializing structured data for use in communications protocols, data storage, and more. It's widely adopted as in various platforms, and it has several characteristics to make it particularly beneficial to Ethereum development.\n\n### Optimized Storage\n\nThe storage cost is significantly higher in Ethereum than compute. For example, an SSTORE operation costs 20,000 gas while a normal ADD costs only 3. It's more reasonable to trade storage cost with computation in Ethereum.\n\nHowever, Solidity in Ethereum is not storage-efficient. A single storage variable of type uint8 also takes the space of a whole word, identical to variables of type uint256. For a variable of type uint256, even if its value is relative small, (e.g it consumes only 4 bytes), it's still stored as 32 bytes. Protocol buffer defines an encoding format which is highly optimized in storage.\n\n### Flexibility\n\nOnce a smart contract is deployed to Ethereum network, it's not updatable. Even though it can be \"upgraded\" using proxies, it comes with constraints and is not easy to use. For example, the upgraded contract might need to use the same field declaration order as the old contract.\n\nSuch inflexibility in logic can be mitigated with flexibility in data definition, which is a core feature of protocol buffer. When implemented with separation of logic and data, the upgraded contracts can work with data from the old ones.\n\n### Cross-platform Support\n\nProtocol buffer has rich support in languages including Java, JavaScript, Python and C++, so the function parameters and return values can be defined using the protocol buffer encoded strings. With this approach, users of smart contracts can use languages like JavaScript to construct function parameters to invoke Solidity functions.\n\n### Security\n\nThe binary of protocol buffer data pertains the data type definition as well as field number. This ensures type-safety of data either on-chain or passed-in externally.\n\nMoreover, Protocol Buffer simplifies the usage of complex data structure in the paramters and return values of external functions. There might be still hidden risk in using ABIEncoderV2, especially with the known bug identified in March 2019. ProtoSolGen allows auto-serialization of the complex data types so that we could use string as paramter/return value types instead of relying on ABIEncoderV2.\n\n\u003ch2 align=\"center\"\u003eConcept\u003c/h2\u003e\n\nSolidity has much more basic types than protocol buffer. For example, in Solidity there are 32 signed integer types, from int8 to int256. In order to address this type mismatch, we provide a custom type defintion for each Solidity types. For example, uint128 is defined as below:\n\n```\nmessage uint128 {bytes data = 1;}\n```\n\nThe data, which is of type bytes, contains the minimum number of bytes needed to hold the value. For example, if the uint128 variable has a value of 20,000, 2 bytes are sufficient to hold this number. Currently we only support length-delimited encoding for value data.\n\n\u003ch2 align=\"center\"\u003eHow to Use It\u003c/h2\u003e\n\n### Installation\n\nTo install ProtoSolGenerator, first install [protobuf compiler](https://github.com/protocolbuffers/protobuf#protocol-compiler-installation).\n\nThen install python requirements. Python \u003e= 3.5 is required.\n\n```pip install -r requirements.txt```\n\n### Data Definition\n\nUsers can use the custom type definition to define their data structure. Below is an example:\n\n```\nsyntax = \"proto3\";\n\nimport \"SolidityTypes.proto\";\n\npackage finance.nuts;\n\nmessage SellerParameter {\n    .solidity.address seller_address = 1;\n    .solidity.uint256 start_date = 2;\n    .solidity.address collateral_token_address = 3;\n    .solidity.uint256 collateral_token_amount = 4;\n    .solidity.uint256 borrow_amount = 5;\n    .solidity.uint16 collateral_due_days = 6;\n    .solidity.uint16 engagement_due_days = 7;\n    .solidity.uint16 tenor_days = 8;\n    .solidity.uint16 interest_rate = 9;\n    .solidity.uint16 grace_period = 10;\n}\n```\n\nProtoSolGenerator generates a Solidity struct definition for this message as well as serialization/deserialization methods. Users can use the generated Solidity stub in their smart contracts.\n\n### Client Generation\n\nUse `run.sh` with input proto files (`--input`) and output Solidity location(`--output`)\n\n```\n./run.sh --input \u003cproto file path\u003e --output \u003coutput directory\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatachainlab%2Fsolidity-protobuf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatachainlab%2Fsolidity-protobuf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatachainlab%2Fsolidity-protobuf/lists"}