Skip to content

Commit

Permalink
Added commitment2 test and modified cleartext code generator to throw…
Browse files Browse the repository at this point in the history
… appropriate exceptions for commitments
  • Loading branch information
adityanathan committed Sep 2, 2024
1 parent 193ed34 commit f4f3b72
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,15 @@ class CleartextCircuitCodeGenerator(context: CodeGeneratorContext) : AbstractCod
builder: CodeBlock.Builder,
): CodeBlock {
require(context.host in source.hosts + target.hosts)
require(source is Local && source.hosts.size == 1 && source.host in source.hosts)
if (source !is Local) {
throw UnsupportedCommunicationException(source, target, argument.sourceLocation)
}
require(source.hosts.size == 1 && source.host in source.hosts)
require(target is CommitmentProtocol)
if (target.cleartextHost != source.host || target.cleartextHost in target.hashHosts) {
throw UnsupportedCommunicationException(source, target, argument.sourceLocation)
}

val argType = kotlinType(argument.type.shape, typeTranslator(argument.type.elementType.value))
val sendingHost = target.cleartextHost
val receivingHosts = target.hashHosts
Expand Down Expand Up @@ -183,11 +187,14 @@ class CleartextCircuitCodeGenerator(context: CodeGeneratorContext) : AbstractCod
builder: CodeBlock.Builder,
): CodeBlock {
require(source is CommitmentProtocol)
require(target is Replication)
if (target !is Cleartext) {
throw UnsupportedCommunicationException(source, target, argument.sourceLocation)
}
require(context.host in source.hosts + target.hosts)
if (source.hashHosts != target.hosts || source.cleartextHost in source.hashHosts) {
throw UnsupportedCommunicationException(source, target, argument.sourceLocation)
}

val argType = kotlinType(argument.type.shape, typeTranslator(argument.type.elementType.value))
val sendingHost = source.cleartextHost
val receivingHosts = target.hosts
Expand Down
18 changes: 18 additions & 0 deletions compiler/tests/should-pass/circuit/cleartext/Commitment2.circuit
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
host alice
host bob

circuit fun <> move@Local(host = alice)(a: int[]) -> b: int[] {
return a
}

circuit fun <> move2@Local(host = bob)(a: int[]) -> b: int[] {
return a
}

fun <> main() -> {
val a@Local(host = alice) = alice.input<int[]>()
val c@Commitment(sender = alice, receivers = {bob}) = move<>(a)
val d@Local(host = bob) = move2<>(c)
val = bob.output<int[]>(d)
return
}
1 change: 1 addition & 0 deletions examples/inputs/circuit/cleartext/Commitment2-alice.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5
Empty file.
Empty file.
1 change: 1 addition & 0 deletions examples/outputs/circuit/cleartext/Commitment2-bob.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5

0 comments on commit f4f3b72

Please sign in to comment.