arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2404.16967cs.LGcs.CR
收藏

ML2SC:将机器学习模型作为智能合约部署在区块链上

ML2SC: Deploying Machine Learning Models as Smart Contracts on the Blockchain

Viterbi School of Engineering, University of Southern California(南加州大学维特比工程学院)

Zhikai Li, Steve Vott, Bhaskar Krishnamachar

AI总结:

本文提出ML2SC框架,将PyTorch编写的MLP模型自动翻译为Solidity智能合约并部署上链,通过定点数学库近似浮点计算,实验证明其链上推理输出与链下完全一致且gas成本呈线性增长。

摘要:

随着对AI安全问题的日益关注,人们需要信任由机器学习(ML)模型执行的计算。区块链技术以透明且防篡改的方式记录数据和运行计算而闻名,能够提供这种信任。在链上部署ML分类器的一个重大挑战是,尽管ML模型通常使用PyTorch等ML库以Python编写,但部署在兼容EVM的区块链上的智能合约却是用Solidity编写的。我们介绍了Machine Learning to Smart Contract(ML2SC),这是一个从PyTorch到Solidity的翻译器,能够自动将以PyTorch编写的多层感知机(MLP)模型翻译为Solidity智能合约版本。ML2SC使用定点数学库来近似浮点计算。部署生成的智能合约后,我们可以使用PyTorch在链下训练模型,然后通过函数调用将获取的权重和偏置进一步传输到智能合约中。最后,也可以通过提供输入的函数调用来完成模型推理。我们对在链上部署、更新模型参数以及运行这些模型推理相关的gas成本进行了数学建模,表明gas成本在MLP的各项相关参数中呈线性增长。我们展示了与我们的建模相匹配的实证结果。我们还评估了分类准确率,表明通过我们透明的链上实现所获得的输出与使用PyTorch的原始链下实现完全一致。

英文摘要:

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 fixed-point 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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑