跳转至

Feldman Verifiable Sum

Introduction

Verifiable secret sharing mechanism is an efficient and practical secret sharing mechanism. Feldman Verifiable sum is a multi-party private data summation module based on verifiable secret sharing.This component can sum the same feature of common users among different participants without exposing private data.(This module is still in the research stage, has not yet been put into production)

Here, three participants of the federation process is given, Party A represents Guest, party B and party C represent Host. The process of Feldman Verifiable Sum is shown below:

Figure 1: Process of Feldman Verifiable Sum Figure 1: Process of Feldman Verifiable Sum

Figure 2: Process of share sub-key Figure 2: Process of share sub-key

In the process shown above, each party encrypts its own secret value, share sub-key, recieve sub-keys from other parties, and then combine all these sub-keys. Guest, as the task initiator, initialize the parameters and decrypt the sum result.

How to Use

In general, this component can be used in the data preprocessing stage to count some features. It supports integers and floating-point numbers from - 2 ^ 63 to 2 ^ 64. By default, the maximum precision is set to 6 decimal places.

Param

feldman_verifiable_sum_param

Classes

FeldmanVerifiableSumParam(sum_cols=None, q_n=6)

Bases: BaseParam

Define how to transfer the cols

Parameters:

Name Type Description Default
sum_cols list of column index, default

Specify which columns need to be sum. If column index is None, each of columns will be sum.

None
q_n int, positive integer less than or equal to 16, default

q_n is the number of significant decimal digit, If the data type is a float, the maximum significant digit is 16. The sum of integer and significant decimal digits should be less than or equal to 16.

6
Source code in python/federatedml/param/feldman_verifiable_sum_param.py
36
37
38
def __init__(self, sum_cols=None, q_n=6):
    self.sum_cols = sum_cols
    self.q_n = q_n
Attributes
sum_cols = sum_cols instance-attribute
q_n = q_n instance-attribute
Functions
check()
Source code in python/federatedml/param/feldman_verifiable_sum_param.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def check(self):
    self.sum_cols = [] if self.sum_cols is None else self.sum_cols
    if isinstance(self.sum_cols, list):
        for idx in self.sum_cols:
            if not isinstance(idx, int):
                raise ValueError(f"type mismatch, column_indexes with element {idx}(type is {type(idx)})")

    if not isinstance(self.q_n, int):
        raise ValueError(f"Init param's q_n {self.q_n} not supported, should be int type", type is {type(self.q_n)})

    if self.q_n < 0:
        raise ValueError(f"param's q_n {self.q_n} not supported, should be non-negative int value")
    elif self.q_n > 16:
        raise ValueError(f"param's q_n {self.q_n} not supported, should be less than or equal to 16")

Features

1.Supports summation of floating-point numbers and negative numbers

2.Attacks can be detected when the malicious participant is less than (n-1)/2

Examples

Example
## Feldman Verifiable Sum Configuration Usage Guide.

This section introduces the dsl and conf for usage of a verifiable sum task.

#### Feldman Verifiable Sum Task.

1. Feldman Verifiable Sum Task:
    script: pipeline-feldman-verifiable-sum.py

Users can use following commands to running the task.

    python ${pipeline_script}
pipeline-feldman-verifiable-sum.py
import argparse

from pipeline.backend.pipeline import PipeLine
from pipeline.component import Reader
from pipeline.component import DataTransform
from pipeline.component import FeldmanVerifiableSum
from pipeline.interface import Data


from pipeline.utils.tools import load_job_config


def main(config="../../config.yaml", namespace=""):
    # obtain config
    if isinstance(config, str):
        config = load_job_config(config)
    parties = config.parties
    guest = parties.guest[0]
    hosts = parties.host

    guest_train_data = {"name": "breast_homo_test", "namespace": f"experiment{namespace}"}
    host_train_data = {"name": "breast_homo_test", "namespace": f"experiment{namespace}"}

    # initialize pipeline
    pipeline = PipeLine()
    # set job initiator
    pipeline.set_initiator(role="guest", party_id=guest)
    # set participants information
    pipeline.set_roles(guest=guest, host=hosts)

    # define Reader components to read in data
    reader_0 = Reader(name="reader_0")
    # configure Reader for guest
    reader_0.get_party_instance(role="guest", party_id=guest).component_param(table=guest_train_data)
    # configure Reader for host
    reader_0.get_party_instance(role="host", party_id=hosts).component_param(table=host_train_data)

    data_transform_0 = DataTransform(name="data_transform_0")
    # get and configure DataTransform party instance of guest
    data_transform_0.get_party_instance(
        role="guest", party_id=guest).component_param(
        with_label=False, output_format="dense")
    # get and configure DataTransform party instance of host
    data_transform_0.get_party_instance(role="host", party_id=hosts).component_param(with_label=False)

    # define FeldmanVerifiableSum components
    feldmanverifiablesum_0 = FeldmanVerifiableSum(name="feldmanverifiablesum_0")

    feldmanverifiablesum_0.get_party_instance(role="guest", party_id=guest).component_param(sum_cols=[1, 2, 3], q_n=6)

    feldmanverifiablesum_0.get_party_instance(role="host", party_id=hosts).component_param(sum_cols=[1, 2, 3], q_n=6)

    # add components to pipeline, in order of task execution.
    pipeline.add_component(reader_0)
    pipeline.add_component(data_transform_0, data=Data(data=reader_0.output.data))
    pipeline.add_component(feldmanverifiablesum_0, data=Data(data=data_transform_0.output.data))

    # compile pipeline once finished adding modules, this step will form conf and dsl files for running job
    pipeline.compile()

    # fit model
    pipeline.fit()


if __name__ == "__main__":
    parser = argparse.ArgumentParser("PIPELINE DEMO")
    parser.add_argument("-config", type=str,
                        help="config file")
    args = parser.parse_args()
    if args.config is not None:
        main(args.config)
    else:
        main()
feldman_verifiable_sum_testsuite.json
{
    "data": [
        {
            "file": "examples/data/breast_homo_test.csv",
            "head": 1,
            "partition": 16,
            "table_name": "breast_homo_test",
            "namespace": "experiment",
            "role": "guest_0"
        },
        {
            "file": "examples/data/breast_homo_test.csv",
            "head": 1,
            "partition": 16,
            "table_name": "breast_homo_test",
            "namespace": "experiment",
            "role": "host_0"
        },
        {
            "file": "examples/data/breast_homo_test.csv",
            "head": 1,
            "partition": 16,
            "table_name": "breast_homo_test",
            "namespace": "experiment",
            "role": "host_1"
        }
    ],
        "pipeline_tasks": {
        "feldman-secret-sharing-sum": {
            "script": "./pipeline-feldman-verifiable-sum.py"
        }
    }
}
## Feldman Verifiable Sum Configuration Usage Guide.

 This section introduces the dsl and conf for usage of different tasks.

 1. Feldman Verifiable Sum Task:

     dsl: test_feldman_verifiable_sum_dsl.json

     runtime_config : test_feldman_verifiable_sum_conf.json

 Users can use following commands to run the task.

     flow job submit -c ${runtime_config} -d ${dsl}        
feldman_verifiable_sum_testsuite.json
{
    "data": [
        {
            "file": "examples/data/breast_homo_test.csv",
            "head": 1,
            "partition": 16,
            "table_name": "breast_homo_testt",
            "namespace": "experiment",
            "role": "guest_0"
        },
        {
            "file": "examples/data/breast_homo_test.csv",
            "head": 1,
            "partition": 16,
            "table_name": "breast_homo_test",
            "namespace": "experiment",
            "role": "host_0"
        },
        {
            "file": "examples/data/breast_homo_test.csv",
            "head": 1,
            "partition": 16,
            "table_name": "breast_homo_test",
            "namespace": "experiment",
            "role": "host_1"
        }
    ],
    "tasks": {
        "feldman-secret-sharing-sum": {
            "conf": "test_feldman_verifiable_sum_conf.json",
            "dsl": "test_feldman_verifiable_sum_dsl.json"
        }
    }
}            
test_feldman_verifiable_sum_dsl.json
{
    "components": {
        "reader_0": {
            "module": "Reader",
            "output": {
                "data": [
                    "data"
                ]
            }
        },
        "data_transform_0": {
            "module": "DataTransform",
            "input": {
                "data": {
                    "data": [
                        "reader_0.data"
                    ]
                }
            },
            "output": {
                "data": [
                    "data"
                ],
                "model": [
                    "data_transform"
                ]
            }
        },
        "feldmanverifiablesum_0": {
            "module": "FeldmanVerifiableSum",
            "input": {
                "data": {
                    "data": [
                        "data_transform_0.data"
                    ]
                }
            },
            "output": {
                "data": [
                    "data"
                ]
            }
        }
    }
}            
test_feldman_verifiable_sum_conf.json
{
    "dsl_version": 2,
    "initiator": {
        "role": "guest",
        "party_id": 9999
    },
    "job_parameters": {
        "common": {
            "task_cores": 4
        }
    },
    "role": {
        "host": [
            10000,
            9999
        ],
        "guest": [
            9999
        ]
    },
    "component_parameters": {
        "common": {
            "feldmanverifiablesum_0": {
                "sum_cols": [
                    1,
                    2,
                    3
                ],
                "q_n": 6
            }
        },
        "role": {
            "host": {
                "0": {
                    "reader_0": {
                        "table": {
                            "name": "breast_homo_test",
                            "namespace": "experiment"
                        }
                    }
                },
                "1": {
                    "reader_0": {
                        "table": {
                            "name": "breast_homo_test",
                            "namespace": "experiment"
                        }
                    }
                }
            },
            "guest": {
                "0": {
                    "reader_0": {
                        "table": {
                            "name": "breast_homo_test",
                            "namespace": "experiment"
                        }
                    }
                }
            }
        }
    }
}            

最后更新: 2022-02-22