[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-detail-123044-en":3,"doc-seo-123044-105":30,"detail-sidebar-cat-0-en-105":95},{"code":4,"msg":5,"data":6},0,"success",{"doc_id":7,"user_id":8,"nickname":9,"user_avatar":10,"doc_module":4,"category_id":11,"category_name":12,"doc_title":13,"doc_description":14,"doc_content":15,"file_id":16,"file_url":17,"file_type":18,"file_size":19,"view_count":20,"is_deleted":4,"is_public":20,"is_downloadable":20,"audit_status":20,"page_count":21,"language":22,"language_code":23,"site_id":24,"html_lang":23,"table_of_contents":25,"faqs":26,"seo_title":27,"seo_description":14,"update_tm":28,"read_time":29},123044,8796095461564,"Liam","https://ap-avatar.wpscdn.com/davatar_155a257f0dc6eb9ab79c44ca47cae57d",6,"Technology","ML2SC - Deploying Machine Learning Models as Smart Contracts on the Blockchain","ML2SC addresses AI safety by enabling verifiable trust in machine-learning computations through tamper-proof blockchain execution. The core problem is bridging ML implementations in Python (e.g., PyTorch) with on-chain inference in Solidity for EVM-compatible smart contracts. ML2SC automatically translates PyTorch multi-layer perceptrons into Solidity, approximating floating-point math via a fixed-point library, then supports off-chain training with on-chain weight transfer. Gas costs for deployment, parameter updates, and inference are modeled and validated, while on-chain outputs match original PyTorch results in classification accuracy.","ML2SC: Deploying Machine Learning Models as Smart Contracts on the Blockchain  \nZhikai Li∗ , Steve Vott∗ and Bhaskar Krishnamachari Viterbi School of Engineering, University of Southern California, Los Angeles, USA {leol, svott, [bkrishna](bkrishna}@usc.edu)[}](bkrishna}@usc.edu)[@usc.edu](bkrishna}@usc.edu)  \narXiv :2404 . 16967v1 [ cs .LG] 28 Mar 2024  \nAbstract—With the growing concern of AI safety, there is a need to trust the computations done by machine learning (ML) models. Blockchain technology, known for recording data and running computations transparently and in a tamper-proof manner, can offer this trust. One significant challenge in deploying ML Classifiers on-chain is that while ML models are typically written in Python using an ML library such as Pytorch, smart contracts deployed on EVM-compatible blockchains are written in Solidity. We introduce Machine Learning to Smart Contract (ML2SC), a PyTorch to Solidity translator that can automatically translate multi-layer perceptron (MLP) models written in Pytorch to Solidity smart contract versions. ML2SC uses a fixedpoint math library to approximate floating-point computation. After deploying the generated smart contract, we can train our models off-chain using PyTorch and then further transfer the acquired weights and biases to the smart contract using a function call. Finally, the model inference can also be done with a function call providing the input. We mathematically model the gas costs associated with deploying, updating model parameters, and running inference on these models on-chain, showing that the gas costs increase linearly in various parameters associated with an MLP. We present empirical results matching our modeling. We also evaluate the classification accuracy showing that the outputs obtained by our transparent on-chain implementation are identical to the original off-chain implementation with Pytorch.  \nIndex Terms—Machine Learning, Blockchain, Smart Contracts, Pytorch  \nI. INTRODUCTION  \nThe advent of machine learning (ML) models in various domains has raised significant concerns regarding privacy and the verifiability of computational outputs. Blockchain technology, renowned for its capacity to preserve node privacy while ensuring transactional transparency across a distributed network, presents a promising solution to these challenges. Recent scholarly efforts have ventured into federated learning algorithms on blockchain platforms, effectively decentralizing the model training process while safeguarding data privacy. This intersection of blockchain with AI for federated learning and data preservation has been the subject of extensive research.  \nExecuting models on-chain ensures the authenticity and transparency of the inference outcomes, affirming that they are generated by the designated models. This aspect is increasingly vital as AI systems grow more complex and sophisticated, where reliable verification methods for model inference are essential to mitigate concerns about potential model hijacking, censorship or manipulation.  \n*These authors contributed equally to this work.  \nDespite these advantages, deploying model inference on blockchain platforms faces significant challenges, primarily due to the computational limitations inherent to such systems. The Ethereum Virtual Machine (EVM), a predominant computation engine in the blockchain domain, lacks support for floating-point operations and standard exponentiation functions. Furthermore, the EVM is constrained by system limitations, including a maximum stack size of 1024 and a capon stack data members at 256 bits. These constraints render the execution of large-scale, computation-intensive AI models impractical.  \nBuilding upon prior works such as the one by Badruddoja et al. [3], our study aims to evaluate the feasibility and efficiency of translating simple ML models to run on blockchain platforms. Specifically, we focus on the multi-layer perceptron (MLP) architecture, chosen for it","cbCaikhfnT5INdOd","https://ap.wps.com/l/cbCaikhfnT5INdOd","pdf",346463,1,5,"English","en",105,"# Introduction\n## On-chain trust, transparency, and verifiability\n## Challenges of executing ML on EVM\n# Related Work\n## On-chain data privacy","[{\"question\":\"What is ML2SC and what problem does it solve?\",\"answer\":\"ML2SC is a PyTorch-to-Solidity translator that converts multi-layer perceptron models into EVM-compatible smart contracts, enabling transparent and verifiable on-chain inference.\"},{\"question\":\"How does ML2SC handle floating-point computation on-chain?\",\"answer\":\"ML2SC uses a fixed-point math library to approximate floating-point operations in Solidity, allowing execution on the Ethereum Virtual Machine.\"},{\"question\":\"How are model parameters and inference executed with ML2SC?\",\"answer\":\"Models are trained off-chain in PyTorch, and then weights and biases are transferred to the deployed smart contract via a function call; inference is performed by calling a contract function with the input.\"},{\"question\":\"Does the on-chain model produce the same results as the original PyTorch model?\",\"answer\":\"Yes. The evaluation shows that on-chain outputs are identical to the off-chain PyTorch implementation, matching classification accuracy while gas costs are modeled and confirmed empirically.\"}]","ML2SC - Deploying Machine Learning Models as Smart Contracts on the Blockchain | PDF",1785814368,13,{"code":4,"msg":31,"data":32},"ok",{"site_id":24,"language":23,"slug":33,"title":13,"keywords":34,"description":14,"schema_data":35,"social_meta":90,"head_meta":92,"extra_data":94,"updated_unix":28},"ml2sc-deploying-machine-learning-models-as-smart-contracts-on-the-blockchain","",{"@graph":36,"@context":89},[37,54,68],{"@type":38,"itemListElement":39},"BreadcrumbList",[40,44,48,51],{"item":41,"name":42,"@type":43,"position":20},"https://docshare.wps.com","Home","ListItem",{"item":45,"name":46,"@type":43,"position":47},"https://docshare.wps.com/document/","Document",2,{"item":49,"name":12,"@type":43,"position":50},"https://docshare.wps.com/document/technology/",3,{"item":52,"name":13,"@type":43,"position":53},"https://docshare.wps.com/document/ml2sc-deploying-machine-learning-models-as-smart-contracts-on-the-blockchain/123044/",4,{"url":52,"name":13,"@type":55,"author":56,"headline":13,"publisher":58,"fileFormat":61,"inLanguage":23,"description":14,"dateModified":62,"datePublished":62,"encodingFormat":61,"isAccessibleForFree":63,"interactionStatistic":64},"DigitalDocument",{"name":9,"@type":57},"Person",{"url":41,"name":59,"@type":60},"DocShare","Organization","application/pdf","2026-08-04",true,{"@type":65,"interactionType":66,"userInteractionCount":20},"InteractionCounter",{"@type":67},"ViewAction",{"@type":69,"mainEntity":70},"FAQPage",[71,77,81,85],{"name":72,"@type":73,"acceptedAnswer":74},"What is ML2SC and what problem does it solve?","Question",{"text":75,"@type":76},"ML2SC is a PyTorch-to-Solidity translator that converts multi-layer perceptron models into EVM-compatible smart contracts, enabling transparent and verifiable on-chain inference.","Answer",{"name":78,"@type":73,"acceptedAnswer":79},"How does ML2SC handle floating-point computation on-chain?",{"text":80,"@type":76},"ML2SC uses a fixed-point math library to approximate floating-point operations in Solidity, allowing execution on the Ethereum Virtual Machine.",{"name":82,"@type":73,"acceptedAnswer":83},"How are model parameters and inference executed with ML2SC?",{"text":84,"@type":76},"Models are trained off-chain in PyTorch, and then weights and biases are transferred to the deployed smart contract via a function call; inference is performed by calling a contract function with the input.",{"name":86,"@type":73,"acceptedAnswer":87},"Does the on-chain model produce the same results as the original PyTorch model?",{"text":88,"@type":76},"Yes. The evaluation shows that on-chain outputs are identical to the off-chain PyTorch implementation, matching classification accuracy while gas costs are modeled and confirmed empirically.","https://schema.org",{"og:url":52,"og:type":91,"og:title":13,"og:site_name":59,"og:description":14},"article",{"robots":93,"canonical":52},"index,follow",{"doc_id":7,"site_id":24},{"code":4,"msg":5,"data":96},[97,101,105,109,113,116,121,126,131,134,138],{"id":20,"doc_module":4,"doc_module_name":46,"category_name":98,"show_sort_weight":99,"slug":100},"Story & Novel",90,"story-novel",{"id":47,"doc_module":4,"doc_module_name":46,"category_name":102,"show_sort_weight":103,"slug":104},"Literature",80,"literature",{"id":53,"doc_module":4,"doc_module_name":46,"category_name":106,"show_sort_weight":107,"slug":108},"Exam",70,"exam",{"id":21,"doc_module":4,"doc_module_name":46,"category_name":110,"show_sort_weight":111,"slug":112},"Comic",60,"comic",{"id":11,"doc_module":4,"doc_module_name":46,"category_name":12,"show_sort_weight":114,"slug":115},50,"technology",{"id":117,"doc_module":4,"doc_module_name":46,"category_name":118,"show_sort_weight":119,"slug":120},7,"Healthcare",40,"healthcare",{"id":122,"doc_module":4,"doc_module_name":46,"category_name":123,"show_sort_weight":124,"slug":125},8,"Research & Report",30,"research-report",{"id":127,"doc_module":4,"doc_module_name":46,"category_name":128,"show_sort_weight":129,"slug":130},9,"Religion & Spirituality",20,"religion-spirituality",{"id":129,"doc_module":4,"doc_module_name":46,"category_name":132,"show_sort_weight":129,"slug":133},"World Cup","world-cup",{"id":135,"doc_module":4,"doc_module_name":46,"category_name":136,"show_sort_weight":135,"slug":137},10,"Lifestyle","lifestyle",{"id":139,"doc_module":4,"doc_module_name":46,"category_name":140,"show_sort_weight":21,"slug":141},19,"General","general"]