Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code examples showing the need for synchronization #344

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/inputs/synchronization/Declassify-alice.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
42
1 change: 1 addition & 0 deletions examples/inputs/synchronization/Declassify-bob.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
43
1 change: 1 addition & 0 deletions examples/inputs/synchronization/PickANumber-alice.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
42
1 change: 1 addition & 0 deletions examples/inputs/synchronization/PickANumber-bob.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
41
1 change: 1 addition & 0 deletions examples/outputs/synchronization/Declassify-alice.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
false
Empty file.
1 change: 1 addition & 0 deletions examples/outputs/synchronization/PickANumber-alice.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
false
1 change: 1 addition & 0 deletions examples/outputs/synchronization/PickANumber-bob.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
false
15 changes: 15 additions & 0 deletions examples/src/main/viaduct/synchronization/Declassify.via
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
host alice : {A & B}
host bob : {B}

fun main() {
let $pick = input int from alice;

let $guess = input int from bob;
let $trusted_guess = endorse $guess from {B};

let $revealed_pick@Replication(hosts = {alice, bob}) = declassify $pick to {A ⊓ B};
let $bob_wins = $revealed_pick == $trusted_guess;

output $bob_wins to alice;
/* output $bob_wins to bob; */
}
16 changes: 16 additions & 0 deletions examples/src/main/viaduct/synchronization/PickANumber.via
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
host alice : {A}
host bob : {B & A<-}

fun main() {
let $pick = input int from alice;
let $trusted_pick = endorse $pick from {A};

let $guess = input int from bob;
let $revealed_guess = declassify $guess to {A ⊓ B};

let $revealed_pick = declassify $trusted_pick to {A ⊓ B};
let $bob_wins = $revealed_pick == $revealed_guess;

output $bob_wins to alice;
output $bob_wins to bob;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.apache.logging.log4j.Level
import org.apache.logging.log4j.core.config.Configurator
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ArgumentsSource
import org.springframework.util.SocketUtils
Expand Down Expand Up @@ -39,6 +40,22 @@ internal class RunExamplesTest {
}
}

/** Convenience function that creates empty input/output files for new test programs. */
@Disabled
@ParameterizedTest
@ArgumentsSource(ViaductProgramProvider::class)
fun createEmptyInputOutputFiles(program: ViaductGeneratedProgram) {
fun createFile(file: File) {
println("Creating $file.")
file.parentFile.mkdirs()
file.createNewFile()
}
program.hosts.forEach { host ->
createFile(inputFile(program, host))
createFile(outputFile(program, host))
}
}

companion object {
@BeforeAll
@JvmStatic
Expand Down