Fidelius开发教程

来自典枢
Zhangxp讨论 | 贡献2022年4月26日 (二) 02:57的版本 →‎Hello World
跳到导航 跳到搜索

简介

Fidelius 提供了自定义算法的能力。此处的算法用于分析数据,并将分析结果交付给用户。

Fidelius 的算法实现基于 C/C++1。一个算法是指一个运行在可信执行环境(TEE)中的代码,由于目前主要的支持硬件为 Intel SGX,因此编程方式符合 Intel SGX 的编程规范。

本文介绍的算法开发基于 Fidelius 的最新版本,请检查自己的版本。

Hello World

需要 git clone example,然后软链接到 example 目录下,需要解释编译的步骤,release 版本签名的步骤,执行的步骤需要解释各个文件的作用和意义 下面来看一个完整的 hello world 程序。

  1. include ”corecommon/ crypto / stdeth . h”
  1. include ” stbox / tsgx / log . h”
  1. include ”ypc_t/ a n a l y z e r / algo_wrapper . h”
  1. include ”ypc_t/ a n a l y z e r /macro . h”

class hello_world {

public :

i n l i n e stbox : : bytes do_parse ( const stbox : : bytes &param ) {

LOG(INFO) << ” h e l l o ␣ world ” ;

return param ;

}

};

ypc : : algo_wrapper<ypc : : crypto : : eth_sgx_crypto ,

ypc : : noinput_data_stream ,

hello_world , ypc : : l o c a l _ r e s u l t >

pw ; YPC_PARSER_IMPL(pw ) ;

algo_wrapper

template<typename Crypto , typename DataSession , typename ParserT ,

typename Result , typename ModelT = void ,

template <typename> c l a s s DataAllowancePolicy = ignore_data_allowance ,

template <typename> c l a s s ModelAllowancePolicy = ignore_model_allowance>

class algo_warpper ;

代码来源core/include/ypc_t/analyzer/algo_wrapper.h

Crypto:密码协议簇,目前支持 ypc::crypto::eth_sgx_crypto,兼容以太坊。

DataSession:数据源方式,支持 noinput_data_stream, raw_data_stream,

sealed_data_stream, multi_data_stream。

ParserT:表示自定义的算法类。

Result:表示结果的类型,支持 local_result, onchain_result, offchain_result,forward_result。

ModelT:表示模型的类型,是 ff::util::ntobject<...>。

DataAllowancePolicy,表示数据源的许可验证策略,支持 ignore_data_allowance,check_data_allowance。

ModelAllowancePolicy,表示模型的许可验证策略,支持 ignore_model_allowance,check_model_allowance。

通过对上述参数的选择和组合,可以支持不同的场景。