From 80115ace06b9e97d90edef198db8938e3a8e4c42 Mon Sep 17 00:00:00 2001 From: Sanjit Bhat Date: Fri, 18 Oct 2024 14:35:20 -0400 Subject: [PATCH] separate out the setup code so that it's logically easier to reason about the different adversarial setup modes --- kt/basictest.go | 38 +++++++++++++++++++++++++++----------- kt/kt_test.go | 5 +++-- kt/timeseries.go | 1 + 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/kt/basictest.go b/kt/basictest.go index d60564a..f09e315 100644 --- a/kt/basictest.go +++ b/kt/basictest.go @@ -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) @@ -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) @@ -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. diff --git a/kt/kt_test.go b/kt/kt_test.go index c11a5c1..d5661ab 100644 --- a/kt/kt_test.go +++ b/kt/kt_test.go @@ -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) { diff --git a/kt/timeseries.go b/kt/timeseries.go index f9e36c7..d6fa312 100644 --- a/kt/timeseries.go +++ b/kt/timeseries.go @@ -1,5 +1,6 @@ package kt +// TODO: rename to history. type TimeSeriesEntry struct { Epoch uint64 TSVal []byte