Skip to content
This repository was archived by the owner on Mar 25, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
429aa20
add BigIntByte to proto
sakamoto-souta Jul 27, 2023
36a00b7
add BigRand
sakamoto-souta Jul 27, 2023
7f813ae
make BigTriple
sakamoto-souta Jul 27, 2023
3cf57c9
Big Triple
sakamoto-souta Jul 27, 2023
7c87430
for BigTriple test
sakamoto-souta Jul 27, 2023
8cad436
delete Type from Job
sakamoto-souta Jul 27, 2023
8fea3c8
fix build file
sakamoto-souta Jul 27, 2023
28066bb
fix typo
sakamoto-souta Jul 27, 2023
866b878
add static
sakamoto-souta Jul 27, 2023
0446d1a
delete typename
sakamoto-souta Jul 27, 2023
1b04673
decrease request_num
sakamoto-souta Jul 27, 2023
153da58
delete typename
sakamoto-souta Jul 27, 2023
efc7382
delete non FP mul
sakamoto-souta Jul 27, 2023
0804447
format
sakamoto-souta Jul 28, 2023
68057fb
fix typo
sakamoto-souta Jul 28, 2023
cfa879e
div c by shift
sakamoto-souta Jul 28, 2023
07a912d
fix equality
sakamoto-souta Jul 28, 2023
d2ffc1a
fix ostream width
sakamoto-souta Jul 28, 2023
578dd39
fix case div0
sakamoto-souta Jul 28, 2023
998c233
format
sakamoto-souta Jul 28, 2023
5493e3c
div0
sakamoto-souta Jul 28, 2023
e617040
format
sakamoto-souta Jul 28, 2023
b697179
format
sakamoto-souta Jul 28, 2023
5dfdc13
fix & -> *
sakamoto-souta Jul 28, 2023
27b3779
fix type
sakamoto-souta Jul 28, 2023
2ee29dc
byte -> abs_byte
sakamoto-souta Jul 28, 2023
0b83a1d
byte -> abs_byte
sakamoto-souta Jul 28, 2023
f436220
fix type
sakamoto-souta Jul 28, 2023
7b9643d
comment out small
sakamoto-souta Jul 28, 2023
4160752
comment out div0
sakamoto-souta Jul 28, 2023
cdc54fc
comment out div0
sakamoto-souta Jul 28, 2023
41be97a
byte -> abs_byte
sakamoto-souta Jul 28, 2023
2877fdc
fix bigInt Mul
sakamoto-souta Jul 28, 2023
b4f95b0
add const
sakamoto-souta Jul 28, 2023
b0a7b9f
clean mathtest
sakamoto-souta Jul 28, 2023
03816ef
convert getDoubleVal
sakamoto-souta Jul 28, 2023
3f1ecae
refactoring sum
sakamoto-souta Jul 28, 2023
e012157
fix math
sakamoto-souta Jul 28, 2023
a454e7c
transform
sakamoto-souta Jul 28, 2023
87abbd0
fix math
sakamoto-souta Jul 28, 2023
e5f71cd
fix float size
sakamoto-souta Jul 28, 2023
c39b4ed
use long mp_float
sakamoto-souta Jul 28, 2023
45c80e2
return long string
sakamoto-souta Jul 28, 2023
250bb1d
fix gramatical error
sakamoto-souta Jul 28, 2023
bdd2ce6
NewInt
sakamoto-souta Jul 30, 2023
b606e18
fix string expression
sakamoto-souta Jul 31, 2023
2de8318
del unused variables
sakamoto-souta Jul 31, 2023
551b14a
fix e2b_test bigInt
sakamoto-souta Jul 31, 2023
8e2f8a6
add big
sakamoto-souta Jul 31, 2023
f44b3fd
getcontext 500
sakamoto-souta Jul 31, 2023
9dc0d74
500 -> 100
sakamoto-souta Jul 31, 2023
63f05f7
100 -> 50
sakamoto-souta Jul 31, 2023
b2f1672
format
sakamoto-souta Jul 31, 2023
ae13763
del too small
sakamoto-souta Jul 31, 2023
cc54195
fixed_point 1000 -> 100
sakamoto-souta Jul 31, 2023
3459910
div0 error
sakamoto-souta Jul 31, 2023
a985822
small sum case : 10^{-8}
sakamoto-souta Jul 31, 2023
0a46b6d
correl div0 try catch
sakamoto-souta Jul 31, 2023
4e4f039
fix small case
sakamoto-souta Jul 31, 2023
bb0fd17
fix div0 case
sakamoto-souta Jul 31, 2023
c87159c
fix div0 case
sakamoto-souta Jul 31, 2023
5e00ff7
undo operator== in FixedPoint
sakamoto-souta Jul 31, 2023
1d27820
add comment prec
sakamoto-souta Jul 31, 2023
22a5e50
fix ==
sakamoto-souta Jul 31, 2023
811dd31
fold comment
sakamoto-souta Jul 31, 2023
85d68cf
undo correl
sakamoto-souta Jul 31, 2023
8fa1c43
info -> error
sakamoto-souta Aug 1, 2023
c5ce0c5
del mp
sakamoto-souta Aug 1, 2023
866740e
use cpp_dec_float_50
sakamoto-souta Aug 1, 2023
1e6ec8c
50->100
sakamoto-souta Aug 1, 2023
f045974
256int->infint
sakamoto-souta Aug 1, 2023
08bb04c
Update BigIntByte to use pb_common_types
mdonaka Aug 8, 2023
d69e2ca
Add decimal prec verify
mdonaka Aug 8, 2023
d661dee
Fix decimal prec in thread
mdonaka Aug 8, 2023
771f62c
Fix flake8
mdonaka Aug 8, 2023
ed6560e
Update decimal_prec to private
mdonaka Aug 8, 2023
3daa569
Fix prec test
mdonaka Aug 8, 2023
8ec3955
direct change FP and pb_common_types::BigIntByte
sakamoto-souta Aug 8, 2023
483ff13
add TestGetRandBigInts
sakamoto-souta Aug 9, 2023
bdb67e2
add testSpanning
sakamoto-souta Aug 9, 2023
3323bb4
add import
sakamoto-souta Aug 9, 2023
01fe661
fix FP -> BigIntByte
sakamoto-souta Aug 9, 2023
dfb3ec2
add comment for decimal_prec
sakamoto-souta Aug 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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
46 changes: 45 additions & 1 deletion packages/client/libclient-py/quickmpc/share/share.py
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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]] =\
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
6 changes: 5 additions & 1 deletion packages/server/beaver_triple_service/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
}
Expand Down Expand Up @@ -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) }

// func TestGetRandBits_10000_10000(t *testing.T) { testGetRandBits(t, 10000, 10000) }
Loading