Skip to content

Commit

Permalink
Follow DEDIS/master updates
Browse files Browse the repository at this point in the history
This commit updates the code to work with the latest updates from the DEDIS/master branch.
Now when we have new commits, we can also open PRs against the DEDIS/master upstream.
  • Loading branch information
ineiti committed Nov 21, 2023
1 parent 09b624c commit a7ea54f
Show file tree
Hide file tree
Showing 21 changed files with 74 additions and 78 deletions.
1 change: 0 additions & 1 deletion cli/cosipbftcontroller/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func TestRosterAddAction_Execute(t *testing.T) {

var p pool.Pool
require.NoError(t, ctx.Injector.Resolve(&p))
require.Equal(t, 1, p.Len())

ctx.Injector = node.NewInjector()
err = action.Execute(ctx)
Expand Down
5 changes: 1 addition & 4 deletions cli/cosipbftcontroller/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ const (
errInjector = "injector: %v"
)

// valueAccessKey is the access key used for the value contract.
var valueAccessKey = [32]byte{2}

func blsSigner() encoding.BinaryMarshaler {
return bls.NewSigner()
}
Expand Down Expand Up @@ -130,7 +127,7 @@ func (m miniController) OnStart(flags cli.Flags, inj node.Injector) error {
rosterFac := authority.NewFactory(onet.GetAddressFactory(), cosi.GetPublicKeyFactory())
cosipbft.RegisterRosterContract(exec, rosterFac, access)

value.RegisterContract(exec, value.NewContract(valueAccessKey[:], access))
value.RegisterContract(exec, value.NewContract(access))

txFac := signed.NewTransactionFactory()
vs := simple.NewService(exec, txFac)
Expand Down
9 changes: 6 additions & 3 deletions contracts/evoting/evoting.go

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

30 changes: 16 additions & 14 deletions contracts/evoting/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ const (
var suite = suites.MustFind("Ed25519")

const (
// ContractUID is the UID of the contract
ContractUID = "EVOT"

// ContractName is the name of the contract.
ContractName = "go.dedis.ch/dela.Evoting"

Expand Down Expand Up @@ -126,8 +129,8 @@ const (

// NewCreds creates new credentials for a evoting contract execution. We might
// want to use in the future a separate credential for each command.
func NewCreds(id []byte) access.Credential {
return access.NewContractCreds(id, ContractName, credentialAllCommand)
func NewCreds() access.Credential {
return access.NewContractCreds([]byte(ContractUID), ContractName, credentialAllCommand)
}

// RegisterContract registers the value contract to the given execution service.
Expand All @@ -143,15 +146,10 @@ type Contract struct {
// access is the access control service managing this smart contract
access access.Service

// accessKey is the access identifier allowed to use this smart contract
accessKey []byte

cmd commands

pedersen dkg.DKG

rosterKey []byte

context serde.Context

formFac serde.Factory
Expand All @@ -160,7 +158,7 @@ type Contract struct {
}

// NewContract creates a new Value contract
func NewContract(accessKey, rosterKey []byte, srvc access.Service,
func NewContract(srvc access.Service,
pedersen dkg.DKG, rosterFac authority.Factory) Contract {

ctx := json.NewContext()
Expand All @@ -170,11 +168,8 @@ func NewContract(accessKey, rosterKey []byte, srvc access.Service,
transactionFac := types.NewTransactionFactory(ciphervoteFac)

contract := Contract{
access: srvc,
accessKey: accessKey,
pedersen: pedersen,

rosterKey: rosterKey,
access: srvc,
pedersen: pedersen,

context: ctx,

Expand All @@ -190,7 +185,7 @@ func NewContract(accessKey, rosterKey []byte, srvc access.Service,

// Execute implements native.Contract
func (c Contract) Execute(snap store.Snapshot, step execution.Step) error {
creds := NewCreds(c.accessKey)
creds := NewCreds()

err := c.access.Match(snap, creds, step.Current.GetIdentity())
if err != nil {
Expand Down Expand Up @@ -256,6 +251,13 @@ func (c Contract) Execute(snap store.Snapshot, step execution.Step) error {
return nil
}

// UID returns the unique 4-bytes contract identifier.
//
// - implements native.Contract
func (c Contract) UID() string {
return ContractUID
}

func init() {
dvoting.PromCollectors = append(dvoting.PromCollectors,
PromFormStatus,
Expand Down
17 changes: 4 additions & 13 deletions contracts/evoting/mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,17 @@ func TestExecute(t *testing.T) {
actor: fakeDkgActor{},
err: nil,
}
var evotingAccessKey = [32]byte{3}
rosterKey := [32]byte{}

service := fakeAccess{err: fake.GetError()}
rosterFac := fakeAuthorityFactory{}

contract := NewContract(evotingAccessKey[:], rosterKey[:], service, fakeDkg, rosterFac)
contract := NewContract(service, fakeDkg, rosterFac)

err := contract.Execute(fakeStore{}, makeStep(t))
require.EqualError(t, err, "identity not authorized: fake.PublicKey ("+fake.GetError().Error()+")")

service = fakeAccess{}

contract = NewContract(evotingAccessKey[:], rosterKey[:], service, fakeDkg, rosterFac)
contract = NewContract(service, fakeDkg, rosterFac)
err = contract.Execute(fakeStore{}, makeStep(t))
require.EqualError(t, err, "\"evoting:command\" not found in tx arg")

Expand Down Expand Up @@ -129,13 +126,10 @@ func TestCommand_CreateForm(t *testing.T) {
data, err := createForm.Serialize(ctx)
require.NoError(t, err)

var evotingAccessKey = [32]byte{3}
rosterKey := [32]byte{}

service := fakeAccess{err: fake.GetError()}
rosterFac := fakeAuthorityFactory{}

contract := NewContract(evotingAccessKey[:], rosterKey[:], service, fakeDkg, rosterFac)
contract := NewContract(service, fakeDkg, rosterFac)

cmd := evotingCommand{
Contract: &contract,
Expand Down Expand Up @@ -1131,13 +1125,10 @@ func initFormAndContract() (types.Form, Contract) {
Roster: fake.Authority{},
}

var evotingAccessKey = [32]byte{3}
rosterKey := [32]byte{}

service := fakeAccess{err: fake.GetError()}
rosterFac := fakeAuthorityFactory{}

contract := NewContract(evotingAccessKey[:], rosterKey[:], service, fakeDkg, rosterFac)
contract := NewContract(service, fakeDkg, rosterFac)

return dummyForm, contract
}
Expand Down
3 changes: 2 additions & 1 deletion contracts/evoting/types/ballots.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ type Ballot struct {
}

// Unmarshal decodes the given string according to the format described in
// "state of smart contract.md"
// "/docs/state_of_smart_contract.md"
// TODO: actually describe the format in there...
func (b *Ballot) Unmarshal(marshalledBallot string, form Form) error {
lines := strings.Split(marshalledBallot, "\n")

Expand Down
2 changes: 1 addition & 1 deletion deb-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ PK=<> # taken from the "ordering export", the part after ":"
sudo dvoting --config /var/opt/dedis/dvoting/data/dela pool add \
--key $keypath \
--args go.dedis.ch/dela.ContractArg --args go.dedis.ch/dela.Access \
--args access:grant_id --args 0300000000000000000000000000000000000000000000000000000000000000 \
--args access:grant_id --args 45564f54 \
--args access:grant_contract --args go.dedis.ch/dela.Evoting \
--args access:grant_command --args all \
--args access:identity --args $PK \
Expand Down
4 changes: 2 additions & 2 deletions docs/state_of_smart_contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

In the use cases we defined two smart contracts for each of the following purposes:

- storing the forms informations
- storing the forms information
- storing a ballot

As (at least for the moment) in a dela there is no notion of “instance of a smart contract”, we have
Expand Down Expand Up @@ -172,7 +172,7 @@ Subject2:

And here is the corresponding Configuration:

```bash
```go
v := Configuration{
MainTitle: "Please give your opinion",
Scaffold: []Subject{
Expand Down
2 changes: 0 additions & 2 deletions integration/ballot.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"math/rand"
"net/http"
Expand Down Expand Up @@ -241,7 +240,6 @@ func marshallBallotManual(voteStr string, pubkey kyber.Point, chunks int) (ptype

ballot := make(ptypes.CiphervoteJSON, chunks)
vote := strings.NewReader(voteStr)
fmt.Printf("votestr is: %v", voteStr)

buf := make([]byte, 29)

Expand Down
16 changes: 4 additions & 12 deletions integration/dvotingdela.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ import (
const certKeyName = "cert.key"
const privateKeyFile = "private.key"

var aKey = [32]byte{1}
var valueAccessKey = [32]byte{2}

// evotingAccessKey is the access key used for the evoting contract.
var evotingAccessKey = [32]byte{3}

// dela defines the common interface for a Dela node.
type dela interface {
Setup(...dela)
Expand Down Expand Up @@ -193,7 +187,7 @@ func newDVotingNode(t require.TestingT, path string, randSource rand.Source) dVo
rosterFac := authority.NewFactory(onet.GetAddressFactory(), cosi.GetPublicKeyFactory())
cosipbft.RegisterRosterContract(exec, rosterFac, accessService)

value.RegisterContract(exec, value.NewContract(valueAccessKey[:], accessService))
value.RegisterContract(exec, value.NewContract(accessService))

txFac := signed.NewTransactionFactory()
vs := simple.NewService(exec, txFac)
Expand Down Expand Up @@ -242,16 +236,14 @@ func newDVotingNode(t require.TestingT, path string, randSource rand.Source) dVo

// access
accessStore := newAccessStore()
contract := accessContract.NewContract(aKey[:], accessService, accessStore)
contract := accessContract.NewContract(accessService, accessStore)
accessContract.RegisterContract(exec, contract)

formFac := etypes.NewFormFactory(etypes.CiphervoteFactory{}, rosterFac)

dkg := pedersen.NewPedersen(onet, srvc, pool, formFac, signer)

rosterKey := [32]byte{}
evoting.RegisterContract(exec, evoting.NewContract(evotingAccessKey[:], rosterKey[:],
accessService, dkg, rosterFac))
evoting.RegisterContract(exec, evoting.NewContract(accessService, dkg, rosterFac))

neffShuffle := neff.NewNeffShuffle(onet, srvc, pool, blocks, formFac, signer)

Expand Down Expand Up @@ -293,7 +285,7 @@ func createDVotingAccess(t require.TestingT, nodes []dVotingCosiDela, dir string
require.NoError(t, err)

pubKey := signer.GetPublicKey()
cred := accessContract.NewCreds(aKey[:])
cred := accessContract.NewCreds()

for _, node := range nodes {
n := node.(dVotingNode)
Expand Down
12 changes: 7 additions & 5 deletions integration/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
"testing"
"time"

"github.com/c4dt/d-voting/contracts/evoting"
"github.com/c4dt/d-voting/proxy/txnmanager"
"github.com/stretchr/testify/require"
"go.dedis.ch/dela/contracts/access"
"go.dedis.ch/dela/core/execution/native"
"go.dedis.ch/dela/core/ordering"
"go.dedis.ch/dela/core/txn"
Expand Down Expand Up @@ -158,11 +160,11 @@ func grantAccess(m txManager, signer crypto.Signer) error {

args := []txn.Arg{
{Key: native.ContractArg, Value: []byte("go.dedis.ch/dela.Access")},
{Key: "access:grant_id", Value: []byte(hex.EncodeToString(evotingAccessKey[:]))},
{Key: "access:grant_contract", Value: []byte("go.dedis.ch/dela.Evoting")},
{Key: "access:grant_command", Value: []byte("all")},
{Key: "access:identity", Value: []byte(base64.StdEncoding.EncodeToString(pubKeyBuf))},
{Key: "access:command", Value: []byte("GRANT")},
{Key: access.GrantIDArg, Value: []byte(hex.EncodeToString([]byte(evoting.ContractUID)))},
{Key: access.GrantContractArg, Value: []byte("go.dedis.ch/dela.Evoting")},
{Key: access.GrantCommandArg, Value: []byte("all")},
{Key: access.IdentityArg, Value: []byte(base64.StdEncoding.EncodeToString(pubKeyBuf))},
{Key: access.CmdArg, Value: []byte(access.CmdSet)},
}
_, err = m.addAndWait(args...)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions internal/testing/fake/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ func (f Pool) Close() error {
return nil
}

func (f Pool) Stats() pool.Stats {
return pool.Stats{}
}

func (f Pool) ResetStats() {}

// Manager is a fake manager
//
// - implements txn.Manager
Expand Down
5 changes: 4 additions & 1 deletion proxy/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ func (h *form) NewForm(w http.ResponseWriter, r *http.Request) {
}

// send the response json
txnmanager.SendResponse(w, response)
err = txnmanager.SendResponse(w, response)
if err != nil {
fmt.Printf("Caught unhandled error: %+v", err)
}
}

// NewFormVote implements proxy.Proxy
Expand Down
2 changes: 1 addition & 1 deletion proxy/txnmanager/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (h *manager) checkTxnIncluded(transactionID []byte, lastBlockIdx uint64) (T
}
}

// submitTxn submits a transaction
// SubmitTxn submits a transaction
// Returns the transaction ID.
func (h *manager) SubmitTxn(ctx context.Context, cmd evoting.Command,
cmdArg string, payload []byte) ([]byte, uint64, error) {
Expand Down
8 changes: 4 additions & 4 deletions runSystems.sh
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,15 @@ if [ "$SETUP" == true ]; then

echo "${GREEN}[4/4]${NC} grant access on the chain"

./dvoting --config /tmp/node1 pool add --key private.key --args go.dedis.ch/dela.ContractArg --args go.dedis.ch/dela.Access --args access:grant_id --args 0300000000000000000000000000000000000000000000000000000000000000 --args access:grant_contract --args go.dedis.ch/dela.Evoting --args access:grant_command --args all --args access:identity --args $(crypto bls signer read --path private.key --format BASE64_PUBKEY) \
./dvoting --config /tmp/node1 pool add --key private.key --args go.dedis.ch/dela.ContractArg --args go.dedis.ch/dela.Access --args access:grant_id --args 45564f54 --args access:grant_contract --args go.dedis.ch/dela.Evoting --args access:grant_command --args all --args access:identity --args $(crypto bls signer read --path private.key --format BASE64_PUBKEY) \
--args access:command --args GRANT

from=1

while [ $from -le $to ]; do

node_name="node$from"
./dvoting --config /tmp/node1 pool add --key private.key --args go.dedis.ch/dela.ContractArg --args go.dedis.ch/dela.Access --args access:grant_id --args 0300000000000000000000000000000000000000000000000000000000000000 --args access:grant_contract --args go.dedis.ch/dela.Evoting --args access:grant_command --args all --args access:identity --args $(crypto bls signer read --path /tmp/$node_name/private.key --format BASE64_PUBKEY) \
./dvoting --config /tmp/node1 pool add --key private.key --args go.dedis.ch/dela.ContractArg --args go.dedis.ch/dela.Access --args access:grant_id --args 45564f54 --args access:grant_contract --args go.dedis.ch/dela.Evoting --args access:grant_command --args all --args access:identity --args $(crypto bls signer read --path /tmp/$node_name/private.key --format BASE64_PUBKEY) \
--args access:command --args GRANT

((from++))
Expand Down Expand Up @@ -309,13 +309,13 @@ if [ "$SETUP" == true ]; then

echo "${GREEN}[4/4]${NC} grant access on the chain"

docker exec node1 dvoting --config /tmp/node1 pool add --key private.key --args go.dedis.ch/dela.ContractArg --args go.dedis.ch/dela.Access --args access:grant_id --args 0300000000000000000000000000000000000000000000000000000000000000 --args access:grant_contract --args go.dedis.ch/dela.Evoting --args access:grant_command --args all --args access:identity --args $access_token --args access:command --args GRANT
docker exec node1 dvoting --config /tmp/node1 pool add --key private.key --args go.dedis.ch/dela.ContractArg --args go.dedis.ch/dela.Access --args access:grant_id --args 45564f54 --args access:grant_contract --args go.dedis.ch/dela.Evoting --args access:grant_command --args all --args access:identity --args $access_token --args access:command --args GRANT

sleep 1

for i in "${vals[@]}"; do
access_token_tmp=$(docker exec node$i crypto bls signer read --path /tmp/node$i/private.key --format BASE64_PUBKEY)
docker exec node1 dvoting --config /tmp/node1 pool add --key private.key --args go.dedis.ch/dela.ContractArg --args go.dedis.ch/dela.Access --args access:grant_id --args 0300000000000000000000000000000000000000000000000000000000000000 --args access:grant_contract --args go.dedis.ch/dela.Evoting --args access:grant_command --args all --args access:identity --args $access_token_tmp --args access:command --args GRANT
docker exec node1 dvoting --config /tmp/node1 pool add --key private.key --args go.dedis.ch/dela.ContractArg --args go.dedis.ch/dela.Access --args access:grant_id --args 45564f54 --args access:grant_contract --args go.dedis.ch/dela.Evoting --args access:grant_command --args all --args access:identity --args $access_token_tmp --args access:command --args GRANT
sleep 1
done
fi
Expand Down
Loading

0 comments on commit a7ea54f

Please sign in to comment.