您当前的位置: 首页 >  ar

mutourend

暂无认证

  • 1浏览

    0关注

    661博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Pinocchio: Nearly Practica Verifable Computationh之circuit compiler

mutourend 发布时间:2019-06-04 17:44:43 ,浏览量:1

下载论文相应源码

一、编译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);
}

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

关注
打赏
1664532908
查看更多评论
立即登录/注册

微信扫码登录

0.0375s