4 files changed, 112 insertions(+) viff/test/sfdl/mp-millionaires.sfdl | 23 ++++++++++++++ viff/test/sfdl/mp-secondpriceauction.sfdl | 45 +++++++++++++++++++++++++++++ viff/test/sfdl/mp-voting.sfdl | 33 +++++++++++++++++++++ viff/test/sfdl/test_examples.py | 11 +++++++
# HG changeset patch # User Martin Geisler <[EMAIL PROTECTED]> # Date 1227518476 -3600 # Node ID ca37920c34868b17549b5bcf0fa17bbf07f05ebb # Parent 4c16d331284ddcdffcc690c1703c769a16fa7519 Added multiparty SFDL examples. The examples have been downloaded from the FairPlay project: http://www.cs.huji.ac.il/project/Fairplay/fairplayMP.html diff --git a/viff/test/sfdl/mp-millionaires.sfdl b/viff/test/sfdl/mp-millionaires.sfdl new file mode 100644 --- /dev/null +++ b/viff/test/sfdl/mp-millionaires.sfdl @@ -0,0 +1,23 @@ +/* + * Alice, Bob and Charlie are player types. + * Alice has input and output, Bob only has an input and Charlie only has an output. + * alice0, alice1, bob and charlie are the players who participate in the protocol. + * alice0 is of type Alice. Her output is 1 if she is richer than bob. + * alice1 is of type Alice. Her output is 1 if she is richer than alice0 and than bob. + * charlie is of type Charlie. His output is 1 if bob is richer than alice0. + */ +program Millionaires{ + type int = Int<4>; + + type Alice = struct {int input, Boolean output}; + type Bob = struct {int input}; + type Charlie = struct {Boolean output}; + + function void main (Alice[2] alice, Bob bob, Charlie charlie){ + alice[0].output = (alice[0].input > bob.input); + alice[1].output = (alice[1].input > alice[0].input) + && (alice[1].input > bob.input); + charlie.output = (bob.input > alice[0].input); + } +} + diff --git a/viff/test/sfdl/mp-secondpriceauction.sfdl b/viff/test/sfdl/mp-secondpriceauction.sfdl new file mode 100644 --- /dev/null +++ b/viff/test/sfdl/mp-secondpriceauction.sfdl @@ -0,0 +1,45 @@ +/** + * Performs a 2nd price auction between 4 bidders. + * At the end only the winning bidder and the seller know the identity of the winner + * Everyone knows the 2nd highest price, + * Nothing else is known to anyone. + **/ +program SecondPriceAuction{ + const nBidders = 4; + type Bid = Int<4>; // enough bits to represent a small bid. + type WinningBidder = Int<3>; // enough bits to represent a winner (nBitters bits). + + type SellerOutput = struct{WinningBidder winner, Bid winningPrice}; + type Seller = struct{SellerOutput output}; // Seller has no input + + type BidderOutput = struct{Boolean win, Bid winningPrice}; + type Bidder = struct{Bid input, BidderOutput output}; + + function void main(Seller seller, Bidder[nBidders] bidder){ + var Bid high; + var Bid second; + var WinningBidder winner; + winner = 0; high = bidder[0].input; second = 0; + + // Making the auction. + for(i=1 to nBidders-1){ + if(bidder[i].input > high){ + winner = i; + second = high; + high = bidder[i].input; + } + else { + if(bidder[i].input > second) + second = bidder[i].input; + } + } + + // Setting the result. + seller.output.winner = winner; + seller.output.winningPrice = second; + for(i=0 to nBidders-1){ + bidder[i].output.win = (winner == i); + bidder[i].output.winningPrice = second; + } + } +} \ No newline at end of file diff --git a/viff/test/sfdl/mp-voting.sfdl b/viff/test/sfdl/mp-voting.sfdl new file mode 100644 --- /dev/null +++ b/viff/test/sfdl/mp-voting.sfdl @@ -0,0 +1,33 @@ +/** + * Performs a voting between two candidates. + * At the end all the voters know who won. + * Nothing else is known to anyone. + **/ +program voting{ + const nVoters = 5; + type VotesCount = Int<4>; // Enough bits to count up to 5 voters. + + // Two candidates (in two's compliment). + type Vote = Int<2>; + type Voter = struct{Vote input, Vote output}; + + function void main(Voter[nVoters] voters){ + var VotesCount[2] vc; + var Vote win; + + // Making the voting. + for(i=0 to nVoters-1){ + if(voters[i].input == 0) + vc[0] = vc[0] + 1; + else + vc[1] = vc[1] + 1; + } + + if (vc[1] > vc[0]) + win = 1; + + // Setting the result. + for(i=0 to nVoters-1) + voters[i].output = win; + } +} diff --git a/viff/test/sfdl/test_examples.py b/viff/test/sfdl/test_examples.py --- a/viff/test/sfdl/test_examples.py +++ b/viff/test/sfdl/test_examples.py @@ -49,6 +49,17 @@ def test_median(self): self.assertParse("median.sfdl") +class TestMultiPlayerParsing(TestCase, ParsingMixin): + + def test_mp_millionaires(self): + self.assertParse("mp-millionaires.sfdl") + + def test_mp_secondpriceauction(self): + self.assertParse("mp-secondpriceauction.sfdl") + + def test_mp_voting(self): + self.assertParse("mp-voting.sfdl") + if SFDLGrammar is None: TestParsing.skip = "Could not import SFDLGrammar, missing pyparsing?" _______________________________________________ viff-patches mailing list [email protected] http://lists.viff.dk/listinfo.cgi/viff-patches-viff.dk
