Skip to content

Commit

Permalink
Merge pull request #34 from mit-pdos/separate-setup
Browse files Browse the repository at this point in the history
separate out the setup code so that it's logically easier to reason about the different adversarial setup modes
  • Loading branch information
sanjit-bhat authored Oct 18, 2024
2 parents 6ebe6eb + 80115ac commit eab0b2d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
38 changes: 27 additions & 11 deletions kt/basictest.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,23 @@ import (
"github.com/goose-lang/primitive"
"github.com/goose-lang/std"
"github.com/mit-pdos/pav/advrpc"
"github.com/mit-pdos/pav/cryptoffi"
)

func testBasic(servAddr, adtr0Addr, adtr1Addr uint64) {
// start server and auditors.
type setupParams struct {
servAddr uint64
servSigPk cryptoffi.PublicKey
servVrfPk *cryptoffi.VrfPublicKey
adtr0Addr uint64
adtr0Pk cryptoffi.PublicKey
adtr1Addr uint64
adtr1Pk cryptoffi.PublicKey
}

// setup starts server and auditors. it's mainly a logical convenience.
// it consolidates the external parties, letting us more easily describe
// different adversary configs.
func setup(servAddr, adtr0Addr, adtr1Addr uint64) *setupParams {
serv, servSigPk, servVrfPk := newServer()
servRpc := newRpcServer(serv)
servRpc.Serve(servAddr)
Expand All @@ -18,17 +31,20 @@ func testBasic(servAddr, adtr0Addr, adtr1Addr uint64) {
adtr1Rpc := newRpcAuditor(adtr1)
adtr1Rpc.Serve(adtr1Addr)
primitive.Sleep(1_000_000)
return &setupParams{servAddr: servAddr, servSigPk: servSigPk, servVrfPk: servVrfPk, adtr0Addr: adtr0Addr, adtr0Pk: adtr0Pk, adtr1Addr: adtr1Addr, adtr1Pk: adtr1Pk}
}

func testBasic(params *setupParams) {
// alice put.
alice := newClient(aliceUid, servAddr, servSigPk, servVrfPk)
alice := newClient(aliceUid, params.servAddr, params.servSigPk, params.servVrfPk)
pk0 := []byte{3}
ep0, err0 := alice.Put(pk0)
primitive.Assume(!err0.err)

// update auditors.
servCli := advrpc.Dial(servAddr)
adtr0Cli := advrpc.Dial(adtr0Addr)
adtr1Cli := advrpc.Dial(adtr1Addr)
servCli := advrpc.Dial(params.servAddr)
adtr0Cli := advrpc.Dial(params.adtr0Addr)
adtr1Cli := advrpc.Dial(params.adtr1Addr)
upd0, err1 := callServAudit(servCli, 0)
primitive.Assume(!err1)
upd1, err2 := callServAudit(servCli, 1)
Expand All @@ -43,20 +59,20 @@ func testBasic(servAddr, adtr0Addr, adtr1Addr uint64) {
primitive.Assume(!err6)

// bob get.
bob := newClient(bobUid, servAddr, servSigPk, servVrfPk)
bob := newClient(bobUid, params.servAddr, params.servSigPk, params.servVrfPk)
isReg, pk1, ep1, err7 := bob.Get(aliceUid)
primitive.Assume(!err7.err)
// same epoch to avoid timeseries for basic TC.
primitive.Assume(ep0 == ep1)

// alice and bob audit.
err8 := alice.Audit(adtr0Addr, adtr0Pk)
err8 := alice.Audit(params.adtr0Addr, params.adtr0Pk)
primitive.Assume(!err8.err)
err9 := alice.Audit(adtr1Addr, adtr1Pk)
err9 := alice.Audit(params.adtr1Addr, params.adtr1Pk)
primitive.Assume(!err9.err)
err10 := bob.Audit(adtr0Addr, adtr0Pk)
err10 := bob.Audit(params.adtr0Addr, params.adtr0Pk)
primitive.Assume(!err10.err)
err11 := bob.Audit(adtr1Addr, adtr1Pk)
err11 := bob.Audit(params.adtr1Addr, params.adtr1Pk)
primitive.Assume(!err11.err)

// assert keys equal.
Expand Down
5 changes: 3 additions & 2 deletions kt/kt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ func TestAll(t *testing.T) {
}

func TestBasic(t *testing.T) {
serverAddr := makeUniqueAddr()
servAddr := makeUniqueAddr()
adtr0Addr := makeUniqueAddr()
adtr1Addr := makeUniqueAddr()
testBasic(serverAddr, adtr0Addr, adtr1Addr)
p := setup(servAddr, adtr0Addr, adtr1Addr)
testBasic(p)
}

func getFreePort() (port uint64, err error) {
Expand Down
1 change: 1 addition & 0 deletions kt/timeseries.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kt

// TODO: rename to history.
type TimeSeriesEntry struct {
Epoch uint64
TSVal []byte
Expand Down

0 comments on commit eab0b2d

Please sign in to comment.