{"id":13620676,"url":"https://github.com/NTA-Capital/SolMATe","last_synced_at":"2025-04-14T22:32:14.314Z","repository":{"id":72580661,"uuid":"442070066","full_name":"NTA-Capital/SolMATe","owner":"NTA-Capital","description":"Solidity Matrix Environment (SolMATe) - Core math + linear algebra libraries for Ethereum smart contracts. Enables machine learning directly on the blockchain.","archived":false,"fork":false,"pushed_at":"2023-07-25T22:51:44.000Z","size":159,"stargazers_count":33,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-08T07:38:19.293Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NTA-Capital.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-12-27T06:23:20.000Z","updated_at":"2024-07-09T09:44:44.000Z","dependencies_parsed_at":"2024-08-01T21:53:58.726Z","dependency_job_id":null,"html_url":"https://github.com/NTA-Capital/SolMATe","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NTA-Capital%2FSolMATe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NTA-Capital%2FSolMATe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NTA-Capital%2FSolMATe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NTA-Capital%2FSolMATe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NTA-Capital","download_url":"https://codeload.github.com/NTA-Capital/SolMATe/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248972018,"owners_count":21191707,"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":[],"created_at":"2024-08-01T21:00:58.362Z","updated_at":"2025-04-14T22:32:14.295Z","avatar_url":"https://github.com/NTA-Capital.png","language":"Solidity","readme":"\u003cimg src=\"https://user-images.githubusercontent.com/5258974/147603258-8abef830-9d86-4701-bd80-523ef8033f8a.png\" alt=\"nta_consulting_small\" height=\"200\" align=\"right\"/\u003e \n\n# SolMATe - The Solidity Matrix Environment \n\n![](https://img.shields.io/badge/PRs-welcome-brightgreen) ![](https://img.shields.io/badge/solidity-0.8.11-blue)\n\n**SolMATe is the fundamental package for floating-point math, array manipulation, and linear algebra in Ethereum smart contracts.** With SolMATe you get:\n\n- Gas-efficient operations with signed 59.18-decimal fixed-point numbers\n- Functions for manipulating vectors and matrices\n- Linear algebra routines enabling the implementation of machine learning algorithms, such as multivariate linear regression and deep neural networks\n\n**SolMATe is the first-ever package making it possible to engage in all aspects of a machine learning pipeline directly on the blockchain** - from data collection to model training and evaluation - without having to involve an off-chain oracle. See below for an example of a key ML algorithm (multiple linear regression) implemented as a smart contract.\n\n# Usage\n\nThe following smart contract performs multiple linear regression solving the equation `Ax=b`, where `A` is a matrix of coefficients, `b` is a vector of outputs, and `x` is the solution vector. It uses approximately `8e7` gas - making it impractical for Layer 1 applications but practical for Layer 2 as of 2022.\n\n```solidity\n// SPDX-License-Identifier: BSD-4-Clause\npragma solidity \u003e=0.8.4;\nimport \"prb-math/contracts/PRBMathSD59x18.sol\";\nimport \"./VectorUtils.sol\";\nimport \"./MatrixUtils.sol\";\n\ncontract SolMATe_demo {\n    using PRBMathSD59x18 for int256;\n    using VectorUtils for int256[];\n    using MatrixUtils for int256[][];\n\n    function multipleLinearRegression(int256[][] memory a, int256[] memory b) public pure returns (int256[][] memory) {\n        int256[][] memory q;\n        int256[][] memory r;\n        int256[][] memory b_mat = b.convertTo59x18().toMatrix();\n        (q,r) = a.convertTo59x18().QRDecomposition();\n        return r.backSubstitute(q.T().dot(b_mat));\n    }\n}\n```\n\nWe can then run the contract using the following Hardhat script:\n\n```javascript\n// We require the Hardhat Runtime Environment explicitly here. This is optional\n// but useful for running the script in a standalone fashion through `node \u003cscript\u003e`.\n//\n// When running the script with `npx hardhat run \u003cscript\u003e` you'll find the Hardhat\n// Runtime Environment's members available in the global scope.\nconst hre = require(\"hardhat\");\n\nasync function main() {\n  // Hardhat always runs the compile task when running scripts with its command\n  // line interface.\n  //\n  // If this script is run directly using `node` you may want to call compile\n  // manually to make sure everything is compiled\n  // await hre.run('compile');\n\n  const SolMATe_demo = await hre.ethers.getContractFactory(\"SolMATe_demo\");\n  const solmate_demo = await SolMATe_demo.deploy();\n\n  await solmate_demo.deployed();\n  const inputMat = [[43,1],[21,1],[25,1],[42,1],[57,1],[59,1]]\n  const b = [99,65,79,75,87,81]\n  const result = await solmate_demo.multipleLinearRegression(inputMat, b);\n  console.log(result);\n}\n\n// We recommend this pattern to be able to use async/await everywhere\n// and properly handle errors.\nmain()\n  .then(() =\u003e process.exit(0))\n  .catch((error) =\u003e {\n    console.error(error);\n    process.exit(1);\n  });\n```\n\nIn SolMATe, all fixed point numbers are scaled by `1e18` and stored as `int256` data. Importing the `PRBMathSD59x18` package allows one to perform math operations on these numbers.\n\n```solidity\nusing PRBMathSD59x18 for int256;\nint256 a = 1.5e18; // represents a = 1.5\nint256 b = 2e18; // represents b = 2\na.mul(b);  // returns 3e18, or 3000000000000000000, which represents 3\n```\n\n# Contributing\n\nSolMATe uses Hardhat for scripts and unit testing. Pull requests are welcome - especially those pertaining to documentation, optimizing algorithms, and developing test cases.\n","funding_links":[],"categories":["Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNTA-Capital%2FSolMATe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNTA-Capital%2FSolMATe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNTA-Capital%2FSolMATe/lists"}