Skip to content

Commit

Permalink
Merge pull request #5 from MaximeZmt/Work-Mzmt-UserID
Browse files Browse the repository at this point in the history
Update ID Wording + transmit SCIPER ID at every transaction on blockchain
  • Loading branch information
MaximeZmt authored Apr 16, 2024
2 parents 84360be + 8973938 commit 2942f02
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 66 deletions.
14 changes: 7 additions & 7 deletions contracts/evoting/controller/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {
}

castVoteRequest := ptypes.CastVoteRequest{
UserID: "user1",
Ballot: ballot1,
VoterID: "user1",
Ballot: ballot1,
}

signed, err := createSignedRequest(secret, castVoteRequest)
Expand All @@ -377,8 +377,8 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {
}

castVoteRequest = ptypes.CastVoteRequest{
UserID: "user2",
Ballot: ballot2,
VoterID: "user2",
Ballot: ballot2,
}

signed, err = createSignedRequest(secret, castVoteRequest)
Expand All @@ -402,8 +402,8 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {
}

castVoteRequest = ptypes.CastVoteRequest{
UserID: "user3",
Ballot: ballot3,
VoterID: "user3",
Ballot: ballot3,
}

signed, err = createSignedRequest(secret, castVoteRequest)
Expand Down Expand Up @@ -593,7 +593,7 @@ func setupSimpleForm(ctx node.Context, secret kyber.Scalar, proxyAddr1 string,

createSimpleFormRequest := ptypes.CreateFormRequest{
Configuration: configuration,
AdminID: "adminId",
UserID: "UserID",
}

signed, err := createSignedRequest(secret, createSimpleFormRequest)
Expand Down
2 changes: 1 addition & 1 deletion contracts/evoting/evoting.go

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

6 changes: 3 additions & 3 deletions contracts/evoting/json/suffragia.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (suffragiaFormat) Decode(ctx serde.Context, data []byte) (serde.Message, er

// SuffragiaJSON defines the JSON representation of a suffragia.
type SuffragiaJSON struct {
UserIDs []string
VoterIDs []string
Ciphervotes []json.RawMessage
}

Expand All @@ -58,7 +58,7 @@ func encodeSuffragia(ctx serde.Context, suffragia types.Suffragia) (SuffragiaJSO
ciphervotes[i] = buff
}
return SuffragiaJSON{
UserIDs: suffragia.UserIDs,
VoterIDs: suffragia.VoterIDs,
Ciphervotes: ciphervotes,
}, nil
}
Expand Down Expand Up @@ -89,7 +89,7 @@ func decodeSuffragia(ctx serde.Context, suffragiaJSON SuffragiaJSON) (types.Suff
}

res = types.Suffragia{
UserIDs: suffragiaJSON.UserIDs,
VoterIDs: suffragiaJSON.VoterIDs,
Ciphervotes: ciphervotes,
}

Expand Down
16 changes: 8 additions & 8 deletions contracts/evoting/json/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (transactionFormat) Encode(ctx serde.Context, msg serde.Message) ([]byte, e
case types.CreateForm:
ce := CreateFormJSON{
Configuration: t.Configuration,
AdminID: t.AdminID,
UserID: t.UserID,
}

m = TransactionJSON{CreateForm: &ce}
Expand All @@ -39,7 +39,7 @@ func (transactionFormat) Encode(ctx serde.Context, msg serde.Message) ([]byte, e

cv := CastVoteJSON{
FormID: t.FormID,
UserID: t.UserID,
VoterID: t.VoterID,
Ciphervote: ballot,
}

Expand Down Expand Up @@ -143,7 +143,7 @@ func (transactionFormat) Decode(ctx serde.Context, data []byte) (serde.Message,
case m.CreateForm != nil:
return types.CreateForm{
Configuration: m.CreateForm.Configuration,
AdminID: m.CreateForm.AdminID,
UserID: m.CreateForm.UserID,
}, nil
case m.OpenForm != nil:
return types.OpenForm{
Expand Down Expand Up @@ -211,7 +211,7 @@ type TransactionJSON struct {
// CreateFormJSON is the JSON representation of a CreateForm transaction
type CreateFormJSON struct {
Configuration types.Configuration
AdminID string
UserID string
}

// OpenFormJSON is the JSON representation of a OpenForm transaction
Expand All @@ -222,7 +222,7 @@ type OpenFormJSON struct {
// CastVoteJSON is the JSON representation of a CastVote transaction
type CastVoteJSON struct {
FormID string
UserID string
VoterID string
Ciphervote json.RawMessage
}

Expand Down Expand Up @@ -285,9 +285,9 @@ func decodeCastVote(ctx serde.Context, m CastVoteJSON) (serde.Message, error) {
}

return types.CastVote{
FormID: m.FormID,
UserID: m.UserID,
Ballot: ciphervote,
FormID: m.FormID,
VoterID: m.VoterID,
Ballot: ciphervote,
}, nil
}

Expand Down
8 changes: 4 additions & 4 deletions contracts/evoting/mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestCommand_CreateForm(t *testing.T) {
}

createForm := types.CreateForm{
AdminID: "dummyAdminID",
UserID: "dummyUserID",
}

data, err := createForm.Serialize(ctx)
Expand Down Expand Up @@ -175,8 +175,8 @@ func TestCommand_CastVote(t *testing.T) {
initMetrics()

castVote := types.CastVote{
FormID: fakeFormID,
UserID: "dummyUserId",
FormID: fakeFormID,
VoterID: "dummyVoterId",
Ballot: types.Ciphervote{types.EGPair{
K: suite.Point(),
C: suite.Point(),
Expand Down Expand Up @@ -300,7 +300,7 @@ func TestCommand_CastVote(t *testing.T) {
require.NoError(t, err)
require.True(t, castVote.Ballot.Equal(suff.Ciphervotes[0]))

require.Equal(t, castVote.UserID, suff.UserIDs[0])
require.Equal(t, castVote.VoterID, suff.VoterIDs[0])
require.Equal(t, float64(form.BallotCount), testutil.ToFloat64(PromFormBallots))
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/evoting/types/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (s *Form) Suffragia(ctx serde.Context, rd store.Readable) (Suffragia, error
return suff, xerrors.Errorf("couldn't unmarshal ballots block in cast: %v", err)
}
suffTmp := msg.(Suffragia)
for i, uid := range suffTmp.UserIDs {
for i, uid := range suffTmp.VoterIDs {
suff.CastVote(uid, suffTmp.Ciphervotes[i])
}
}
Expand Down
12 changes: 6 additions & 6 deletions contracts/evoting/types/suffragia.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func RegisterSuffragiaFormat(format serde.Format, engine serde.FormatEngine) {
}

type Suffragia struct {
UserIDs []string
VoterIDs []string
Ciphervotes []Ciphervote
}

Expand All @@ -36,22 +36,22 @@ func (s Suffragia) Serialize(ctx serde.Context) ([]byte, error) {
}

// CastVote adds a new vote and its associated user or updates a user's vote.
func (s *Suffragia) CastVote(userID string, ciphervote Ciphervote) {
for i, u := range s.UserIDs {
if u == userID {
func (s *Suffragia) CastVote(voterID string, ciphervote Ciphervote) {
for i, u := range s.VoterIDs {
if u == voterID {
s.Ciphervotes[i] = ciphervote
return
}
}

s.UserIDs = append(s.UserIDs, userID)
s.VoterIDs = append(s.VoterIDs, voterID)
s.Ciphervotes = append(s.Ciphervotes, ciphervote.Copy())
}

// Hash returns the hash of this list of ballots.
func (s *Suffragia) Hash(ctx serde.Context) ([]byte, error) {
h := sha256.New()
for i, u := range s.UserIDs {
for i, u := range s.VoterIDs {
h.Write([]byte(u))
buf, err := s.Ciphervotes[i].Serialize(ctx)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions contracts/evoting/types/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (t TransactionFactory) Deserialize(ctx serde.Context, data []byte) (serde.M
// - implements serde.Message
type CreateForm struct {
Configuration Configuration
AdminID string
UserID string
}

// Serialize implements serde.Message
Expand Down Expand Up @@ -132,9 +132,9 @@ func (oe OpenForm) Serialize(ctx serde.Context) ([]byte, error) {
// - implements serde.Message
type CastVote struct {
// FormID is hex-encoded
FormID string
UserID string
Ballot Ciphervote
FormID string
VoterID string
Ballot Ciphervote
}

// Serialize implements serde.Message
Expand Down
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Return:

```json
{
"UserID": "",
"VoterID": "",
"Ballot": [
{
"K": "<bin>",
Expand Down
4 changes: 2 additions & 2 deletions docs/smart_contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ This transaction requires the following 3 parameters:

1. `actor` of type dkg.Actor
2. `formID` (see Create Form above)
3. `userID` of the voter
3. `VoterID` of the voter
4. `vote` to be casted

Key / Value pairs sent in the transaction in order to create a form:
Expand All @@ -88,7 +88,7 @@ where:
evoting.CastVoteArg = "evoting:cast_vote"
castVoteBuf = a marshalled version of types.CastVoteTransaction{
FormID: hex.EncodeToString(formID),
UserID: userID,
VoterID: VoterID,
Ballot: ballot, // a vote encrypted by the actor
}
evoting.CmdArg = "evoting:command"
Expand Down
3 changes: 2 additions & 1 deletion docs/verifiability_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The current d-voting [latest commit](https://github.com/c4dt/d-voting/commit/39a
Note over User: encrypt ballot via Elgamal encryption using electionPubKey
Note over User, Backend: data = encrypted ballot
Note over Backend: check role and sign payload.
Note over Backend: add voterID inside payload.
Note over Backend: add userID inside payload.
Note over Backend: sign = kyber.sign.schnorr.sign(edCurve, scalar, hash);
Backend ->>+ NodeX: POST /evoting/elections/
Expand Down Expand Up @@ -96,7 +97,7 @@ sequenceDiagram
Note over User: generate hash of encrypted ballot and show to user
Note over User, Backend: data = encrypted ballot
Note over Backend: check role and sign payload.
Note over Backend: add userID inside payload.
Note over Backend: add VoterID inside payload.
Note over Backend: sign = kyber.sign.schnorr.sign(edCurve, scalar, hash);
Backend ->>+ NodeX: POST /evoting/elections/
Note over Backend, NodeX: data: {"Payload": dataStrB64, "Signature": ""}
Expand Down
24 changes: 12 additions & 12 deletions integration/ballot.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ func castVotesRandomly(m txManager, actor dkg.Actor, form types.Form,
return nil, xerrors.Errorf("failed to marshallBallot: %v", err)
}

userID := "user " + strconv.Itoa(i)
voterID := "user " + strconv.Itoa(i)

castVote := types.CastVote{
FormID: form.FormID,
UserID: userID,
Ballot: ciphervote,
FormID: form.FormID,
VoterID: voterID,
Ballot: ciphervote,
}

data, err := castVote.Serialize(serdecontext)
Expand Down Expand Up @@ -122,12 +122,12 @@ func castBadVote(m txManager, actor dkg.Actor, form types.Form, numberOfBadVotes
return xerrors.Errorf("failed to marshallBallot: %v", err)
}

userID := "badUser " + strconv.Itoa(i)
voterID := "badUser " + strconv.Itoa(i)

castVote := types.CastVote{
FormID: form.FormID,
UserID: userID,
Ballot: ciphervote,
FormID: form.FormID,
VoterID: voterID,
Ballot: ciphervote,
}

data, err := castVote.Serialize(serdecontext)
Expand Down Expand Up @@ -348,8 +348,8 @@ func castVotesLoad(numVotesPerSec, numSec, BallotSize, chunksPerBallot int, form
idx := i*numVotesPerSec + j
randomproxy := proxyArray[rand.Intn(proxyCount)]
castVoteRequest := ptypes.CastVoteRequest{
UserID: "user" + strconv.Itoa(idx),
Ballot: ballot,
VoterID: "user" + strconv.Itoa(idx),
Ballot: ballot,
}
// cast asynchrounously and increment includedVoteCount
// if the cast was succesfull
Expand Down Expand Up @@ -450,8 +450,8 @@ func castVotesScenario(numVotes, BallotSize, chunksPerBallot int, formID, conten
require.NoError(t, err)

castVoteRequest := ptypes.CastVoteRequest{
UserID: "user" + strconv.Itoa(i+1),
Ballot: ballot,
VoterID: "user" + strconv.Itoa(i+1),
Ballot: ballot,
}

randomproxy := proxyArray[rand.Intn(len(proxyArray))]
Expand Down
4 changes: 2 additions & 2 deletions integration/form.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func createForm(m txManager, title string, admin string) ([]byte, error) {

createForm := types.CreateForm{
Configuration: configuration,
AdminID: admin,
UserID: admin,
}

data, err := createForm.Serialize(serdecontext)
Expand Down Expand Up @@ -75,7 +75,7 @@ func createFormScenario(contentType, proxy string, secret kyber.Scalar, t *testi

createSimpleFormRequest := ptypes.CreateFormRequest{
Configuration: configuration,
AdminID: "adminId",
UserID: "adminId",
}

signed, err := createSignedRequest(secret, createSimpleFormRequest)
Expand Down
10 changes: 5 additions & 5 deletions integration/performance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func createFormNChunks(m txManager, title types.Title, admin string, numChunks i

createForm := types.CreateForm{
Configuration: configuration,
AdminID: admin,
UserID: admin,
}

data, err := createForm.Serialize(serdecontext)
Expand Down Expand Up @@ -272,12 +272,12 @@ func castVotesNChunks(m txManager, actor dkg.Actor, form types.Form,
start := time.Now()
for i := 0; i < numberOfVotes; i++ {

userID := "user " + strconv.Itoa(i)
voterID := "user " + strconv.Itoa(i)

castVote := types.CastVote{
FormID: form.FormID,
UserID: userID,
Ballot: ballot,
FormID: form.FormID,
VoterID: voterID,
Ballot: ballot,
}

data, err := castVote.Serialize(serdecontext)
Expand Down
Loading

0 comments on commit 2942f02

Please sign in to comment.