Skip to content

Commit 4dc46f7

Browse files
authored
Merge pull request #14 from shaojian-ant/main
repo-sync-2024-08-08T19:24:12+0800
2 parents 3a359da + 2736319 commit 4dc46f7

9 files changed

Lines changed: 68 additions & 45 deletions

File tree

README.md

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interconnection-impl 引用了 spu 仓库代码,需要根据[ spu 构建前提
99
然后执行以下构建指令:
1010

1111
```shell
12-
bazel build ic_impl/ic_main
12+
bazel build -c opt ic_impl/ic_main
1313
```
1414

1515
## 运行 ECDH-PSI
@@ -19,13 +19,13 @@ bazel build ic_impl/ic_main
1919
本地同时执行以下两条指令:
2020

2121
```shell
22-
bazel run ic_impl/ic_main -- -rank=0 -algo=ECDH_PSI -protocol_families=ECC \
22+
bazel run -c opt ic_impl/ic_main -- -rank=0 -algo=ECDH_PSI -protocol_families=ECC \
2323
-in_path ic_impl/data/psi_1.csv -field_names id -out_path /tmp/p1.out \
2424
-parties=127.0.0.1:9530,127.0.0.1:9531
2525
```
2626

2727
```shell
28-
bazel run ic_impl/ic_main -- -rank=1 -algo=ECDH_PSI -protocol_families=ECC \
28+
bazel run -c opt ic_impl/ic_main -- -rank=1 -algo=ECDH_PSI -protocol_families=ECC \
2929
-in_path ic_impl/data/psi_2.csv -field_names id -out_path /tmp/p2.out \
3030
-parties=127.0.0.1:9530,127.0.0.1:9531
3131
```
@@ -38,7 +38,7 @@ bazel run ic_impl/ic_main -- -rank=1 -algo=ECDH_PSI -protocol_families=ECC \
3838

3939
程序运行需要关闭握手过程:
4040
```shell
41-
bazel run ic_impl/ic_main -- -disable_handshake=1
41+
bazel run -c opt ic_impl/ic_main -- -disable_handshake=1
4242
```
4343

4444
ECDH-PSI 算法配置的环境变量如下表所示。环境变量设置可参考 [ecdh-psi-env-alice.sh](./ic_impl/env/ecdh-psi-env-alice.sh)[ecdh-psi-env-bob.sh](./ic_impl/env/ecdh-psi-env-bob.sh)
@@ -62,30 +62,43 @@ ECDH-PSI 算法配置的环境变量如下表所示。环境变量设置可参
6262

6363
### 启动 Beaver 服务
6464

65-
运行 SS-LR 之前,需要先启动 Beaver 服务。Beaver 服务的代码位于 SPU 仓库中,需要将 SPU 代码克隆到本地,然后编译并启动 Beaver
66-
服务:
65+
运行 SS-LR 之前,需要先启动 Beaver 服务。Beaver 服务的代码位于 SPU 仓库中,需要将 SPU 代码克隆到本地并编译:
6766

6867
```shell
6968
git clone git@github.com:secretflow/spu.git
70-
cd spu && bazel run libspu/mpc/semi2k/beaver/ttp_server:beaver_server_main -- -port=9449
69+
cd spu && bazel build -c opt libspu/mpc/semi2k/beaver/beaver_impl/ttp_server:beaver_server_main
70+
```
71+
72+
然后生成 Beaver 服务的公钥和私钥:
73+
74+
```
75+
bazel-bin/libspu/mpc/semi2k/beaver/beaver_impl/ttp_server/beaver_server_main -gen_key=true
76+
```
77+
78+
最后启动 Beaver 服务,将上一步生成的私钥通过命令行参数传递给 Beaver 服务:
79+
80+
```
81+
bazel-bin/libspu/mpc/semi2k/beaver/beaver_impl/ttp_server/beaver_server_main -port=9449 -server_private_key=LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JR0lBZ0VBTUJRR0NDcUJITTlWQVlJdEJnZ3FnUnpQVlFHQ0xRUnRNR3NDQVFFRUlJVnRVS1JEalVERFptZ3cKL0xUd0dYUmZXVFM5MStTSEhqODAwNnc2SUUxNW9VUURRZ0FFdER5RHNLM0RQN3YyWmdEdjZYNVQySnMzdGtmNQpPYXVBUEdXTHErTlhuMW1HYkd5N3pIZEVaa0FvNERDSGZyRmVuRWFCckxXMFZxUUtUY3QxUzJUYXpnPT0KLS0tLS1FTkQgUFJJVkFURSBLRVktLS0tLQo=
7182
```
7283

7384
### 命令行传参
7485

75-
启动 Beaver 服务后,本地同时执行以下两条指令:
86+
启动 Beaver 服务后,本地同时执行以下两条指令,命令行参数包括上述 Beaver 服务生成的公钥
7687

7788
```shell
78-
bazel run ic_impl/ic_main -- -rank=0 -algo=SS_LR -protocol_families=SS \
89+
bazel run -c opt ic_impl/ic_main -- -rank=0 -algo=SS_LR -protocol_families=SS \
7990
-dataset=ic_impl/data/perfect_logit_a.csv -has_label=true \
8091
-use_ttp=true -ttp_server_host=127.0.0.1:9449 \
81-
-parties=127.0.0.1:9530,127.0.0.1:9531
92+
-parties=127.0.0.1:9530,127.0.0.1:9531 -ttp_asym_crypto_schema=sm2 \
93+
-ttp_public_key=LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUZvd0ZBWUlLb0VjejFVQmdpMEdDQ3FCSE05VkFZSXRBMElBQkxROGc3Q3R3eis3OW1ZQTcrbCtVOWliTjdaSAorVG1yZ0R4bGk2dmpWNTlaaG14c3U4eDNSR1pBS09Bd2gzNnhYcHhHZ2F5MXRGYWtDazNMZFV0azJzND0KLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg==
8294
```
8395

8496
```shell
85-
bazel run ic_impl/ic_main -- -rank=1 -algo=SS_LR -protocol_families=SS \
97+
bazel run -c opt ic_impl/ic_main -- -rank=1 -algo=SS_LR -protocol_families=SS \
8698
-dataset=ic_impl/data/perfect_logit_b.csv -has_label=false \
8799
-use_ttp=true -ttp_server_host=127.0.0.1:9449 \
88-
-parties=127.0.0.1:9530,127.0.0.1:9531
100+
-parties=127.0.0.1:9530,127.0.0.1:9531 -ttp_asym_crypto_schema=sm2 \
101+
-ttp_public_key=LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUZvd0ZBWUlLb0VjejFVQmdpMEdDQ3FCSE05VkFZSXRBMElBQkxROGc3Q3R3eis3OW1ZQTcrbCtVOWliTjdaSAorVG1yZ0R4bGk2dmpWNTlaaG14c3U4eDNSR1pBS09Bd2gzNnhYcHhHZ2F5MXRGYWtDazNMZFV0azJzND0KLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg==
89102
```
90103

91104
### 环境变量传参
@@ -96,7 +109,7 @@ bazel run ic_impl/ic_main -- -rank=1 -algo=SS_LR -protocol_families=SS \
96109

97110
程序运行需要关闭握手过程:
98111
```shell
99-
bazel run ic_impl/ic_main -- -disable_handshake=1
112+
bazel run -c opt ic_impl/ic_main -- -disable_handshake=1
100113
```
101114

102115
SS-LR 算法配置的环境变量如下表所示。环境变量设置可参考 [ss-lr-env-alice.sh](./ic_impl/env/ss-lr-env-alice.sh)[ss-lr-env-bob.sh](./ic_impl/env/ss-lr-env-bob.sh)
@@ -121,7 +134,8 @@ SS-LR 算法配置的环境变量如下表所示。环境变量设置可参考 [
121134
| runtime.component.parameter.shard_serialize_format | raw | serialization format used for communicating secret shares |
122135
| runtime.component.parameter.use_ttp | true | whether to use beaver service |
123136
| runtime.component.parameter.ttp_server_host | ip:port | remote ip:port or load-balance uri of beaver service |
124-
| runtime.component.parameter.ttp_session_id | interconnection-root | session id of beaver service |
137+
| runtime.component.parameter.ttp_asym_crypto_schema | sm2 | asym_crypto_schema of beaver service |
138+
| runtime.component.parameter.ttp_public_key | | public key of beaver service |
125139
| runtime.component.parameter.ttp_adjust_rank | 0 | which rank do adjust rpc call to beaver service |
126140
| system.storage.host.url | file://path/to/root | root path of input/output file |
127141
| runtime.component.input.train_data | {"namespace":"data","name":"perfect_logit_a.csv"} | relative path and name of input file |

WORKSPACE

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ protocol_deps()
2020
load("//bazel:repositories.bzl", "ic_impl_deps")
2121
ic_impl_deps()
2222

23-
load("@psi//bazel:repositories.bzl", "psi_deps")
24-
25-
psi_deps()
26-
2723
# spu
2824
load("@spulib//bazel:repositories.bzl", "spu_deps")
2925
spu_deps()
3026

27+
load("@psi//bazel:repositories.bzl", "psi_deps")
28+
psi_deps()
29+
3130
# yacl
3231
load("@yacl//bazel:repositories.bzl", "yacl_deps")
3332
yacl_deps()

bazel/repositories.bzl

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414

1515
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
1616
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
17+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
1718

1819
SECRETFLOW_GIT = "https://github.com/secretflow"
1920

20-
SPU_COMMIT_ID = "8bf3c97da503f1cffd1292c8e365ecbc30675400"
21-
22-
PSI_COMMIT_ID = "330623e9eb42d92ef9701d352af947b70c2c9e7c"
21+
SPU_COMMIT_ID = "74c6d54e5bff9e5d35ab5a73dda98cd9ccf0bfc8"
2322

2423
IC_COMMIT_ID = "30e4220b7444d0bb077a9040f1b428632124e31a"
2524

@@ -35,13 +34,6 @@ def ic_impl_deps():
3534
remote = "{}/{}.git".format(SECRETFLOW_GIT, SPU_REPOSITORY),
3635
)
3736

38-
maybe(
39-
git_repository,
40-
name = "psi",
41-
commit = PSI_COMMIT_ID,
42-
remote = "{}/psi.git".format(SECRETFLOW_GIT),
43-
)
44-
4537
def protocol_deps():
4638
maybe(
4739
git_repository,
@@ -52,8 +44,12 @@ def protocol_deps():
5244

5345
def _com_github_nlohmann_json():
5446
maybe(
55-
git_repository,
47+
http_archive,
5648
name = "com_github_nlohmann_json",
57-
commit = "5d2754306d67d1e654a1a34e1d2e74439a9d53b3",
58-
remote = "git@github.com:nlohmann/json.git",
49+
sha256 = "0d8ef5af7f9794e3263480193c491549b2ba6cc74bb018906202ada498a79406",
50+
strip_prefix = "json-3.11.3",
51+
type = "tar.gz",
52+
urls = [
53+
"https://github.com/nlohmann/json/archive/refs/tags/v3.11.3.tar.gz",
54+
],
5955
)

ic_impl/algo/lr/lr_handler.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ bool LrHandler::ProcessHandshakeResponse(const HandshakeResponseV2& response) {
286286
YACL_ENFORCE(ss_param.triple_config().version() ==
287287
ctx_->ttp_config.ttp_server_version);
288288
ctx_->ttp_config.ttp_server_host = ss_param.triple_config().server_host();
289-
ctx_->ttp_config.ttp_session_id = ss_param.triple_config().session_id();
290289
ctx_->ttp_config.ttp_adjust_rank = ss_param.triple_config().adjust_rank();
291290

292291
return true;
@@ -642,8 +641,6 @@ HandshakeResponseV2 LrHandler::BuildHandshakeResponse() {
642641
ctx_->ttp_config.ttp_server_host);
643642
ss_param.mutable_triple_config()->set_version(
644643
ctx_->ttp_config.ttp_server_version);
645-
ss_param.mutable_triple_config()->set_session_id(
646-
ctx_->ttp_config.ttp_session_id);
647644
ss_param.mutable_triple_config()->set_adjust_rank(
648645
ctx_->ttp_config.ttp_adjust_rank);
649646
response.add_protocol_family_params()->PackFrom(ss_param);
@@ -755,10 +752,12 @@ std::unique_ptr<spu::SPUContext> LrHandler::MakeSpuContext() {
755752
config.set_beaver_type(spu::RuntimeConfig_BeaverType_TrustedThirdParty);
756753
config.mutable_ttp_beaver_config()->set_server_host(
757754
ctx_->ttp_config.ttp_server_host);
755+
config.mutable_ttp_beaver_config()->set_asym_crypto_schema(
756+
ctx_->ttp_config.ttp_asym_crypto_schema);
757+
config.mutable_ttp_beaver_config()->set_server_public_key(
758+
ctx_->ttp_config.ttp_public_key);
758759
config.mutable_ttp_beaver_config()->set_adjust_rank(
759760
ctx_->ttp_config.ttp_adjust_rank);
760-
config.mutable_ttp_beaver_config()->set_session_id(
761-
ctx_->ttp_config.ttp_session_id);
762761
} else {
763762
config.set_beaver_type(spu::RuntimeConfig_BeaverType_TrustedFirstParty);
764763
}

ic_impl/env/ss-lr-env-alice.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ exec env \
2222
"runtime.component.parameter.shard_serialize_format=raw" \
2323
"runtime.component.parameter.use_ttp=true" \
2424
"runtime.component.parameter.ttp_server_host=127.0.0.1:9449" \
25-
"runtime.component.parameter.ttp_session_id=interconnection-root-1" \
25+
"runtime.component.parameter.ttp_asym_crypto_schema=sm2" \
26+
"runtime.component.parameter.ttp_public_key=LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUZvd0ZBWUlLb0VjejFVQmdpMEdDQ3FCSE05VkFZSXRBMElBQkxROGc3Q3R3eis3OW1ZQTcrbCtVOWliTjdaSAorVG1yZ0R4bGk2dmpWNTlaaG14c3U4eDNSR1pBS09Bd2gzNnhYcHhHZ2F5MXRGYWtDazNMZFV0azJzND0KLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg==" \
2627
"runtime.component.parameter.ttp_adjust_rank=0" \
2728
"runtime.component.parameter.label_owner=host.0" \
2829
'runtime.component.parameter.feature_nums={"host.0":10, "guest.0":10}' \

ic_impl/env/ss-lr-env-bob.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ exec env \
2222
"runtime.component.parameter.shard_serialize_format=raw" \
2323
"runtime.component.parameter.use_ttp=true" \
2424
"runtime.component.parameter.ttp_server_host=127.0.0.1:9449" \
25-
"runtime.component.parameter.ttp_session_id=interconnection-root-1" \
25+
"runtime.component.parameter.ttp_asym_crypto_schema=sm2" \
26+
"runtime.component.parameter.ttp_public_key=LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUZvd0ZBWUlLb0VjejFVQmdpMEdDQ3FCSE05VkFZSXRBMElBQkxROGc3Q3R3eis3OW1ZQTcrbCtVOWliTjdaSAorVG1yZ0R4bGk2dmpWNTlaaG14c3U4eDNSR1pBS09Bd2gzNnhYcHhHZ2F5MXRGYWtDazNMZFV0azJzND0KLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg==" \
2627
"runtime.component.parameter.ttp_adjust_rank=0" \
2728
"runtime.component.parameter.label_owner=host.0" \
2829
'runtime.component.parameter.feature_nums={"host.0":10, "guest.0":10}' \

ic_impl/protocol_family/ss/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ cc_library(
2323
deps = [
2424
"//ic_impl:util",
2525
"//ic_impl:handshake_cc_proto",
26+
"@com_github_brpc_brpc//:brpc",
2627
"@com_github_gflags_gflags//:gflags",
2728
]
2829
)

ic_impl/protocol_family/ss/ss.cc

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "ic_impl/protocol_family/ss/ss.h"
1616

17+
#include "butil/base64.h"
1718
#include "gflags/gflags.h"
1819

1920
#include "ic_impl/util.h"
@@ -33,8 +34,9 @@ DEFINE_bool(use_ttp, false, "whether use trusted third party's beaver service");
3334
DEFINE_string(
3435
ttp_server_host, "127.0.0.1:9449",
3536
"trustedThirdParty beaver server's remote ip:port or load-balance uri");
36-
DEFINE_string(ttp_session_id, "interconnection-root",
37-
"trustedThirdParty beaver server's session id");
37+
DEFINE_string(ttp_asym_crypto_schema, "sm2",
38+
"asym_crypto_schema: support [\"SM2\"]");
39+
DEFINE_string(ttp_public_key, "", "TTP public key");
3840
DEFINE_int32(ttp_adjust_rank, 0, "which rank do adjust rpc call");
3941

4042
namespace ic_impl::protocol_family::ss {
@@ -77,8 +79,16 @@ std::string SuggestedTtpServerHost() {
7779
return util::GetParamEnv("ttp_server_host", FLAGS_ttp_server_host);
7880
}
7981

80-
std::string SuggestedTtpSessionId() {
81-
return util::GetParamEnv("ttp_session_id", FLAGS_ttp_session_id);
82+
std::string SuggestedTtpAsymCryptoSchema() {
83+
return util::GetParamEnv("ttp_asym_crypto_schema",
84+
FLAGS_ttp_asym_crypto_schema);
85+
}
86+
87+
std::string SuggestedTtpPublicKey() {
88+
std::string ret;
89+
auto pk = util::GetParamEnv("ttp_public_key", FLAGS_ttp_public_key);
90+
YACL_ENFORCE(butil::Base64Decode(pk, &ret));
91+
return ret;
8292
}
8393

8494
int32_t SuggestedTtpAdjustRank() {
@@ -102,7 +112,8 @@ TrustedThirdPartyConfig SuggestedTtpConfig() {
102112
TrustedThirdPartyConfig ttp_config;
103113
ttp_config.use_ttp = SuggestedUseTtp();
104114
ttp_config.ttp_server_host = SuggestedTtpServerHost();
105-
ttp_config.ttp_session_id = SuggestedTtpSessionId();
115+
ttp_config.ttp_asym_crypto_schema = SuggestedTtpAsymCryptoSchema();
116+
ttp_config.ttp_public_key = SuggestedTtpPublicKey();
106117
ttp_config.ttp_adjust_rank = SuggestedTtpAdjustRank();
107118

108119
return ttp_config;

ic_impl/protocol_family/ss/ss.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ struct SsProtocolParam {
2929
struct TrustedThirdPartyConfig {
3030
bool use_ttp;
3131
std::string ttp_server_host;
32-
int32_t ttp_server_version = 1;
33-
std::string ttp_session_id;
32+
int32_t ttp_server_version = 2;
33+
std::string ttp_asym_crypto_schema;
34+
std::string ttp_public_key;
3435
int32_t ttp_adjust_rank;
3536
};
3637

0 commit comments

Comments
 (0)