diff --git a/packages/client/libclient-py/quickmpc/proto/common_types/common_types_pb2.py b/packages/client/libclient-py/quickmpc/proto/common_types/common_types_pb2.py index e9ca1ed9e..a4e21a272 100644 --- a/packages/client/libclient-py/quickmpc/proto/common_types/common_types_pb2.py +++ b/packages/client/libclient-py/quickmpc/proto/common_types/common_types_pb2.py @@ -11,7 +11,7 @@ _sym_db = _symbol_database.Default() -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1f\x63ommon_types/common_types.proto\x12\x0fpb_common_types\"{\n\x11ProcedureProgress\x12\n\n\x02id\x18\x01 \x01(\x04\x12\x13\n\x0b\x64\x65scription\x18\x02 \x01(\t\x12\x10\n\x08progress\x18\x03 \x01(\x02\x12\x11\n\tcompleted\x18\x04 \x01(\x08\x12\x14\n\x07\x64\x65tails\x18\x05 \x01(\tH\x00\x88\x01\x01\x42\n\n\x08_details\"\x83\x01\n\x0bJobProgress\x12\x10\n\x08job_uuid\x18\x01 \x01(\t\x12*\n\x06status\x18\x02 \x01(\x0e\x32\x1a.pb_common_types.JobStatus\x12\x36\n\nprogresses\x18\x03 \x03(\x0b\x32\".pb_common_types.ProcedureProgress\"\x8d\x01\n\nStacktrace\x12\x31\n\x06\x66rames\x18\x01 \x03(\x0b\x32!.pb_common_types.Stacktrace.Frame\x1aL\n\x05\x46rame\x12\x17\n\x0fsource_location\x18\x01 \x01(\t\x12\x13\n\x0bsource_line\x18\x02 \x01(\x04\x12\x15\n\rfunction_name\x18\x03 \x01(\t\"\x93\x01\n\x0cJobErrorInfo\x12\x0c\n\x04what\x18\x01 \x01(\t\x12\x1c\n\x0f\x61\x64\x64itional_info\x18\x02 \x01(\tH\x00\x88\x01\x01\x12\x34\n\nstacktrace\x18\x03 \x01(\x0b\x32\x1b.pb_common_types.StacktraceH\x01\x88\x01\x01\x42\x12\n\x10_additional_infoB\r\n\x0b_stacktrace\"I\n\x06Schema\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x31\n\x04type\x18\x02 \x01(\x0e\x32#.pb_common_types.ShareValueTypeEnum*g\n\tJobStatus\x12\x0b\n\x07UNKNOWN\x10\x00\x12\t\n\x05\x45RROR\x10\x01\x12\x0c\n\x08RECEIVED\x10\x02\x12\x0b\n\x07PRE_JOB\x10\x03\x12\x0b\n\x07READ_DB\x10\x04\x12\x0b\n\x07\x43OMPUTE\x10\x05\x12\r\n\tCOMPLETED\x10\x06*\xf5\x01\n\x11\x43omputationMethod\x12\"\n\x1e\x43OMPUTATION_METHOD_UNSPECIFIED\x10\x00\x12\x1b\n\x17\x43OMPUTATION_METHOD_MEAN\x10\x01\x12\x1f\n\x1b\x43OMPUTATION_METHOD_VARIANCE\x10\x02\x12\x1a\n\x16\x43OMPUTATION_METHOD_SUM\x10\x03\x12\x1d\n\x19\x43OMPUTATION_METHOD_CORREL\x10\x04\x12 \n\x1c\x43OMPUTATION_METHOD_MESH_CODE\x10\x05\x12!\n\x1d\x43OMPUTATION_METHOD_JOIN_TABLE\x10\x06*\x8b\x01\n\x12ShareValueTypeEnum\x12 \n\x1cSHARE_VALUE_TYPE_UNSPECIFIED\x10\x00\x12 \n\x1cSHARE_VALUE_TYPE_FIXED_POINT\x10\x01\x12\x31\n-SHARE_VALUE_TYPE_UTF_8_INTEGER_REPRESENTATION\x10\x02\x42\x39Z7github.com/acompany-develop/QuickMPC/proto/common_typesb\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1f\x63ommon_types/common_types.proto\x12\x0fpb_common_types\"{\n\x11ProcedureProgress\x12\n\n\x02id\x18\x01 \x01(\x04\x12\x13\n\x0b\x64\x65scription\x18\x02 \x01(\t\x12\x10\n\x08progress\x18\x03 \x01(\x02\x12\x11\n\tcompleted\x18\x04 \x01(\x08\x12\x14\n\x07\x64\x65tails\x18\x05 \x01(\tH\x00\x88\x01\x01\x42\n\n\x08_details\"\x83\x01\n\x0bJobProgress\x12\x10\n\x08job_uuid\x18\x01 \x01(\t\x12*\n\x06status\x18\x02 \x01(\x0e\x32\x1a.pb_common_types.JobStatus\x12\x36\n\nprogresses\x18\x03 \x03(\x0b\x32\".pb_common_types.ProcedureProgress\"\x8d\x01\n\nStacktrace\x12\x31\n\x06\x66rames\x18\x01 \x03(\x0b\x32!.pb_common_types.Stacktrace.Frame\x1aL\n\x05\x46rame\x12\x17\n\x0fsource_location\x18\x01 \x01(\t\x12\x13\n\x0bsource_line\x18\x02 \x01(\x04\x12\x15\n\rfunction_name\x18\x03 \x01(\t\"\x93\x01\n\x0cJobErrorInfo\x12\x0c\n\x04what\x18\x01 \x01(\t\x12\x1c\n\x0f\x61\x64\x64itional_info\x18\x02 \x01(\tH\x00\x88\x01\x01\x12\x34\n\nstacktrace\x18\x03 \x01(\x0b\x32\x1b.pb_common_types.StacktraceH\x01\x88\x01\x01\x42\x12\n\x10_additional_infoB\r\n\x0b_stacktrace\"I\n\x06Schema\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x31\n\x04type\x18\x02 \x01(\x0e\x32#.pb_common_types.ShareValueTypeEnum\"+\n\nBigIntByte\x12\x0b\n\x03sgn\x18\x01 \x01(\x08\x12\x10\n\x08\x61\x62s_byte\x18\x02 \x01(\x0c*g\n\tJobStatus\x12\x0b\n\x07UNKNOWN\x10\x00\x12\t\n\x05\x45RROR\x10\x01\x12\x0c\n\x08RECEIVED\x10\x02\x12\x0b\n\x07PRE_JOB\x10\x03\x12\x0b\n\x07READ_DB\x10\x04\x12\x0b\n\x07\x43OMPUTE\x10\x05\x12\r\n\tCOMPLETED\x10\x06*\xf5\x01\n\x11\x43omputationMethod\x12\"\n\x1e\x43OMPUTATION_METHOD_UNSPECIFIED\x10\x00\x12\x1b\n\x17\x43OMPUTATION_METHOD_MEAN\x10\x01\x12\x1f\n\x1b\x43OMPUTATION_METHOD_VARIANCE\x10\x02\x12\x1a\n\x16\x43OMPUTATION_METHOD_SUM\x10\x03\x12\x1d\n\x19\x43OMPUTATION_METHOD_CORREL\x10\x04\x12 \n\x1c\x43OMPUTATION_METHOD_MESH_CODE\x10\x05\x12!\n\x1d\x43OMPUTATION_METHOD_JOIN_TABLE\x10\x06*\x8b\x01\n\x12ShareValueTypeEnum\x12 \n\x1cSHARE_VALUE_TYPE_UNSPECIFIED\x10\x00\x12 \n\x1cSHARE_VALUE_TYPE_FIXED_POINT\x10\x01\x12\x31\n-SHARE_VALUE_TYPE_UTF_8_INTEGER_REPRESENTATION\x10\x02\x42\x39Z7github.com/acompany-develop/QuickMPC/proto/common_typesb\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) @@ -21,12 +21,12 @@ DESCRIPTOR._options = None DESCRIPTOR._serialized_options = b'Z7github.com/acompany-develop/QuickMPC/proto/common_types' - _globals['_JOBSTATUS']._serialized_start = 680 - _globals['_JOBSTATUS']._serialized_end = 783 - _globals['_COMPUTATIONMETHOD']._serialized_start = 786 - _globals['_COMPUTATIONMETHOD']._serialized_end = 1031 - _globals['_SHAREVALUETYPEENUM']._serialized_start = 1034 - _globals['_SHAREVALUETYPEENUM']._serialized_end = 1173 + _globals['_JOBSTATUS']._serialized_start = 725 + _globals['_JOBSTATUS']._serialized_end = 828 + _globals['_COMPUTATIONMETHOD']._serialized_start = 831 + _globals['_COMPUTATIONMETHOD']._serialized_end = 1076 + _globals['_SHAREVALUETYPEENUM']._serialized_start = 1079 + _globals['_SHAREVALUETYPEENUM']._serialized_end = 1218 _globals['_PROCEDUREPROGRESS']._serialized_start = 52 _globals['_PROCEDUREPROGRESS']._serialized_end = 175 _globals['_JOBPROGRESS']._serialized_start = 178 @@ -39,4 +39,6 @@ _globals['_JOBERRORINFO']._serialized_end = 603 _globals['_SCHEMA']._serialized_start = 605 _globals['_SCHEMA']._serialized_end = 678 + _globals['_BIGINTBYTE']._serialized_start = 680 + _globals['_BIGINTBYTE']._serialized_end = 723 # @@protoc_insertion_point(module_scope) diff --git a/packages/client/libclient-py/quickmpc/proto/common_types/common_types_pb2.pyi b/packages/client/libclient-py/quickmpc/proto/common_types/common_types_pb2.pyi index 139dbaf88..ca1e8558e 100644 --- a/packages/client/libclient-py/quickmpc/proto/common_types/common_types_pb2.pyi +++ b/packages/client/libclient-py/quickmpc/proto/common_types/common_types_pb2.pyi @@ -220,3 +220,21 @@ class Schema(google.protobuf.message.Message): def ClearField(self, field_name: typing_extensions.Literal["name", b"name", "type", b"type"]) -> None: ... global___Schema = Schema + +@typing_extensions.final +class BigIntByte(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + SGN_FIELD_NUMBER: builtins.int + ABS_BYTE_FIELD_NUMBER: builtins.int + sgn: builtins.bool + abs_byte: builtins.bytes + def __init__( + self, + *, + sgn: builtins.bool = ..., + abs_byte: builtins.bytes = ..., + ) -> None: ... + def ClearField(self, field_name: typing_extensions.Literal["abs_byte", b"abs_byte", "sgn", b"sgn"]) -> None: ... + +global___BigIntByte = BigIntByte diff --git a/packages/client/libclient-py/quickmpc/share/share.py b/packages/client/libclient-py/quickmpc/share/share.py index 8e4bb7065..338dcf9af 100644 --- a/packages/client/libclient-py/quickmpc/share/share.py +++ b/packages/client/libclient-py/quickmpc/share/share.py @@ -1,5 +1,8 @@ +import inspect +import threading from dataclasses import dataclass -from decimal import Decimal +from decimal import Decimal, getcontext +from functools import wraps from typing import (Any, Callable, ClassVar, List, Optional, Sequence, Tuple, Union) @@ -16,6 +19,47 @@ logger = get_logger() +# getcontext().precがthreadごとに初期化されてしまうため, +# theread毎に初期化し返せるようできるようにフラグを管理する +_local_dict = threading.local() +# Triple cのshareが23byteで約10^{54}なので, 余裕を持って収まるように100にしておく +_decimal_prec = 100 + + +def set_decimal_prec(): + try: + _local_dict.is_initialized + except Exception: + getcontext().prec = _decimal_prec + _local_dict.is_initialized = True + + +set_decimal_prec() + + +def _verify_decimal_prec(f): + """メソッドにprecのverifyを適用させるデコレータ""" + @wraps(f) + def _wrapper(*args, **kw): + set_decimal_prec() + if getcontext().prec != _decimal_prec: + raise RuntimeError( + f"Decimal context prec is must be {_decimal_prec}.") + return f(*args, **kw) + return _wrapper + + +def _verify_decimal_prec_all(cls): + """クラスの全てのメソッドにprecのverifyを適用させるデコレータ""" + for name, fn in inspect.getmembers(cls): + if name.startswith('__'): + continue + if callable(getattr(cls, name)): + setattr(cls, name, _verify_decimal_prec(fn)) + return cls + + +@_verify_decimal_prec_all @dataclass(frozen=True) class Share: __share_random_range: ClassVar[Tuple[Decimal, Decimal]] =\ diff --git a/packages/client/libclient-py/tests/unit_tests/share/test_share_recons.py b/packages/client/libclient-py/tests/unit_tests/share/test_share_recons.py index 8c64e2d9a..b98b72fc0 100644 --- a/packages/client/libclient-py/tests/unit_tests/share/test_share_recons.py +++ b/packages/client/libclient-py/tests/unit_tests/share/test_share_recons.py @@ -1,11 +1,11 @@ import math -from decimal import Decimal +from decimal import Decimal, getcontext import numpy as np import pytest from quickmpc.exception import ArgumentError -from quickmpc.share.share import Share +from quickmpc.share.share import _decimal_prec, Share class TestQMPC: @@ -174,3 +174,23 @@ def test_sharize_recons(self, secrets: list): secrets_2: list = Share.recons(conved) secrets_2 = Share.convert_type(secrets_2) assert (np.allclose(secrets, secrets_2)) + + @pytest.mark.parametrize( + ("secrets", "prec"), + [ + (1, 28), + (1, 280), + ([1], 28), + ([1], 280), + ([[1]], 28), + ([[1]], 280), + ] + ) + def test_recons_decimal_prec_error(self, secrets, prec): + """ 異なるprecが指定されているときにエラーが出るかTest """ + getcontext().prec = prec + with pytest.raises(RuntimeError): + Share.recons(secrets) + + # Global値をいじっているので元の値に戻しておく + getcontext().prec = _decimal_prec diff --git a/packages/client/libclient-py/tests/unit_tests/share/test_share_sharize.py b/packages/client/libclient-py/tests/unit_tests/share/test_share_sharize.py index e0eba8bdd..0d2d2cc93 100644 --- a/packages/client/libclient-py/tests/unit_tests/share/test_share_sharize.py +++ b/packages/client/libclient-py/tests/unit_tests/share/test_share_sharize.py @@ -1,12 +1,12 @@ import math -from decimal import Decimal +from decimal import Decimal, getcontext from typing import List import numpy as np import pytest from quickmpc.exception import ArgumentError -from quickmpc.share.share import Share +from quickmpc.share.share import _decimal_prec, Share def sharize_params(secrets=[1], party_size=3): @@ -154,3 +154,23 @@ def test_sharize_errorhandring(self, args, expected_exception): """ 異常値を与えてエラーが出るかTest """ with pytest.raises(expected_exception): Share.sharize(*args) + + @pytest.mark.parametrize( + ("args", "prec"), + [ + (sharize_params(secrets=1), 28), + (sharize_params(secrets=1), 280), + (sharize_params(secrets=[1]), 28), + (sharize_params(secrets=[1]), 280), + (sharize_params(secrets=[[1]]), 28), + (sharize_params(secrets=[[1]]), 280), + ] + ) + def test_sharize_decimal_prec_error(self, args, prec): + """ 異なるprecが指定されているときにエラーが出るかTest """ + getcontext().prec = prec + with pytest.raises(RuntimeError): + Share.sharize(*args) + + # Global値をいじっているので元の値に戻しておく + getcontext().prec = _decimal_prec diff --git a/packages/server/beaver_triple_service/go.mod b/packages/server/beaver_triple_service/go.mod index 215f96c35..f81c4a757 100644 --- a/packages/server/beaver_triple_service/go.mod +++ b/packages/server/beaver_triple_service/go.mod @@ -2,9 +2,13 @@ module github.com/acompany-develop/QuickMPC/packages/server/beaver_triple_servic go 1.18 -replace github.com/acompany-develop/QuickMPC/proto/engine_to_bts => ./../proto/engine_to_bts +replace ( + github.com/acompany-develop/QuickMPC/proto/common_types => ./../proto/common_types + github.com/acompany-develop/QuickMPC/proto/engine_to_bts => ./../proto/engine_to_bts +) require ( + github.com/acompany-develop/QuickMPC/proto/common_types v0.0.0-00010101000000-000000000000 github.com/acompany-develop/QuickMPC/proto/engine_to_bts v0.0.0-00010101000000-000000000000 github.com/golang-jwt/jwt/v4 v4.4.2 github.com/google/uuid v1.3.0 diff --git a/packages/server/beaver_triple_service/server/engine_to_bts/e2b.go b/packages/server/beaver_triple_service/server/engine_to_bts/e2b.go index 7b22ac056..7f3c25489 100644 --- a/packages/server/beaver_triple_service/server/engine_to_bts/e2b.go +++ b/packages/server/beaver_triple_service/server/engine_to_bts/e2b.go @@ -61,7 +61,7 @@ func (s *server) GetTriples(ctx context.Context, in *pb.GetRequest) (*pb.GetTrip if err != nil { return nil, err } - logger.Infof("jobId: %d, partyId: %d\n", in.GetJobId(), partyId,) + logger.Infof("jobId: %d, partyId: %d\n", in.GetJobId(), partyId) triples, err := tg.GetTriples(claims, in.GetJobId(), partyId, in.GetAmount(), in.GetRequestId()) if err != nil { diff --git a/packages/server/beaver_triple_service/server/engine_to_bts/e2b_test.go b/packages/server/beaver_triple_service/server/engine_to_bts/e2b_test.go index aea1036d1..ae3c2ef2f 100644 --- a/packages/server/beaver_triple_service/server/engine_to_bts/e2b_test.go +++ b/packages/server/beaver_triple_service/server/engine_to_bts/e2b_test.go @@ -3,14 +3,16 @@ package e2bserver import ( "context" "fmt" + "math/big" "os" "sync" "testing" jwt_types "github.com/acompany-develop/QuickMPC/packages/server/beaver_triple_service/jwt" - ts "github.com/acompany-develop/QuickMPC/packages/server/beaver_triple_service/triple_store" rbs "github.com/acompany-develop/QuickMPC/packages/server/beaver_triple_service/rand_bit_store" + ts "github.com/acompany-develop/QuickMPC/packages/server/beaver_triple_service/triple_store" utils "github.com/acompany-develop/QuickMPC/packages/server/beaver_triple_service/utils" + pb_types "github.com/acompany-develop/QuickMPC/proto/common_types" pb "github.com/acompany-develop/QuickMPC/proto/engine_to_bts" "google.golang.org/grpc/metadata" @@ -133,16 +135,28 @@ func testGetTriplesByJobId(t *testing.T, client pb.EngineToBtsClient, amount uin }) } +func convertToBigInt(b *pb_types.BigIntByte) *big.Int { + var ret *big.Int = big.NewInt(0) + bytes := b.AbsByte + ret.SetBytes(bytes) + if b.Sgn { + ret.Neg(ret) + } + return ret +} + func testValidityOfTriples(t *testing.T) { for _, triples := range DbTripleTest.Triples { for i := 0; i < len(triples[1]); i++ { - aShareSum, bShareSum, cShareSum := int64(0), int64(0), int64(0) + aShareSum, bShareSum, cShareSum := big.NewInt(0), big.NewInt(0), big.NewInt(0) for partyId := uint32(1); partyId <= uint32(len(triples)); partyId++ { - aShareSum += triples[partyId][i].A - bShareSum += triples[partyId][i].B - cShareSum += triples[partyId][i].C + aShareSum.Add(aShareSum, convertToBigInt(triples[partyId][i].A)) + bShareSum.Add(bShareSum, convertToBigInt(triples[partyId][i].B)) + cShareSum.Add(cShareSum, convertToBigInt(triples[partyId][i].C)) } - if aShareSum*bShareSum != cShareSum { + ab := big.NewInt(0) + ab.Mul(aShareSum, bShareSum) + if ab.Cmp(cShareSum) != 0 { t.Fatal("a*b != c") } } @@ -263,8 +277,10 @@ func TestGetRandBits_1_10000(t *testing.T) { testGetRandBits(t, 1, 10000) } func TestGetRandBits_100_1(t *testing.T) { testGetRandBits(t, 100, 1) } func TestGetRandBits_100_100(t *testing.T) { testGetRandBits(t, 100, 100) } + // func TestGetRandBits_100_10000(t *testing.T) { testGetRandBits(t, 100, 10000) } func TestGetRandBits_10000_1(t *testing.T) { testGetRandBits(t, 10000, 1) } func TestGetRandBits_10000_100(t *testing.T) { testGetRandBits(t, 10000, 100) } -// func TestGetRandBits_10000_10000(t *testing.T) { testGetRandBits(t, 10000, 10000) } \ No newline at end of file + +// func TestGetRandBits_10000_10000(t *testing.T) { testGetRandBits(t, 10000, 10000) } diff --git a/packages/server/beaver_triple_service/triple_generator/triple_generator.go b/packages/server/beaver_triple_service/triple_generator/triple_generator.go index 81fe277c3..b76cefe6a 100644 --- a/packages/server/beaver_triple_service/triple_generator/triple_generator.go +++ b/packages/server/beaver_triple_service/triple_generator/triple_generator.go @@ -2,41 +2,49 @@ package triplegenerator import ( "errors" + "math/big" jwt_types "github.com/acompany-develop/QuickMPC/packages/server/beaver_triple_service/jwt" logger "github.com/acompany-develop/QuickMPC/packages/server/beaver_triple_service/log" ts "github.com/acompany-develop/QuickMPC/packages/server/beaver_triple_service/triple_store" utils "github.com/acompany-develop/QuickMPC/packages/server/beaver_triple_service/utils" + pb_types "github.com/acompany-develop/QuickMPC/proto/common_types" pb "github.com/acompany-develop/QuickMPC/proto/engine_to_bts" ) var Db *ts.SafeTripleStore -var tripleRandMax = int64(1000) -var tripleRandMin = int64(-1000) + +// a,b の生成範囲は 10^{19+8} ~ 2^{90} +var tripleBitLength uint32 = 90 func init() { Db = ts.GetInstance() } -func sharize(data int64, size uint32) ([]int64, error) { - sharizeRandMin := - int64(1 << 60) - sharizeRandMax := int64(1 << 60) - shares, err := utils.GetRandInt64Slice(uint64(size-1), sharizeRandMin, sharizeRandMax) +func sharize(data big.Int, bitLength uint32, party_num uint32) ([]big.Int, error) { + shares, err := utils.GetRandBigInts(bitLength, party_num-1) if err != nil { errText := "乱数取得に失敗" logger.Error(errText) return nil, errors.New(errText) } - sum := int64(0) - for _, x := range shares { - sum += x + for _, share := range shares { + data.Sub(&data, &share) } + shares = append(shares, data) - shares = append(shares, data-sum) return shares, nil } +func toBytes(share big.Int) (pb_types.BigIntByte, error) { + ret := pb_types.BigIntByte{ + Sgn: share.Sign() == -1, + AbsByte: share.Bytes(), + } + return ret, nil +} + func GenerateTriples(claims *jwt_types.Claim, amount uint32) (map[uint32]([]*ts.Triple), error) { ret := make(map[uint32]([]*ts.Triple)) party_num := uint32(len(claims.PartyInfo)) @@ -45,37 +53,50 @@ func GenerateTriples(claims *jwt_types.Claim, amount uint32) (map[uint32]([]*ts. ret[partyId] = []*ts.Triple{} } - for i := uint32(0); i < amount; i++ { - randInt64Slice, err := utils.GetRandInt64Slice(2, tripleRandMin, tripleRandMax) - if err != nil { - errText := "乱数取得に失敗" - logger.Error(errText) - return nil, errors.New(errText) - } + ab, err := utils.GetRandBigInts(tripleBitLength, 2*amount) + if err != nil { + errText := "乱数取得に失敗" + logger.Error(errText) + return nil, errors.New(errText) + } - a := randInt64Slice[0] - b := randInt64Slice[1] - c := a * b + for i := uint32(0); i < 2*amount; i += 2 { + var a big.Int = ab[i] + var b big.Int = ab[i+1] + var c big.Int + c.Mul(&a, &b) - aShares, err := sharize(a, party_num) + aShares, err := sharize(a, tripleBitLength, party_num) if err != nil { return nil, err } - bShares, err := sharize(b, party_num) + bShares, err := sharize(b, tripleBitLength, party_num) if err != nil { return nil, err } - cShares, err := sharize(c, party_num) + cShares, err := sharize(c, 2*tripleBitLength, party_num) if err != nil { return nil, err } // partyIdは1-index for partyId := uint32(1); partyId <= party_num; partyId++ { + a_, err := toBytes(aShares[partyId-1]) + if err != nil { + return nil, err + } + b_, err := toBytes(bShares[partyId-1]) + if err != nil { + return nil, err + } + c_, err := toBytes(cShares[partyId-1]) + if err != nil { + return nil, err + } t := ts.Triple{ - A: aShares[partyId-1], - B: bShares[partyId-1], - C: cShares[partyId-1], + A: &a_, + B: &b_, + C: &c_, } ret[partyId] = append(ret[partyId], &t) } @@ -88,7 +109,7 @@ func GetTriples(claims *jwt_types.Claim, jobId uint32, partyId uint32, amount ui Db.Mux.Lock() defer Db.Mux.Unlock() - if partyId == 0 || partyId > uint32(len(claims.PartyInfo)){ + if partyId == 0 || partyId > uint32(len(claims.PartyInfo)) { errText := "out range partyId" logger.Error(errText) return nil, errors.New(errText) @@ -104,14 +125,14 @@ func GetTriples(claims *jwt_types.Claim, jobId uint32, partyId uint32, amount ui pre_id, ok := Db.PreID[jobId][partyId] // request が初めての場合 - if !ok{ + if !ok { Db.PreID[jobId][partyId] = requestId Db.PreAmount[jobId][partyId] = amount } // 前回の request と異なる場合 // requestId が -1 の場合は必ず前回と異なるとみなす(test用) - if ok && (pre_id != requestId || requestId == -1){ + if ok && (pre_id != requestId || requestId == -1) { pre_amount := Db.PreAmount[jobId][partyId] Db.Triples[jobId][partyId] = Db.Triples[jobId][partyId][pre_amount:] Db.PreID[jobId][partyId] = requestId @@ -119,7 +140,7 @@ func GetTriples(claims *jwt_types.Claim, jobId uint32, partyId uint32, amount ui } // 今回返す Triples がまだ生成されてない場合 - if len(Db.Triples[jobId][partyId]) == 0{ + if len(Db.Triples[jobId][partyId]) == 0 { newTriples, err := GenerateTriples(claims, amount) if err != nil { return nil, err @@ -137,4 +158,4 @@ func GetTriples(claims *jwt_types.Claim, jobId uint32, partyId uint32, amount ui triples := Db.Triples[jobId][partyId][:amount] return triples, nil -} \ No newline at end of file +} diff --git a/packages/server/beaver_triple_service/triple_generator/triple_generator_test.go b/packages/server/beaver_triple_service/triple_generator/triple_generator_test.go index 5f90353bd..9a7c82393 100644 --- a/packages/server/beaver_triple_service/triple_generator/triple_generator_test.go +++ b/packages/server/beaver_triple_service/triple_generator/triple_generator_test.go @@ -1,43 +1,46 @@ package triplegenerator_test import ( - "os" "fmt" - "testing" + "math/big" + "os" "sync" + "testing" jwt_types "github.com/acompany-develop/QuickMPC/packages/server/beaver_triple_service/jwt" - utils "github.com/acompany-develop/QuickMPC/packages/server/beaver_triple_service/utils" tg "github.com/acompany-develop/QuickMPC/packages/server/beaver_triple_service/triple_generator" ts "github.com/acompany-develop/QuickMPC/packages/server/beaver_triple_service/triple_store" + utils "github.com/acompany-develop/QuickMPC/packages/server/beaver_triple_service/utils" + pb_types "github.com/acompany-develop/QuickMPC/proto/common_types" ) -type TriplesStock struct{ +type TriplesStock struct { Stock map[uint32](map[uint32]([]*ts.Triple)) - Mux sync.Mutex + Mux sync.Mutex } + var TS TriplesStock func all_init() { TS.Stock = make(map[uint32](map[uint32]([]*ts.Triple))) tg.Db = &ts.SafeTripleStore{ - Triples: make(map[uint32](map[uint32]([]*ts.Triple))), - PreID: make(map[uint32](map[uint32](int64))), + Triples: make(map[uint32](map[uint32]([]*ts.Triple))), + PreID: make(map[uint32](map[uint32](int64))), PreAmount: make(map[uint32](map[uint32](uint32))), } } -func getClaims() (*jwt_types.Claim, error){ +func getClaims() (*jwt_types.Claim, error) { token, ok := os.LookupEnv("BTS_TOKEN") if ok { - claims,err := utils.AuthJWT(token) + claims, err := utils.AuthJWT(token) if err != nil { - return nil,err + return nil, err } - return claims,nil + return claims, nil } - return nil,fmt.Errorf("BTS TOKEN is not valified") + return nil, fmt.Errorf("BTS TOKEN is not valified") } // 固定された (jobId, partyId) に対し requestTimes 回の(長さ amount の) Triples を作成 @@ -52,7 +55,7 @@ func multiGetTriples(t *testing.T, jobId uint32, partyId uint32, amount uint32, TS.Mux.Lock() _, ok := TS.Stock[jobId] - if !ok{ + if !ok { TS.Stock[jobId] = make(map[uint32]([]*ts.Triple)) } @@ -80,16 +83,28 @@ func multiGetTriples(t *testing.T, jobId uint32, partyId uint32, amount uint32, }) } +func convertToBigInt(b *pb_types.BigIntByte) *big.Int { + var ret *big.Int = big.NewInt(0) + bytes := b.AbsByte + ret.SetBytes(bytes) + if b.Sgn { + ret.Neg(ret) + } + return ret +} + func testValidityOfTriples(t *testing.T) { for _, PartyToTriples := range TS.Stock { for i := 0; i < len(PartyToTriples[1]); i++ { - aShareSum, bShareSum, cShareSum := int64(0), int64(0), int64(0) + aShareSum, bShareSum, cShareSum := big.NewInt(0), big.NewInt(0), big.NewInt(0) for partyId := uint32(1); partyId <= uint32(len(PartyToTriples)); partyId++ { - aShareSum += PartyToTriples[partyId][i].A - bShareSum += PartyToTriples[partyId][i].B - cShareSum += PartyToTriples[partyId][i].C + aShareSum.Add(aShareSum, convertToBigInt(PartyToTriples[partyId][i].A)) + bShareSum.Add(bShareSum, convertToBigInt(PartyToTriples[partyId][i].B)) + cShareSum.Add(cShareSum, convertToBigInt(PartyToTriples[partyId][i].C)) } - if aShareSum*bShareSum != cShareSum { + ab := big.NewInt(0) + ab.Mul(aShareSum, bShareSum) + if ab.Cmp(cShareSum) != 0 { t.Fatal("a*b != c") } } @@ -110,37 +125,37 @@ func testParallelGetTriples(t *testing.T, jobNum uint32, amount uint32, requestT for loopPartyId := uint32(1); loopPartyId <= uint32(len(claims.PartyInfo)); loopPartyId++ { jobId := loopJobId partyId := loopPartyId - t.Run("TestTripleGenerator", func(t *testing.T){ + t.Run("TestTripleGenerator", func(t *testing.T) { t.Parallel() multiGetTriples(t, jobId, partyId, amount, requestTime) }) } } - t.Cleanup(func(){ + t.Cleanup(func() { testValidityOfTriples(t) }) } // --- 以下呼ばれる関数群 --- -func TestParallelGetTriples_1_1_1(t *testing.T){ +func TestParallelGetTriples_1_1_1(t *testing.T) { testParallelGetTriples(t, 1, 1, 1) } -func TestParallelGetTriples_10_10_10(t *testing.T){ +func TestParallelGetTriples_10_10_10(t *testing.T) { testParallelGetTriples(t, 10, 10, 10) } -func TestParallelGetTriples_10000_5_5(t *testing.T){ +func TestParallelGetTriples_10000_5_5(t *testing.T) { testParallelGetTriples(t, 10000, 5, 5) } -func TestParallelGetTriples_5_10000_5(t *testing.T){ +func TestParallelGetTriples_5_10000_5(t *testing.T) { testParallelGetTriples(t, 5, 10000, 5) } -func TestParallelGetTriples_5_5_10000(t *testing.T){ +func TestParallelGetTriples_5_5_10000(t *testing.T) { testParallelGetTriples(t, 5, 5, 10000) } // 同じ request ID は同じ Triple -func TestSameRequestId(t *testing.T){ +func TestSameRequestId(t *testing.T) { t.Helper() all_init() @@ -171,7 +186,7 @@ func TestSameRequestId(t *testing.T){ } // 異なる request ID は異なる Triple -func TestDifferentRequestId(t *testing.T){ +func TestDifferentRequestId(t *testing.T) { t.Helper() all_init() @@ -202,7 +217,7 @@ func TestDifferentRequestId(t *testing.T){ } // 範囲外の PartyId が来た時にエラーを吐くか -func TestOutRangePartyId(t *testing.T){ +func TestOutRangePartyId(t *testing.T) { expected_text := "out range partyId" claims, err := getClaims() if err != nil { @@ -210,12 +225,12 @@ func TestOutRangePartyId(t *testing.T){ } partyId := uint32(0) - if _, err := tg.GetTriples(claims, 1, partyId, 1, -1); err.Error() != expected_text{ + if _, err := tg.GetTriples(claims, 1, partyId, 1, -1); err.Error() != expected_text { t.Fatal("does not output 'out range partyId'") } - partyId = uint32(len(claims.PartyInfo)) + uint32(1) - if _, err := tg.GetTriples(claims, 1, partyId, 1, -1); err.Error() != expected_text{ + partyId = uint32(len(claims.PartyInfo)) + uint32(1) + if _, err := tg.GetTriples(claims, 1, partyId, 1, -1); err.Error() != expected_text { t.Fatal("does not output 'out range partyId'") } -} \ No newline at end of file +} diff --git a/packages/server/beaver_triple_service/triple_store/triple_store_test.go b/packages/server/beaver_triple_service/triple_store/triple_store_test.go index bd157c8b5..73f1ee350 100644 --- a/packages/server/beaver_triple_service/triple_store/triple_store_test.go +++ b/packages/server/beaver_triple_service/triple_store/triple_store_test.go @@ -1,12 +1,17 @@ package triplestore_test import ( - "os" + "bytes" + "encoding/binary" "fmt" + "os" + "testing" + jwt_types "github.com/acompany-develop/QuickMPC/packages/server/beaver_triple_service/jwt" - utils "github.com/acompany-develop/QuickMPC/packages/server/beaver_triple_service/utils" ts "github.com/acompany-develop/QuickMPC/packages/server/beaver_triple_service/triple_store" - "testing" + utils "github.com/acompany-develop/QuickMPC/packages/server/beaver_triple_service/utils" + pb_types "github.com/acompany-develop/QuickMPC/proto/common_types" + pb "github.com/acompany-develop/QuickMPC/proto/engine_to_bts" ) var Db *ts.SafeTripleStore @@ -18,51 +23,86 @@ func init() { func getClaims() (*jwt_types.Claim, error) { token, ok := os.LookupEnv("BTS_TOKEN") if ok { - claims,err := utils.AuthJWT(token) + claims, err := utils.AuthJWT(token) if err != nil { - return nil,err + return nil, err } - return claims,nil + return claims, nil + } + + return nil, fmt.Errorf("BTS TOKEN is not valified") +} + +func convertToBigIntByte(a int64) (*pb_types.BigIntByte, error) { + sgn := bool(a < 0) + buf := new(bytes.Buffer) + err := binary.Write(buf, binary.BigEndian, a) + if err != nil { + return nil, err } + byteSlice := buf.Bytes() + return &pb_types.BigIntByte{ + Sgn: sgn, + AbsByte: byteSlice, + }, nil +} - return nil,fmt.Errorf("BTS TOKEN is not valified") +func convertToTriple(a, b, c int64) (*pb.Triple, error) { + a_, err := convertToBigIntByte(a) + if err != nil { + return nil, err + } + b_, err := convertToBigIntByte(b) + if err != nil { + return nil, err + } + c_, err := convertToBigIntByte(c) + if err != nil { + return nil, err + } + return &pb.Triple{ + A: a_, + B: b_, + C: c_, + }, nil } -func generateTriples(amount uint32) map[uint32]([]*ts.Triple) { +func generateTriples(amount uint32) (map[uint32]([]*ts.Triple), error) { ret := make(map[uint32]([]*ts.Triple)) for i := uint32(0); i < amount; i++ { - t := ts.Triple{ - A: 1, - B: 1, - C: 3, + t, err := convertToTriple(1, 1, 3) + if err != nil { + return nil, err } - ret[1] = append(ret[1], &t) + ret[1] = append(ret[1], t) - t = ts.Triple{ - A: 2, - B: 2, - C: 6, + t, err = convertToTriple(2, 2, 6) + if err != nil { + return nil, err } - ret[2] = append(ret[2], &t) + ret[2] = append(ret[2], t) - t = ts.Triple{ - A: 3, - B: 3, - C: 9, + t, err = convertToTriple(3, 3, 9) + if err != nil { + return nil, err } - ret[3] = append(ret[3], &t) + ret[3] = append(ret[3], t) } - return ret + return ret, nil } -func getTriples(t *testing.T, jobId uint32, partyId uint32, amount uint32) []*ts.Triple { +func getTriples(t *testing.T, jobId uint32, partyId uint32, amount uint32) ([]*ts.Triple, error) { Db.Mux.Lock() defer Db.Mux.Unlock() if len(Db.Triples[jobId]) == 0 { - Db.Triples[jobId] = generateTriples(amount) + newTriples, err := generateTriples(amount) + if err != nil { + return nil, err + } + Db.Triples[jobId] = newTriples } triples, ok := Db.Triples[jobId][partyId] @@ -73,7 +113,7 @@ func getTriples(t *testing.T, jobId uint32, partyId uint32, amount uint32) []*ts if len(triples) == 0 { t.Fatal("すでに取得済みのリソースがリクエストされた") } - return triples + return triples, nil } func getTriplesForParallel(t *testing.T, partyId uint32, amount uint32, jobNum uint32) { diff --git a/packages/server/beaver_triple_service/utils/csprng.go b/packages/server/beaver_triple_service/utils/csprng.go index e7021afc8..b3964247c 100644 --- a/packages/server/beaver_triple_service/utils/csprng.go +++ b/packages/server/beaver_triple_service/utils/csprng.go @@ -9,6 +9,28 @@ import ( "math/big" ) +// [0, 2^{bitLength}) の乱数を amount 個生成 +func GetRandBigInts(bitLength uint32, amount uint32) ([]big.Int, error) { + var byteLength uint32 = (bitLength + 8 - 1) / 8 + + bSlice := make([]byte, byteLength * amount) + _, err := rand.Read(bSlice) + if err != nil { + return nil, err + } + + randSlice := make([]big.Int, amount) + + for i := uint32(0); i < amount; i++ { + var n big.Int + buf := bSlice[i*byteLength : (i+1)*byteLength] + n.SetBytes(buf) + randSlice[i] = n + } + + return randSlice, nil +} + func mod(x, y int64) int64 { bx, by := big.NewInt(x), big.NewInt(y) return new(big.Int).Mod(bx, by).Int64() diff --git a/packages/server/beaver_triple_service/utils/csprng_test.go b/packages/server/beaver_triple_service/utils/csprng_test.go index 2382ac7b7..7028aa464 100644 --- a/packages/server/beaver_triple_service/utils/csprng_test.go +++ b/packages/server/beaver_triple_service/utils/csprng_test.go @@ -1,15 +1,74 @@ package utils_test import ( + "errors" + "math/big" "testing" utils "github.com/acompany-develop/QuickMPC/packages/server/beaver_triple_service/utils" ) +// 90bit で指定した時に [0,96)bit が 100000 個で全て作られているか +func TestGetRandBigInts(t *testing.T) { + t.Helper() + rands, err := utils.GetRandBigInts(90, 100000) + if err != nil{ + t.Fatal(err) + } + + x := big.NewInt(0) + + for _, rand := range rands { + sgn := rand.Sign() + if sgn < 0 { + err := errors.New("negative rand") + t.Fatal(err) + } + x.Or(x, &rand) + } + + expected := big.NewInt(1) + expected.Lsh(expected, 96) + expected.Sub(expected, big.NewInt(1)) + + if x.Cmp(expected) != 0 { + err := errors.New("missing bit") + t.Fatal(err) + } +} + +// 8bit 整数 [0,256) が 100000 個で全て作られているか +func TestSpanningGetRandBigInts(t *testing.T) { + t.Helper() + rands, err := utils.GetRandBigInts(8, 100000) + if err != nil{ + t.Fatal(err) + } + + setUint64 := make(map[uint64]struct{}) + for _, rand := range rands { + if !rand.IsUint64() { + err := errors.New("not Uint64") + t.Fatal(err) + } + x := rand.Uint64() + if x >= 256 { + err := errors.New("over 1 byte") + t.Fatal(err) + } + setUint64[x] = struct{}{} + } + + if len(setUint64) != 256 { + err := errors.New("not Spanning") + t.Fatal(err) + } +} + var randMax = int64(10000000) var randMin = int64(-10000000) -func testCsprng(t *testing.T, sliceSize uint64, randMin int64, randMax int64) { +func testGetRandInt64Slice(t *testing.T, sliceSize uint64, randMin int64, randMax int64) { t.Helper() randSlices, err := utils.GetRandInt64Slice(sliceSize, randMin, randMax) if err != nil { @@ -28,12 +87,12 @@ func testCsprng(t *testing.T, sliceSize uint64, randMin int64, randMax int64) { } } -func TestCsprng_1(t *testing.T) { testCsprng(t, 1, randMin, randMax) } -func TestCsprng_100(t *testing.T) { testCsprng(t, 100, randMin, randMax) } -func TestCsprng_10000(t *testing.T) { testCsprng(t, 10000, randMin, randMax) } -func TestCsprng_1000000(t *testing.T) { testCsprng(t, 1000000, randMin, randMax) } +func TestGetRandInt64Slice_1(t *testing.T) { testGetRandInt64Slice(t, 1, randMin, randMax) } +func TestGetRandInt64Slice_100(t *testing.T) { testGetRandInt64Slice(t, 100, randMin, randMax) } +func TestGetRandInt64Slice_10000(t *testing.T) { testGetRandInt64Slice(t, 10000, randMin, randMax) } +func TestGetRandInt64Slice_1000000(t *testing.T) { testGetRandInt64Slice(t, 1000000, randMin, randMax) } -func TestCsprng_CornerCase_1(t *testing.T) { +func TestGetRandInt64Slice_CornerCase_1(t *testing.T) { // sliceSize = 1, randMin == randMaxのケース sliceSize := uint64(1) randMin := int64(1) @@ -57,7 +116,7 @@ func TestCsprng_CornerCase_1(t *testing.T) { } } -func TestCsprng_CornerCase_2(t *testing.T) { +func TestGetRandInt64Slice_CornerCase_2(t *testing.T) { // 閉区間で生成できているかの確認 sliceSize := uint64(1000) randMin := int64(-1) diff --git a/packages/server/computation_container/bts_handler/BUILD b/packages/server/computation_container/bts_handler/BUILD index e457277bc..f2993ab89 100644 --- a/packages/server/computation_container/bts_handler/BUILD +++ b/packages/server/computation_container/bts_handler/BUILD @@ -15,5 +15,8 @@ cc_library( hdrs = [ "job.hpp", ], + deps = [ + "//fixed_point:fixed_point" + ], visibility = ["//visibility:public"], ) \ No newline at end of file diff --git a/packages/server/computation_container/bts_handler/job.hpp b/packages/server/computation_container/bts_handler/job.hpp index 1415a62cb..aafdcc9d3 100644 --- a/packages/server/computation_container/bts_handler/job.hpp +++ b/packages/server/computation_container/bts_handler/job.hpp @@ -4,14 +4,14 @@ #include #include +#include "fixed_point/fixed_point.hpp" + namespace qmpc::BtsHandler::BTSJobType { namespace etb = enginetobts; - -template struct Triple { - using result_type = std::tuple; + using result_type = std::tuple; using response_type = etb::GetTriplesResponse; static inline std::string op_name = "GetTriples"; @@ -33,16 +33,18 @@ struct Triple for (size_t i = 0; i < length; i++) { auto triple = response.triples(i); - ret[i] = std::make_tuple(T(triple.a()), T(triple.b()), T(triple.c())); + FixedPoint a = FixedPoint(triple.a()); + FixedPoint b = FixedPoint(triple.b()); + FixedPoint c = FixedPoint(triple.c()) / FixedPoint::getShift(); + ret[i] = std::make_tuple(a, b, c); } return ret; } }; -template struct RandBit { - using result_type = T; + using result_type = std::int64_t; using response_type = etb::GetRandBitsResponse; static inline std::string op_name = "GetRandBits"; @@ -68,4 +70,4 @@ struct RandBit return ret; } }; -} // namespace qmpc::BtsHandler::BTSJobType \ No newline at end of file +} // namespace qmpc::BtsHandler::BTSJobType diff --git a/packages/server/computation_container/bts_handler/stock_bts.hpp b/packages/server/computation_container/bts_handler/stock_bts.hpp index 3f58491de..8d2598891 100644 --- a/packages/server/computation_container/bts_handler/stock_bts.hpp +++ b/packages/server/computation_container/bts_handler/stock_bts.hpp @@ -11,7 +11,8 @@ namespace qmpc::BtsHandler template class StockBTS { - const std::size_t request_num = 100000; + // Todo : stream にする + const std::size_t request_num = 10000; using Result = typename BTSJob::result_type; thread_local static inline std::queue stock; @@ -53,10 +54,6 @@ class StockBTS return ret; } }; - -template -using StockTriple = StockBTS>; - -template -using StockRandBit = StockBTS>; +using StockTriple = StockBTS; +using StockRandBit = StockBTS; } // namespace qmpc::BtsHandler diff --git a/packages/server/computation_container/client/computation_to_computation_container/client.hpp b/packages/server/computation_container/client/computation_to_computation_container/client.hpp index 77ae29d46..899aaa94c 100644 --- a/packages/server/computation_container/client/computation_to_computation_container/client.hpp +++ b/packages/server/computation_container/client/computation_to_computation_container/client.hpp @@ -73,10 +73,10 @@ class Client } else { - computationtocomputation::BigIntByte *fp = multiple_shares->mutable_fp(); - auto [sgn, byte] = values[i].getSgnByte(); - fp->set_sgn(sgn); - fp->set_byte(byte); + pb_common_types::BigIntByte *fp = multiple_shares->mutable_fp(); + auto val = values[i].getBigIntByte(); + fp->set_abs_byte(val.abs_byte()); + fp->set_sgn(val.sgn()); } } share_vec.push_back(s); diff --git a/packages/server/computation_container/fixed_point/BUILD b/packages/server/computation_container/fixed_point/BUILD index 5d255d795..d96768380 100644 --- a/packages/server/computation_container/fixed_point/BUILD +++ b/packages/server/computation_container/fixed_point/BUILD @@ -14,5 +14,8 @@ cc_library( hdrs = [ "fixed_point.hpp", ], + deps = [ + "@proto//common_types:common_types_cc_proto", + ], visibility = ["//visibility:public"] ) diff --git a/packages/server/computation_container/fixed_point/fixed_point.hpp b/packages/server/computation_container/fixed_point/fixed_point.hpp index f0bd00fac..8510961c3 100644 --- a/packages/server/computation_container/fixed_point/fixed_point.hpp +++ b/packages/server/computation_container/fixed_point/fixed_point.hpp @@ -8,13 +8,13 @@ #include #include #include +#include "external/proto/common_types/common_types.pb.h" namespace qmpc::Utils { -namespace mp = boost::multiprecision; using mp_int = boost::multiprecision::cpp_int; -using mp_float = boost::multiprecision::number>; -using SgnByte = std::pair; +using mp_float = boost::multiprecision::cpp_dec_float_100; +using BIB = pb_common_types::BigIntByte; class FixedPoint : private boost::operators { @@ -41,11 +41,11 @@ class FixedPoint : private boost::operators mp_float v_{str}; value = static_cast(v_ * shift); } - FixedPoint(const SgnByte &P) + FixedPoint(const BIB &a) { - const auto &[sgn, abs_byte] = P; + std::string abs_byte = a.abs_byte(); import_bits(value, abs_byte.begin(), abs_byte.end(), 8); - if (sgn) + if (a.sgn()) { value *= -1; } @@ -70,7 +70,12 @@ class FixedPoint : private boost::operators { mp_float ret = static_cast(value); ret /= shift; - return ret.str(20, std::ios_base::fixed); + std::string s = ret.str(0, std::ios_base::fixed); + while (s.size() and s.back() == '0') + { + s.pop_back(); + } + return s; } mp_int getRoundValue() const { @@ -81,17 +86,27 @@ class FixedPoint : private boost::operators } return ret; } - SgnByte getSgnByte() const + BIB getBigIntByte() const { - bool sgn = value < 0; - std::string bytes; - export_bits(value, std::back_inserter(bytes), 8); - return std::make_pair(sgn, bytes); + BIB ret; + ret.set_sgn(value < 0); + std::string abs_byte; + export_bits(value, std::back_inserter(abs_byte), 8); + ret.set_abs_byte(abs_byte); + return ret; } - double getDoubleVal() const + template + T getDoubleVal() const { - mp_float ret = static_cast(value); - return static_cast(ret / shift); + mp_float ret = static_cast(value) / shift; + if constexpr (std::is_same_v) + { + return ret; + } + else + { + return static_cast(ret); + } } constexpr static auto getShift() noexcept { return shift; } @@ -141,7 +156,14 @@ class FixedPoint : private boost::operators } bool operator==(const FixedPoint &obj) const noexcept { - return (value - obj.value >= -1 and value - obj.value <= 1) ? true : false; + /* + todo : value == obj.value に修正 + test で EXPECT_EQ(a,b) を用いている箇所は + EXPECT_NEAR(a.getDoubleVal(), b.getDoubleVal(), 1e-7) のように明示的に書く + ただし加減算だけなど, 誤差が出ないことが仕様として保証されている場合は EXPECT_EQ + のままで良い + */ + return abs(value - obj.value) <= 10; } bool operator<(const FixedPoint &obj) const noexcept { return value < obj.value; } /* @@ -155,7 +177,7 @@ class FixedPoint : private boost::operators friend std::ostream &operator<<(std::ostream &os, const FixedPoint &fp) { os << std::fixed; - os << std::setprecision(10); + os << std::setprecision(8); os << fp.value.template convert_to() / shift; os << std::resetiosflags(std::ios_base::floatfield); return os; diff --git a/packages/server/computation_container/math/math.cpp b/packages/server/computation_container/math/math.cpp index b4a83eb2a..acc7bcd3c 100644 --- a/packages/server/computation_container/math/math.cpp +++ b/packages/server/computation_container/math/math.cpp @@ -60,7 +60,7 @@ FixedPoint stdev(std::vector &v) var = variance(v); FixedPoint stdev = open_and_recons(var); - auto value = boost::multiprecision::cpp_dec_float_100(stdev.getStrVal()); + auto value = stdev.getDoubleVal(); if (value < 0) { value = 0; @@ -84,22 +84,12 @@ Share correl(std::vector &x, std::vector &y) FixedPoint stdeX = stdev(x); FixedPoint stdeY = stdev(y); - // 0徐算エラー - // TODO:一時的に値を入れているので要修正 - if (stdeX <= FixedPoint(0.001) and stdeX >= FixedPoint(-0.001)) + if (stdeX == FixedPoint(0) || stdeY == FixedPoint(0)) { - stdeX = FixedPoint("0.001"); + QMPC_LOG_ERROR("correl returns 0 when stdev is 0"); + return Share(FixedPoint(0)); } - if (stdeY <= FixedPoint(0.001) and stdeY >= FixedPoint(-0.001)) - { - stdeY = FixedPoint("0.001"); - } - - // if (stdeX.getVal() == 0 or stdeY.getVal() == 0) - // { - // throw std::runtime_error("0 divede error"); - // } int n = sizex; std::vector tmpX; tmpX.reserve(n); diff --git a/packages/server/computation_container/math/math.hpp b/packages/server/computation_container/math/math.hpp index 7290d1399..d33b0da9c 100644 --- a/packages/server/computation_container/math/math.hpp +++ b/packages/server/computation_container/math/math.hpp @@ -13,9 +13,9 @@ using Share = qmpc::Share::Share; Share sum(const std::vector &v); Share smean(const std::vector &v); Share variance(std::vector &v); -//標準偏差 +// 標準偏差 FixedPoint stdev(std::vector &v); -//相関係数 +// 相関係数 Share correl(std::vector &x, std::vector &y); Share exp(const Share &x); Share sigmoid(const Share &x, const FixedPoint &a = 1); diff --git a/packages/server/computation_container/server/computation_to_computation_container/server.hpp b/packages/server/computation_container/server/computation_to_computation_container/server.hpp index cd93b0ef4..69b4d6462 100644 --- a/packages/server/computation_container/server/computation_to_computation_container/server.hpp +++ b/packages/server/computation_container/server/computation_to_computation_container/server.hpp @@ -142,10 +142,7 @@ class Server final : public computationtocomputation::ComputationToComputation:: else { assert(share_value.has_fp()); - auto fp = share_value.fp(); - bool sgn = fp.sgn(); - std::string byte = fp.byte(); - return SV(std::make_pair(sgn, byte)); + return SV(share_value.fp()); } } }; diff --git a/packages/server/computation_container/share/share.hpp b/packages/server/computation_container/share/share.hpp index a9dd71a45..31580819f 100644 --- a/packages/server/computation_container/share/share.hpp +++ b/packages/server/computation_container/share/share.hpp @@ -76,7 +76,7 @@ class Share : boost::totally_ordered>, Share &operator*=(const Share &obj) { // Beaver Triplet a, b, c のシェア [a], [b], [c] を得る - auto t = qmpc::BtsHandler::StockTriple::getInstance()->get(); + auto t = qmpc::BtsHandler::StockTriple::getInstance()->get(); Share a(std::get<0>(t[0])), b(std::get<1>(t[0])), c(std::get<2>(t[0])); // [d] = [x] - [a], [e] = [y] - [b] を計算する @@ -243,7 +243,7 @@ class Share : boost::totally_ordered>, ); } // Beaver Triplet a, b, c のシェア [a], [b], [c] を得る - auto t = qmpc::BtsHandler::StockTriple::getInstance()->get(n); + auto t = qmpc::BtsHandler::StockTriple::getInstance()->get(n); std::vector a, b, c; a.reserve(n); @@ -327,14 +327,14 @@ auto _isZero(const T &x) template Share getRandBitShare() { - auto bit = qmpc::BtsHandler::StockRandBit::getInstance()->get(); + auto bit = qmpc::BtsHandler::StockRandBit::getInstance()->get(); return Share(bit[0]); } template std::vector> getRandBitShare(std::size_t amount) { - auto bit = qmpc::BtsHandler::StockRandBit::getInstance()->get(amount); + auto bit = qmpc::BtsHandler::StockRandBit::getInstance()->get(amount); std::vector> ret(amount); for (size_t i = 0; i < amount; i++) diff --git a/packages/server/computation_container/test/integration_test/join_table_test.hpp b/packages/server/computation_container/test/integration_test/join_table_test.hpp index 52164e34c..697bb8ec1 100644 --- a/packages/server/computation_container/test/integration_test/join_table_test.hpp +++ b/packages/server/computation_container/test/integration_test/join_table_test.hpp @@ -53,7 +53,7 @@ class TableJoinerTest : public testing::Test initialize(data_id); data_ids.emplace_back(data_id); - //テストで使用するデータをDBに保存する + // テストで使用するデータをDBに保存する const int piece_id = 0; auto [schema, table] = test_tables[table_itr]; auto json_schema = qmpc::ComputationToDb::convertSchemaVectorToJsonVector(schema); diff --git a/packages/server/computation_container/test/integration_test/mesh_code_test.hpp b/packages/server/computation_container/test/integration_test/mesh_code_test.hpp index dd347f4fb..9dec80775 100644 --- a/packages/server/computation_container/test/integration_test/mesh_code_test.hpp +++ b/packages/server/computation_container/test/integration_test/mesh_code_test.hpp @@ -60,7 +60,7 @@ TEST(MeshCodeTest, BulkMeshCode) end = std::chrono::system_clock::now(); // 計測終了時間 double elapsed = std::chrono::duration_cast(end - start) - .count(); //処理に要した時間をミリ秒に変換 + .count(); // 処理に要した時間をミリ秒に変換 QMPC_LOG_INFO("meshcode took {0} ms.", elapsed); for (const auto &meshcode : ret) diff --git a/packages/server/computation_container/test/integration_test/read_triple_from_bts_test.hpp b/packages/server/computation_container/test/integration_test/read_triple_from_bts_test.hpp index 824b5dbd2..e8e575785 100644 --- a/packages/server/computation_container/test/integration_test/read_triple_from_bts_test.hpp +++ b/packages/server/computation_container/test/integration_test/read_triple_from_bts_test.hpp @@ -24,7 +24,7 @@ void readTriplesTest(const unsigned int jobIdMax, const unsigned int amount) for (unsigned int jobId = 1; jobId <= jobIdMax; jobId++) { QMPC_LOG_INFO("jobId[{}]: ...", jobId); - using JobTriple = qmpc::BtsHandler::BTSJobType::Triple; + using JobTriple = qmpc::BtsHandler::BTSJobType::Triple; auto triples = cc_to_bts->readRequest(amount); EXPECT_EQ(triples.size(), amount); // TODO: Party間で足並みを揃えてa*b=cのチェック diff --git a/packages/server/computation_container/test/integration_test/share_test.hpp b/packages/server/computation_container/test/integration_test/share_test.hpp index 65d8fec2a..fafa43487 100644 --- a/packages/server/computation_container/test/integration_test/share_test.hpp +++ b/packages/server/computation_container/test/integration_test/share_test.hpp @@ -941,17 +941,6 @@ TEST(ShareTest, subIntShare) auto a_rec = open_and_recons(a); EXPECT_EQ(a_rec, n_parties * 3 - n_parties * 4); } -TEST(ShareTest, mulIntShare) -{ - Config *conf = Config::getInstance(); - int n_parties = conf->n_parties; - qmpc::Share::Share a(3); - qmpc::Share::Share b(4); - a = a * b; - std::cout << a.getVal() << std::endl; - auto a_rec = open_and_recons(a); - EXPECT_EQ(a_rec, (n_parties * 3) * (n_parties * 4)); -} TEST(ShareTest, boolLarge) { std::vector> a(50000, true); @@ -967,16 +956,6 @@ TEST(ShareTest, FPLarge) std::vector> a(50000, FixedPoint("1")); auto target = open_and_recons(a); } -TEST(ShareTest, IntMulLarge) -{ - Config *conf = Config::getInstance(); - int n_parties = conf->n_parties; - std::vector> a(20000, 1); - std::vector> b(20000, 1); - a = a * b; - auto rec = open_and_recons(a); - EXPECT_EQ(rec[0], (n_parties * 1) * (n_parties * 1)); -} TEST(ShareTest, FPMulLarge) { Config *conf = Config::getInstance(); @@ -986,43 +965,8 @@ TEST(ShareTest, FPMulLarge) a = a * b; auto rec = open_and_recons(a); - EXPECT_EQ(rec[0], (n_parties * 1) * (n_parties * 1)); -} - -TEST(ShareTest, IntMulExtraLarge) -{ - Config *conf = Config::getInstance(); - int n_parties = conf->n_parties; - std::vector> a(100000, 1); - std::vector> b(100000, 1); - a = a * b; - auto rec = open_and_recons(a); - EXPECT_EQ(rec[0], (n_parties * 1) * (n_parties * 1)); -} - -// 現状乱数範囲(セキュリティ)の都合上64bit浮動小数の積は使用できない -/* -TEST(ShareTest, doubleMulExtraLarge) -{ - Config *conf = Config::getInstance(); - int n_parties = conf->n_parties; - std::vector> a(100000, 1.0); - std::vector> b(100000, 1.0); - a = a * b; - auto rec = open_and_recons(a); - EXPECT_EQ(rec[0], (n_parties * 1) * (n_parties * 1)); -} -TEST(ShareTest, floatMulExtraLarge) -{ - Config *conf = Config::getInstance(); - int n_parties = conf->n_parties; - std::vector> a(100000, 1); - std::vector> b(100000, 1); - a = a * b; - auto rec = open_and_recons(a); - EXPECT_EQ(rec[0], (n_parties * 1) * (n_parties * 1)); + EXPECT_EQ(rec[0], n_parties * n_parties); } -*/ TEST(ShareTest, FPMulExtraLarge) { @@ -1033,5 +977,5 @@ TEST(ShareTest, FPMulExtraLarge) a = a * b; auto rec = open_and_recons(a); - EXPECT_EQ(rec[0], (n_parties * 1) * (n_parties * 1)); + EXPECT_EQ(rec[0], n_parties * n_parties); } diff --git a/packages/server/computation_container/test/unit_test/fixed_point_test.cpp b/packages/server/computation_container/test/unit_test/fixed_point_test.cpp index 27092f70b..1068e1139 100644 --- a/packages/server/computation_container/test/unit_test/fixed_point_test.cpp +++ b/packages/server/computation_container/test/unit_test/fixed_point_test.cpp @@ -201,11 +201,11 @@ TEST(FixedPointTest, Equation) TEST(FixedPointTest, getVal) { FixedPoint a("1.45"); // operand - EXPECT_EQ(a.getStrVal(), "1.45000000000000000000"); + EXPECT_EQ(a.getStrVal(), "1.45"); EXPECT_EQ(a.getDoubleVal(), 1.45); FixedPoint b("-1.45"); // operand - EXPECT_EQ(b.getStrVal(), "-1.45000000000000000000"); + EXPECT_EQ(b.getStrVal(), "-1.45"); EXPECT_EQ(b.getDoubleVal(), -1.45); } diff --git a/proto/common_types/common_types.pb.go b/proto/common_types/common_types.pb.go index 48e742a53..9d92c71fa 100644 --- a/proto/common_types/common_types.pb.go +++ b/proto/common_types/common_types.pb.go @@ -498,6 +498,61 @@ func (x *Schema) GetType() ShareValueTypeEnum { return ShareValueTypeEnum_SHARE_VALUE_TYPE_UNSPECIFIED } +type BigIntByte struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Sgn bool `protobuf:"varint,1,opt,name=sgn,proto3" json:"sgn,omitempty"` + AbsByte []byte `protobuf:"bytes,2,opt,name=abs_byte,json=absByte,proto3" json:"abs_byte,omitempty"` +} + +func (x *BigIntByte) Reset() { + *x = BigIntByte{} + if protoimpl.UnsafeEnabled { + mi := &file_common_types_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BigIntByte) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BigIntByte) ProtoMessage() {} + +func (x *BigIntByte) ProtoReflect() protoreflect.Message { + mi := &file_common_types_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BigIntByte.ProtoReflect.Descriptor instead. +func (*BigIntByte) Descriptor() ([]byte, []int) { + return file_common_types_proto_rawDescGZIP(), []int{5} +} + +func (x *BigIntByte) GetSgn() bool { + if x != nil { + return x.Sgn + } + return false +} + +func (x *BigIntByte) GetAbsByte() []byte { + if x != nil { + return x.AbsByte + } + return nil +} + type Stacktrace_Frame struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -511,7 +566,7 @@ type Stacktrace_Frame struct { func (x *Stacktrace_Frame) Reset() { *x = Stacktrace_Frame{} if protoimpl.UnsafeEnabled { - mi := &file_common_types_proto_msgTypes[5] + mi := &file_common_types_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -524,7 +579,7 @@ func (x *Stacktrace_Frame) String() string { func (*Stacktrace_Frame) ProtoMessage() {} func (x *Stacktrace_Frame) ProtoReflect() protoreflect.Message { - mi := &file_common_types_proto_msgTypes[5] + mi := &file_common_types_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -616,42 +671,46 @@ var file_common_types_proto_rawDesc = []byte{ 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x23, 0x2e, 0x70, 0x62, 0x5f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x54, 0x79, 0x70, 0x65, 0x45, 0x6e, 0x75, 0x6d, - 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x2a, 0x67, 0x0a, 0x09, 0x4a, 0x6f, 0x62, 0x53, 0x74, 0x61, - 0x74, 0x75, 0x73, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, - 0x12, 0x09, 0x0a, 0x05, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x52, - 0x45, 0x43, 0x45, 0x49, 0x56, 0x45, 0x44, 0x10, 0x02, 0x12, 0x0b, 0x0a, 0x07, 0x50, 0x52, 0x45, - 0x5f, 0x4a, 0x4f, 0x42, 0x10, 0x03, 0x12, 0x0b, 0x0a, 0x07, 0x52, 0x45, 0x41, 0x44, 0x5f, 0x44, - 0x42, 0x10, 0x04, 0x12, 0x0b, 0x0a, 0x07, 0x43, 0x4f, 0x4d, 0x50, 0x55, 0x54, 0x45, 0x10, 0x05, - 0x12, 0x0d, 0x0a, 0x09, 0x43, 0x4f, 0x4d, 0x50, 0x4c, 0x45, 0x54, 0x45, 0x44, 0x10, 0x06, 0x2a, - 0xf5, 0x01, 0x0a, 0x11, 0x43, 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4d, - 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x22, 0x0a, 0x1e, 0x43, 0x4f, 0x4d, 0x50, 0x55, 0x54, 0x41, - 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x4d, 0x45, 0x54, 0x48, 0x4f, 0x44, 0x5f, 0x55, 0x4e, 0x53, 0x50, - 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x1b, 0x0a, 0x17, 0x43, 0x4f, 0x4d, - 0x50, 0x55, 0x54, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x4d, 0x45, 0x54, 0x48, 0x4f, 0x44, 0x5f, - 0x4d, 0x45, 0x41, 0x4e, 0x10, 0x01, 0x12, 0x1f, 0x0a, 0x1b, 0x43, 0x4f, 0x4d, 0x50, 0x55, 0x54, - 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x4d, 0x45, 0x54, 0x48, 0x4f, 0x44, 0x5f, 0x56, 0x41, 0x52, - 0x49, 0x41, 0x4e, 0x43, 0x45, 0x10, 0x02, 0x12, 0x1a, 0x0a, 0x16, 0x43, 0x4f, 0x4d, 0x50, 0x55, - 0x54, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x4d, 0x45, 0x54, 0x48, 0x4f, 0x44, 0x5f, 0x53, 0x55, - 0x4d, 0x10, 0x03, 0x12, 0x1d, 0x0a, 0x19, 0x43, 0x4f, 0x4d, 0x50, 0x55, 0x54, 0x41, 0x54, 0x49, - 0x4f, 0x4e, 0x5f, 0x4d, 0x45, 0x54, 0x48, 0x4f, 0x44, 0x5f, 0x43, 0x4f, 0x52, 0x52, 0x45, 0x4c, - 0x10, 0x04, 0x12, 0x20, 0x0a, 0x1c, 0x43, 0x4f, 0x4d, 0x50, 0x55, 0x54, 0x41, 0x54, 0x49, 0x4f, - 0x4e, 0x5f, 0x4d, 0x45, 0x54, 0x48, 0x4f, 0x44, 0x5f, 0x4d, 0x45, 0x53, 0x48, 0x5f, 0x43, 0x4f, - 0x44, 0x45, 0x10, 0x05, 0x12, 0x21, 0x0a, 0x1d, 0x43, 0x4f, 0x4d, 0x50, 0x55, 0x54, 0x41, 0x54, - 0x49, 0x4f, 0x4e, 0x5f, 0x4d, 0x45, 0x54, 0x48, 0x4f, 0x44, 0x5f, 0x4a, 0x4f, 0x49, 0x4e, 0x5f, - 0x54, 0x41, 0x42, 0x4c, 0x45, 0x10, 0x06, 0x2a, 0x8b, 0x01, 0x0a, 0x12, 0x53, 0x68, 0x61, 0x72, - 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x54, 0x79, 0x70, 0x65, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x20, - 0x0a, 0x1c, 0x53, 0x48, 0x41, 0x52, 0x45, 0x5f, 0x56, 0x41, 0x4c, 0x55, 0x45, 0x5f, 0x54, 0x59, - 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, - 0x12, 0x20, 0x0a, 0x1c, 0x53, 0x48, 0x41, 0x52, 0x45, 0x5f, 0x56, 0x41, 0x4c, 0x55, 0x45, 0x5f, - 0x54, 0x59, 0x50, 0x45, 0x5f, 0x46, 0x49, 0x58, 0x45, 0x44, 0x5f, 0x50, 0x4f, 0x49, 0x4e, 0x54, - 0x10, 0x01, 0x12, 0x31, 0x0a, 0x2d, 0x53, 0x48, 0x41, 0x52, 0x45, 0x5f, 0x56, 0x41, 0x4c, 0x55, - 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x54, 0x46, 0x5f, 0x38, 0x5f, 0x49, 0x4e, 0x54, - 0x45, 0x47, 0x45, 0x52, 0x5f, 0x52, 0x45, 0x50, 0x52, 0x45, 0x53, 0x45, 0x4e, 0x54, 0x41, 0x54, - 0x49, 0x4f, 0x4e, 0x10, 0x02, 0x42, 0x39, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, - 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x2d, 0x64, 0x65, 0x76, - 0x65, 0x6c, 0x6f, 0x70, 0x2f, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x4d, 0x50, 0x43, 0x2f, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x39, 0x0a, 0x0a, 0x42, 0x69, 0x67, 0x49, 0x6e, 0x74, + 0x42, 0x79, 0x74, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x67, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x08, 0x52, 0x03, 0x73, 0x67, 0x6e, 0x12, 0x19, 0x0a, 0x08, 0x61, 0x62, 0x73, 0x5f, 0x62, 0x79, + 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x61, 0x62, 0x73, 0x42, 0x79, 0x74, + 0x65, 0x2a, 0x67, 0x0a, 0x09, 0x4a, 0x6f, 0x62, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x0b, + 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x45, + 0x52, 0x52, 0x4f, 0x52, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x52, 0x45, 0x43, 0x45, 0x49, 0x56, + 0x45, 0x44, 0x10, 0x02, 0x12, 0x0b, 0x0a, 0x07, 0x50, 0x52, 0x45, 0x5f, 0x4a, 0x4f, 0x42, 0x10, + 0x03, 0x12, 0x0b, 0x0a, 0x07, 0x52, 0x45, 0x41, 0x44, 0x5f, 0x44, 0x42, 0x10, 0x04, 0x12, 0x0b, + 0x0a, 0x07, 0x43, 0x4f, 0x4d, 0x50, 0x55, 0x54, 0x45, 0x10, 0x05, 0x12, 0x0d, 0x0a, 0x09, 0x43, + 0x4f, 0x4d, 0x50, 0x4c, 0x45, 0x54, 0x45, 0x44, 0x10, 0x06, 0x2a, 0xf5, 0x01, 0x0a, 0x11, 0x43, + 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, + 0x12, 0x22, 0x0a, 0x1e, 0x43, 0x4f, 0x4d, 0x50, 0x55, 0x54, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, + 0x4d, 0x45, 0x54, 0x48, 0x4f, 0x44, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, + 0x45, 0x44, 0x10, 0x00, 0x12, 0x1b, 0x0a, 0x17, 0x43, 0x4f, 0x4d, 0x50, 0x55, 0x54, 0x41, 0x54, + 0x49, 0x4f, 0x4e, 0x5f, 0x4d, 0x45, 0x54, 0x48, 0x4f, 0x44, 0x5f, 0x4d, 0x45, 0x41, 0x4e, 0x10, + 0x01, 0x12, 0x1f, 0x0a, 0x1b, 0x43, 0x4f, 0x4d, 0x50, 0x55, 0x54, 0x41, 0x54, 0x49, 0x4f, 0x4e, + 0x5f, 0x4d, 0x45, 0x54, 0x48, 0x4f, 0x44, 0x5f, 0x56, 0x41, 0x52, 0x49, 0x41, 0x4e, 0x43, 0x45, + 0x10, 0x02, 0x12, 0x1a, 0x0a, 0x16, 0x43, 0x4f, 0x4d, 0x50, 0x55, 0x54, 0x41, 0x54, 0x49, 0x4f, + 0x4e, 0x5f, 0x4d, 0x45, 0x54, 0x48, 0x4f, 0x44, 0x5f, 0x53, 0x55, 0x4d, 0x10, 0x03, 0x12, 0x1d, + 0x0a, 0x19, 0x43, 0x4f, 0x4d, 0x50, 0x55, 0x54, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x4d, 0x45, + 0x54, 0x48, 0x4f, 0x44, 0x5f, 0x43, 0x4f, 0x52, 0x52, 0x45, 0x4c, 0x10, 0x04, 0x12, 0x20, 0x0a, + 0x1c, 0x43, 0x4f, 0x4d, 0x50, 0x55, 0x54, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x4d, 0x45, 0x54, + 0x48, 0x4f, 0x44, 0x5f, 0x4d, 0x45, 0x53, 0x48, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x10, 0x05, 0x12, + 0x21, 0x0a, 0x1d, 0x43, 0x4f, 0x4d, 0x50, 0x55, 0x54, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x4d, + 0x45, 0x54, 0x48, 0x4f, 0x44, 0x5f, 0x4a, 0x4f, 0x49, 0x4e, 0x5f, 0x54, 0x41, 0x42, 0x4c, 0x45, + 0x10, 0x06, 0x2a, 0x8b, 0x01, 0x0a, 0x12, 0x53, 0x68, 0x61, 0x72, 0x65, 0x56, 0x61, 0x6c, 0x75, + 0x65, 0x54, 0x79, 0x70, 0x65, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x20, 0x0a, 0x1c, 0x53, 0x48, 0x41, + 0x52, 0x45, 0x5f, 0x56, 0x41, 0x4c, 0x55, 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, + 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x20, 0x0a, 0x1c, 0x53, + 0x48, 0x41, 0x52, 0x45, 0x5f, 0x56, 0x41, 0x4c, 0x55, 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, + 0x46, 0x49, 0x58, 0x45, 0x44, 0x5f, 0x50, 0x4f, 0x49, 0x4e, 0x54, 0x10, 0x01, 0x12, 0x31, 0x0a, + 0x2d, 0x53, 0x48, 0x41, 0x52, 0x45, 0x5f, 0x56, 0x41, 0x4c, 0x55, 0x45, 0x5f, 0x54, 0x59, 0x50, + 0x45, 0x5f, 0x55, 0x54, 0x46, 0x5f, 0x38, 0x5f, 0x49, 0x4e, 0x54, 0x45, 0x47, 0x45, 0x52, 0x5f, + 0x52, 0x45, 0x50, 0x52, 0x45, 0x53, 0x45, 0x4e, 0x54, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x10, 0x02, + 0x42, 0x39, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, + 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x2d, 0x64, 0x65, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x2f, + 0x51, 0x75, 0x69, 0x63, 0x6b, 0x4d, 0x50, 0x43, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, + 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( @@ -667,7 +726,7 @@ func file_common_types_proto_rawDescGZIP() []byte { } var file_common_types_proto_enumTypes = make([]protoimpl.EnumInfo, 3) -var file_common_types_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_common_types_proto_msgTypes = make([]protoimpl.MessageInfo, 7) var file_common_types_proto_goTypes = []interface{}{ (JobStatus)(0), // 0: pb_common_types.JobStatus (ComputationMethod)(0), // 1: pb_common_types.ComputationMethod @@ -677,12 +736,13 @@ var file_common_types_proto_goTypes = []interface{}{ (*Stacktrace)(nil), // 5: pb_common_types.Stacktrace (*JobErrorInfo)(nil), // 6: pb_common_types.JobErrorInfo (*Schema)(nil), // 7: pb_common_types.Schema - (*Stacktrace_Frame)(nil), // 8: pb_common_types.Stacktrace.Frame + (*BigIntByte)(nil), // 8: pb_common_types.BigIntByte + (*Stacktrace_Frame)(nil), // 9: pb_common_types.Stacktrace.Frame } var file_common_types_proto_depIdxs = []int32{ 0, // 0: pb_common_types.JobProgress.status:type_name -> pb_common_types.JobStatus 3, // 1: pb_common_types.JobProgress.progresses:type_name -> pb_common_types.ProcedureProgress - 8, // 2: pb_common_types.Stacktrace.frames:type_name -> pb_common_types.Stacktrace.Frame + 9, // 2: pb_common_types.Stacktrace.frames:type_name -> pb_common_types.Stacktrace.Frame 5, // 3: pb_common_types.JobErrorInfo.stacktrace:type_name -> pb_common_types.Stacktrace 2, // 4: pb_common_types.Schema.type:type_name -> pb_common_types.ShareValueTypeEnum 5, // [5:5] is the sub-list for method output_type @@ -759,6 +819,18 @@ func file_common_types_proto_init() { } } file_common_types_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BigIntByte); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_common_types_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Stacktrace_Frame); i { case 0: return &v.state @@ -779,7 +851,7 @@ func file_common_types_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_common_types_proto_rawDesc, NumEnums: 3, - NumMessages: 6, + NumMessages: 7, NumExtensions: 0, NumServices: 0, }, diff --git a/proto/common_types/common_types.proto b/proto/common_types/common_types.proto index 790c0a0d6..aa3e40088 100644 --- a/proto/common_types/common_types.proto +++ b/proto/common_types/common_types.proto @@ -63,3 +63,9 @@ message Schema { string name = 1; ShareValueTypeEnum type = 2; } + +message BigIntByte{ + bool sgn = 1; + bytes abs_byte = 2; +} + diff --git a/proto/computation_to_computation_container/BUILD b/proto/computation_to_computation_container/BUILD index da281fd91..3bcdc47e7 100644 --- a/proto/computation_to_computation_container/BUILD +++ b/proto/computation_to_computation_container/BUILD @@ -6,7 +6,8 @@ load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library") proto_library( name = "computation_to_computation_proto", srcs = ["computation_to_computation.proto"], - deps = ["@com_google_protobuf//:empty_proto"], + deps = ["@com_google_protobuf//:empty_proto", + "@proto//common_types:common_types"], ) cc_proto_library( diff --git a/proto/computation_to_computation_container/computation_to_computation.proto b/proto/computation_to_computation_container/computation_to_computation.proto index 6710eae64..b4e89a664 100644 --- a/proto/computation_to_computation_container/computation_to_computation.proto +++ b/proto/computation_to_computation_container/computation_to_computation.proto @@ -4,6 +4,7 @@ package computationtocomputation; // 引数無しにする際に使用 import "google/protobuf/empty.proto"; +import "common_types/common_types.proto"; /** * ComputationToComputation service @@ -24,11 +25,6 @@ message Address{ int32 party_id = 4; // the id of party(0, 1, 2) } -message BigIntByte{ - bool sgn = 1; - bytes byte = 2; -} - /** * the message of shares */ @@ -36,10 +32,10 @@ message Shares { message Share{ oneof value{ int64 num = 1; - BigIntByte fp = 2; + pb_common_types.BigIntByte fp = 2; bool flag = 3; } } repeated Share share_list = 1; Address address_id = 2; -} \ No newline at end of file +} diff --git a/proto/engine_to_bts/BUILD b/proto/engine_to_bts/BUILD index d6b174f91..cfc11fe25 100644 --- a/proto/engine_to_bts/BUILD +++ b/proto/engine_to_bts/BUILD @@ -6,7 +6,8 @@ load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library") proto_library( name = "engine_to_bts_proto", srcs = ["engine_to_bts.proto"], - deps = ["@com_google_protobuf//:empty_proto"] + deps = ["@com_google_protobuf//:empty_proto", + "@proto//common_types:common_types"], ) cc_proto_library( diff --git a/proto/engine_to_bts/engine_to_bts.pb.go b/proto/engine_to_bts/engine_to_bts.pb.go index b219abe00..77bb03148 100644 --- a/proto/engine_to_bts/engine_to_bts.pb.go +++ b/proto/engine_to_bts/engine_to_bts.pb.go @@ -7,6 +7,7 @@ package engine_to_bts import ( + common_types "github.com/acompany-develop/QuickMPC/proto/common_types" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -88,9 +89,9 @@ type Triple struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - A int64 `protobuf:"varint,2,opt,name=a,proto3" json:"a,omitempty"` - B int64 `protobuf:"varint,3,opt,name=b,proto3" json:"b,omitempty"` - C int64 `protobuf:"varint,4,opt,name=c,proto3" json:"c,omitempty"` + A *common_types.BigIntByte `protobuf:"bytes,2,opt,name=a,proto3" json:"a,omitempty"` + B *common_types.BigIntByte `protobuf:"bytes,3,opt,name=b,proto3" json:"b,omitempty"` + C *common_types.BigIntByte `protobuf:"bytes,4,opt,name=c,proto3" json:"c,omitempty"` } func (x *Triple) Reset() { @@ -125,25 +126,25 @@ func (*Triple) Descriptor() ([]byte, []int) { return file_engine_to_bts_proto_rawDescGZIP(), []int{1} } -func (x *Triple) GetA() int64 { +func (x *Triple) GetA() *common_types.BigIntByte { if x != nil { return x.A } - return 0 + return nil } -func (x *Triple) GetB() int64 { +func (x *Triple) GetB() *common_types.BigIntByte { if x != nil { return x.B } - return 0 + return nil } -func (x *Triple) GetC() int64 { +func (x *Triple) GetC() *common_types.BigIntByte { if x != nil { return x.C } - return 0 + return nil } type GetTriplesResponse struct { @@ -245,38 +246,45 @@ var File_engine_to_bts_proto protoreflect.FileDescriptor var file_engine_to_bts_proto_rawDesc = []byte{ 0x0a, 0x13, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x6f, 0x5f, 0x62, 0x74, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0b, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x74, 0x6f, 0x62, - 0x74, 0x73, 0x22, 0x5a, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x15, 0x0a, 0x06, 0x6a, 0x6f, 0x62, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, - 0x52, 0x05, 0x6a, 0x6f, 0x62, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, - 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, - 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x03, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x22, 0x32, - 0x0a, 0x06, 0x54, 0x72, 0x69, 0x70, 0x6c, 0x65, 0x12, 0x0c, 0x0a, 0x01, 0x61, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x03, 0x52, 0x01, 0x61, 0x12, 0x0c, 0x0a, 0x01, 0x62, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x03, 0x52, 0x01, 0x62, 0x12, 0x0c, 0x0a, 0x01, 0x63, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, - 0x01, 0x63, 0x22, 0x43, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x54, 0x72, 0x69, 0x70, 0x6c, 0x65, 0x73, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2d, 0x0a, 0x07, 0x74, 0x72, 0x69, 0x70, - 0x6c, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x65, 0x6e, 0x67, 0x69, - 0x6e, 0x65, 0x74, 0x6f, 0x62, 0x74, 0x73, 0x2e, 0x54, 0x72, 0x69, 0x70, 0x6c, 0x65, 0x52, 0x07, - 0x74, 0x72, 0x69, 0x70, 0x6c, 0x65, 0x73, 0x22, 0x31, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x52, 0x61, - 0x6e, 0x64, 0x42, 0x69, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1a, - 0x0a, 0x08, 0x72, 0x61, 0x6e, 0x64, 0x62, 0x69, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x03, - 0x52, 0x08, 0x72, 0x61, 0x6e, 0x64, 0x62, 0x69, 0x74, 0x73, 0x32, 0xa3, 0x01, 0x0a, 0x0b, 0x45, - 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x6f, 0x42, 0x74, 0x73, 0x12, 0x48, 0x0a, 0x0a, 0x47, 0x65, - 0x74, 0x54, 0x72, 0x69, 0x70, 0x6c, 0x65, 0x73, 0x12, 0x17, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, - 0x65, 0x74, 0x6f, 0x62, 0x74, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x1f, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x74, 0x6f, 0x62, 0x74, 0x73, 0x2e, - 0x47, 0x65, 0x74, 0x54, 0x72, 0x69, 0x70, 0x6c, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x22, 0x00, 0x12, 0x4a, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x64, 0x42, - 0x69, 0x74, 0x73, 0x12, 0x17, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x74, 0x6f, 0x62, 0x74, - 0x73, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x65, - 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x74, 0x6f, 0x62, 0x74, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, - 0x6e, 0x64, 0x42, 0x69, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, - 0x42, 0x3a, 0x5a, 0x38, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, - 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x2d, 0x64, 0x65, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x2f, - 0x51, 0x75, 0x69, 0x63, 0x6b, 0x4d, 0x50, 0x43, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x65, - 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x6f, 0x5f, 0x62, 0x74, 0x73, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x74, 0x73, 0x1a, 0x1f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, + 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0x5a, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x15, 0x0a, 0x06, 0x6a, 0x6f, 0x62, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0d, 0x52, 0x05, 0x6a, 0x6f, 0x62, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, + 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, + 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x22, + 0x89, 0x01, 0x0a, 0x06, 0x54, 0x72, 0x69, 0x70, 0x6c, 0x65, 0x12, 0x29, 0x0a, 0x01, 0x61, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x70, 0x62, 0x5f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, + 0x6e, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x42, 0x69, 0x67, 0x49, 0x6e, 0x74, 0x42, 0x79, + 0x74, 0x65, 0x52, 0x01, 0x61, 0x12, 0x29, 0x0a, 0x01, 0x62, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x1b, 0x2e, 0x70, 0x62, 0x5f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x5f, 0x74, 0x79, 0x70, + 0x65, 0x73, 0x2e, 0x42, 0x69, 0x67, 0x49, 0x6e, 0x74, 0x42, 0x79, 0x74, 0x65, 0x52, 0x01, 0x62, + 0x12, 0x29, 0x0a, 0x01, 0x63, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x70, 0x62, + 0x5f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x42, 0x69, + 0x67, 0x49, 0x6e, 0x74, 0x42, 0x79, 0x74, 0x65, 0x52, 0x01, 0x63, 0x22, 0x43, 0x0a, 0x12, 0x47, + 0x65, 0x74, 0x54, 0x72, 0x69, 0x70, 0x6c, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x2d, 0x0a, 0x07, 0x74, 0x72, 0x69, 0x70, 0x6c, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x74, 0x6f, 0x62, 0x74, 0x73, + 0x2e, 0x54, 0x72, 0x69, 0x70, 0x6c, 0x65, 0x52, 0x07, 0x74, 0x72, 0x69, 0x70, 0x6c, 0x65, 0x73, + 0x22, 0x31, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x64, 0x42, 0x69, 0x74, 0x73, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x61, 0x6e, 0x64, 0x62, + 0x69, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x03, 0x52, 0x08, 0x72, 0x61, 0x6e, 0x64, 0x62, + 0x69, 0x74, 0x73, 0x32, 0xa3, 0x01, 0x0a, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x6f, + 0x42, 0x74, 0x73, 0x12, 0x48, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x54, 0x72, 0x69, 0x70, 0x6c, 0x65, + 0x73, 0x12, 0x17, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x74, 0x6f, 0x62, 0x74, 0x73, 0x2e, + 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x65, 0x6e, 0x67, + 0x69, 0x6e, 0x65, 0x74, 0x6f, 0x62, 0x74, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x54, 0x72, 0x69, 0x70, + 0x6c, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4a, 0x0a, + 0x0b, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x64, 0x42, 0x69, 0x74, 0x73, 0x12, 0x17, 0x2e, 0x65, + 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x74, 0x6f, 0x62, 0x74, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x74, 0x6f, + 0x62, 0x74, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x64, 0x42, 0x69, 0x74, 0x73, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x3a, 0x5a, 0x38, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, + 0x2d, 0x64, 0x65, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x2f, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x4d, 0x50, + 0x43, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x5f, 0x74, + 0x6f, 0x5f, 0x62, 0x74, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -293,22 +301,26 @@ func file_engine_to_bts_proto_rawDescGZIP() []byte { var file_engine_to_bts_proto_msgTypes = make([]protoimpl.MessageInfo, 4) var file_engine_to_bts_proto_goTypes = []interface{}{ - (*GetRequest)(nil), // 0: enginetobts.GetRequest - (*Triple)(nil), // 1: enginetobts.Triple - (*GetTriplesResponse)(nil), // 2: enginetobts.GetTriplesResponse - (*GetRandBitsResponse)(nil), // 3: enginetobts.GetRandBitsResponse + (*GetRequest)(nil), // 0: enginetobts.GetRequest + (*Triple)(nil), // 1: enginetobts.Triple + (*GetTriplesResponse)(nil), // 2: enginetobts.GetTriplesResponse + (*GetRandBitsResponse)(nil), // 3: enginetobts.GetRandBitsResponse + (*common_types.BigIntByte)(nil), // 4: pb_common_types.BigIntByte } var file_engine_to_bts_proto_depIdxs = []int32{ - 1, // 0: enginetobts.GetTriplesResponse.triples:type_name -> enginetobts.Triple - 0, // 1: enginetobts.EngineToBts.GetTriples:input_type -> enginetobts.GetRequest - 0, // 2: enginetobts.EngineToBts.GetRandBits:input_type -> enginetobts.GetRequest - 2, // 3: enginetobts.EngineToBts.GetTriples:output_type -> enginetobts.GetTriplesResponse - 3, // 4: enginetobts.EngineToBts.GetRandBits:output_type -> enginetobts.GetRandBitsResponse - 3, // [3:5] is the sub-list for method output_type - 1, // [1:3] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name + 4, // 0: enginetobts.Triple.a:type_name -> pb_common_types.BigIntByte + 4, // 1: enginetobts.Triple.b:type_name -> pb_common_types.BigIntByte + 4, // 2: enginetobts.Triple.c:type_name -> pb_common_types.BigIntByte + 1, // 3: enginetobts.GetTriplesResponse.triples:type_name -> enginetobts.Triple + 0, // 4: enginetobts.EngineToBts.GetTriples:input_type -> enginetobts.GetRequest + 0, // 5: enginetobts.EngineToBts.GetRandBits:input_type -> enginetobts.GetRequest + 2, // 6: enginetobts.EngineToBts.GetTriples:output_type -> enginetobts.GetTriplesResponse + 3, // 7: enginetobts.EngineToBts.GetRandBits:output_type -> enginetobts.GetRandBitsResponse + 6, // [6:8] is the sub-list for method output_type + 4, // [4:6] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name } func init() { file_engine_to_bts_proto_init() } diff --git a/proto/engine_to_bts/engine_to_bts.proto b/proto/engine_to_bts/engine_to_bts.proto index 3b7309daa..f6d24de59 100644 --- a/proto/engine_to_bts/engine_to_bts.proto +++ b/proto/engine_to_bts/engine_to_bts.proto @@ -4,6 +4,8 @@ package enginetobts; option go_package = "github.com/acompany-develop/QuickMPC/proto/engine_to_bts"; +import "common_types/common_types.proto"; + service EngineToBts { rpc GetTriples(GetRequest) returns (GetTriplesResponse) {} rpc GetRandBits(GetRequest) returns (GetRandBitsResponse) {} @@ -16,9 +18,9 @@ message GetRequest{ } message Triple{ - int64 a = 2; - int64 b = 3; - int64 c = 4; + pb_common_types.BigIntByte a = 2; + pb_common_types.BigIntByte b = 3; + pb_common_types.BigIntByte c = 4; } message GetTriplesResponse{ diff --git a/scripts/libclient/src/tests/test_correl.py b/scripts/libclient/src/tests/test_correl.py index 0345b8471..02ac83ba8 100644 --- a/scripts/libclient/src/tests/test_correl.py +++ b/scripts/libclient/src/tests/test_correl.py @@ -19,8 +19,9 @@ [1], [2], pd.DataFrame([[1.0]])), + # todo : reconsider the arguments # small data case - (data_frame([[10**-9, 10**-9+5], [10**-9+10, 10**-9+10]], + (data_frame([[10**-8, 10**-8+5], [10**-8+10, 10**-8+10]], columns=["s1", "s2"]), [1], [2], pd.DataFrame([[1.0]])), diff --git a/scripts/libclient/src/tests/test_sum.py b/scripts/libclient/src/tests/test_sum.py index b7bccd4c8..c678d1088 100644 --- a/scripts/libclient/src/tests/test_sum.py +++ b/scripts/libclient/src/tests/test_sum.py @@ -22,9 +22,9 @@ pd.DataFrame([2.0*10**18])), # small data case - (data_frame([[10**-18], [10**-18]], columns=["s1"]), + (data_frame([[10**-8], [10**-8]], columns=["s1"]), [1], - pd.DataFrame([2.0*10**-10])), + pd.DataFrame([2.0*10**-8])), # duplicated src case (data_frame([[1, 2, 3], [4, 5, 6]], columns=["s1", "s2", "s3"]), diff --git a/scripts/libclient/src/tests/test_variance.py b/scripts/libclient/src/tests/test_variance.py index 94970c55b..2631d80bb 100644 --- a/scripts/libclient/src/tests/test_variance.py +++ b/scripts/libclient/src/tests/test_variance.py @@ -22,9 +22,9 @@ pd.DataFrame([25.0])), # small data case - (data_frame([[10**-9], [10**-9+10]], columns=["s1"]), + (data_frame([[10**-8], [10**-8+10**-4]], columns=["s1"]), [1], - pd.DataFrame([25.0])), + pd.DataFrame([25 * 10**-8])), # duplicated src case (data_frame([[1, 2, 3], [4, 7, 10]], columns=["s1", "s2", "s3"]),