Skip to content

Commit

Permalink
Merge branch 'c4dt:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeZmt authored Mar 4, 2024
2 parents 036084d + af1c47a commit c703526
Show file tree
Hide file tree
Showing 67 changed files with 2,401 additions and 1,120 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ jobs:
uses: docker/build-push-action@v2
with:
context: .
target: build
file: Dockerfiles/Dockerfile.dela
platforms: linux/amd64
push: true
Expand Down
22 changes: 12 additions & 10 deletions Dockerfiles/Dockerfile.dela
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
FROM golang:1.20.6-bookworm AS base
RUN apt-get update && apt-get install git
# make sure we're using the same head as d-voting
RUN git clone https://github.com/c4dt/dela.git
WORKDIR /go/dela/cli/crypto
RUN go install
WORKDIR /go/d-voting
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .

FROM base AS build
COPY --from=base /go/dela .
COPY --from=base /go/d-voting .
ENV GOCACHE=/root/.cache/go-build
WORKDIR /go/d-voting/cli/dvoting
RUN go build
ENV PATH=/go/dela/cli/crypto:/go/d-voting/cli/dvoting:${PATH}
RUN --mount=type=cache,target="/root/.cache/go-build" go install
# make sure we're using the same head as d-voting
RUN --mount=type=cache,target="/root/.cache/go-build" cd $( go list -f '{{.Dir}}' go.dedis.ch/dela )/cli/crypto && go install

FROM golang:1.20.6-bookworm
WORKDIR /usr/local/bin
COPY --from=base /go/bin/crypto .
COPY --from=base /go/bin/dvoting .
ENTRYPOINT ["/bin/bash", "-c", "dvoting --config /data/node start --postinstall --proxyaddr :$PROXYPORT --proxykey $PROXYKEY --listen tcp://0.0.0.0:2000 --public $PUBLIC_URL --routing tree --noTLS"]
CMD []
63 changes: 18 additions & 45 deletions contracts/evoting/controller/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {

fmt.Fprintln(ctx.Out, "Get form")

form, err = getForm(serdecontext, formFac, formID, service)
form, err = types.FormFromStore(serdecontext, formFac, formID, service.GetStore())
if err != nil {
return xerrors.Errorf(getFormErr, err)
}
Expand Down Expand Up @@ -420,12 +420,16 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {

dela.Logger.Info().Msg(responseBody + respBody)

form, err = getForm(serdecontext, formFac, formID, service)
form, err = types.FormFromStore(serdecontext, formFac, formID, service.GetStore())
if err != nil {
return xerrors.Errorf(getFormErr, err)
}

encryptedBallots := form.Suffragia.Ciphervotes
suff, err := form.Suffragia(serdecontext, service.GetStore())
if err != nil {
return xerrors.Errorf(getFormErr, err)
}
encryptedBallots := suff.Ciphervotes
dela.Logger.Info().Msg("Length encrypted ballots: " + strconv.Itoa(len(encryptedBallots)))
dela.Logger.Info().Msgf("Ballot of user1: %s", encryptedBallots[0])
dela.Logger.Info().Msgf("Ballot of user2: %s", encryptedBallots[1])
Expand All @@ -440,7 +444,7 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {
return xerrors.Errorf("failed to close form: %v", err)
}

form, err = getForm(serdecontext, formFac, formID, service)
form, err = types.FormFromStore(serdecontext, formFac, formID, service.GetStore())
if err != nil {
return xerrors.Errorf(getFormErr, err)
}
Expand Down Expand Up @@ -478,14 +482,18 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {

// time.Sleep(20 * time.Second)

form, err = getForm(serdecontext, formFac, formID, service)
form, err = types.FormFromStore(serdecontext, formFac, formID, service.GetStore())
if err != nil {
return xerrors.Errorf(getFormErr, err)
}

logFormStatus(form)
dela.Logger.Info().Msg("Number of shuffled ballots : " + strconv.Itoa(len(form.ShuffleInstances)))
dela.Logger.Info().Msg("Number of encrypted ballots : " + strconv.Itoa(len(form.Suffragia.Ciphervotes)))
suff, err = form.Suffragia(serdecontext, service.GetStore())
if err != nil {
return xerrors.Errorf(getFormErr, err)
}
dela.Logger.Info().Msg("Number of encrypted ballots : " + strconv.Itoa(len(suff.Ciphervotes)))

// ###################################### REQUEST PUBLIC SHARES ############

Expand All @@ -498,7 +506,7 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {

time.Sleep(10 * time.Second)

form, err = getForm(serdecontext, formFac, formID, service)
form, err = types.FormFromStore(serdecontext, formFac, formID, service.GetStore())
if err != nil {
return xerrors.Errorf(getFormErr, err)
}
Expand All @@ -517,7 +525,7 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {
return xerrors.Errorf("failed to combine shares: %v", err)
}

form, err = getForm(serdecontext, formFac, formID, service)
form, err = types.FormFromStore(serdecontext, formFac, formID, service.GetStore())
if err != nil {
return xerrors.Errorf(getFormErr, err)
}
Expand All @@ -532,7 +540,7 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {

fmt.Fprintln(ctx.Out, "Get form result")

form, err = getForm(serdecontext, formFac, formID, service)
form, err = types.FormFromStore(serdecontext, formFac, formID, service.GetStore())
if err != nil {
return xerrors.Errorf(getFormErr, err)
}
Expand Down Expand Up @@ -631,7 +639,7 @@ func setupSimpleForm(ctx node.Context, secret kyber.Scalar, proxyAddr1 string,
return "", types.Form{}, nil, xerrors.Errorf("failed to decode formID '%s': %v", formID, err)
}

form, err := getForm(serdecontext, formFac, formID, service)
form, err := types.FormFromStore(serdecontext, formFac, formID, service.GetStore())
if err != nil {
return "", types.Form{}, nil, xerrors.Errorf(getFormErr, err)
}
Expand Down Expand Up @@ -803,41 +811,6 @@ func updateDKG(secret kyber.Scalar, proxyAddr, formIDHex, action string) (int, e
return 0, nil
}

// getForm gets the form from the snap. Returns the form ID NOT hex
// encoded.
func getForm(ctx serde.Context, formFac serde.Factory, formIDHex string,
srv ordering.Service) (types.Form, error) {

var form types.Form

formID, err := hex.DecodeString(formIDHex)
if err != nil {
return form, xerrors.Errorf("failed to decode formIDHex: %v", err)
}

proof, err := srv.GetProof(formID)
if err != nil {
return form, xerrors.Errorf("failed to get proof: %v", err)
}

formBuff := proof.GetValue()
if len(formBuff) == 0 {
return form, xerrors.Errorf("form does not exist")
}

message, err := formFac.Deserialize(ctx, formBuff)
if err != nil {
return form, xerrors.Errorf("failed to deserialize Form: %v", err)
}

form, ok := message.(types.Form)
if !ok {
return form, xerrors.Errorf("wrong message type: %T", message)
}

return form, nil
}

func createSignedErr(err error) error {
return xerrors.Errorf("failed to create signed request: %v", err)
}
Expand Down
33 changes: 12 additions & 21 deletions contracts/evoting/evoting.go

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

Loading

0 comments on commit c703526

Please sign in to comment.