Pinocchio: Nearly Practica Verifable Computationh之circuit compiler

下载论文相应源码

一、编译circuit compiler源码

circuit compiler对应源码在vc/sourceCode/vc/pinocchio/ccompiler/目录下,其中有文件结构为:
1)external-code:外部依赖文件。
2)input:用于测试pinocchio的sample程序。
3)src:compiler的源码(均为python脚本)。其中的drawcirc.py可可视化相应的circuit.

1.1 安装外部依赖

cd vc/sourceCode/vc/pinocchio/ccompiler/external-code
make

在这里插入图片描述
主要有两个工具:
1)pycparser :
pycparser is a complete parser of the C language, written in
pure Python using the PLY parsing library.
It parses C code into an AST and can serve as a front-end for
C compilers or analysis tools.
2)ply:
PLY is an implementation of lex and yacc parsing tools for Python.
lex的工作就是根据词法规则自动生成词法分析器。 执行语法分析的程序则称为解析器。yacc就是根据语法规则自动生成解析器的程序。

1.2 运行sample程序

cd vc/sourceCode/vc/pinocchio/ccompiler/input
python ../src/build-test-matrix.py #在当前目录下生成make.matrix文件,为makefile格式文件
make -f make.matrix #编译,会在build文件夹内生成相应的circuit(*.arith)和可执行文件。

注意:
若使用64位gcc编译,需要在make.mattrix和make.in文件中,将所有的gcc命令后面加 -m32,否则会报错Error: operand type mismatch for push.
../src/Vercomp.py脚本把输入的.c程序转换为.arith circuit文件。

1.3 将*.arith cirtuit文件通过drawcirc.py转换为可视化图形

drawcirc.py中使用了pydot来可视化决策树,需要安装:

pip install pydot
apt-get install graphviz

以common/App.py中的App(“eqtest”)为例。默认的drawcirc.py无法处理其中的zerop的值,需在drawcirc.py sub_parse函数中增加:

elif (verb=="zerop"):
  self.add_gate(Gate("zerop", in_a, out_a))
cd vc/sourceCode/vc/pinocchio/ccompiler/input
python ../src/drawcirc.py --arith build/eqtest-p0-b32.arith --out output.pdf

生成的图形类似为:
在这里插入图片描述

默认生成的这个circuit是判断input->a+5与input->b*2是否相等。图形并不是特别直观,可修改eqtest.c中代码,改为判断input->a和input->b值是否相等。

void outsource(struct Input *input, struct Output *output)
{    
    output->x = (input->a) == (input->b);
}

对应的图形为:
在这里插入图片描述

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值