-
Notifications
You must be signed in to change notification settings - Fork 4
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
Implementation of Commitment Protocol backend for Viaduct 2.0 (Circuit IR) #795
base: master
Are you sure you want to change the base?
Changes from all commits
e8f52ef
cdfda40
6b2da3f
ce97d35
47b2c25
4841963
ed3b1ae
720e8c8
193ed34
f4f3b72
415e91b
dbb7419
914471a
0c396ac
4881cdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
cmake-build-*/ | ||
|
||
# IntelliJ | ||
.idea/ | ||
out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.github.aplcornell.viaduct.backends.commitment | ||
|
||
import com.squareup.kotlinpoet.CodeBlock | ||
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy | ||
import com.squareup.kotlinpoet.TypeName | ||
import com.squareup.kotlinpoet.asTypeName | ||
import io.github.aplcornell.viaduct.circuitcodegeneration.AbstractCodeGenerator | ||
import io.github.aplcornell.viaduct.circuitcodegeneration.Argument | ||
import io.github.aplcornell.viaduct.circuitcodegeneration.CodeGeneratorContext | ||
import io.github.aplcornell.viaduct.circuitcodegeneration.UnsupportedCommunicationException | ||
import io.github.aplcornell.viaduct.circuitcodegeneration.typeTranslator | ||
import io.github.aplcornell.viaduct.runtime.commitment.Committed | ||
import io.github.aplcornell.viaduct.syntax.Protocol | ||
import io.github.aplcornell.viaduct.syntax.types.ValueType | ||
import io.github.aplcornell.viaduct.runtime.commitment.Commitment as CommitmentValue | ||
|
||
/** | ||
* Backend code generator for the commitment protocol for the circuit IR. | ||
* | ||
* Throws an UnsupportedCommunicationException when used in an input program as a computation protocol. | ||
* This is because the commitment protocol is only a storage format and not a computation protocol. | ||
*/ | ||
class CommitmentCircuitCodeGenerator(context: CodeGeneratorContext) : AbstractCodeGenerator(context) { | ||
override fun paramType(protocol: Protocol, sourceType: ValueType): TypeName { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this code belongs under storageType. paramType should be undefined (throw an error). |
||
require(protocol is Commitment) | ||
return when (context.host) { | ||
protocol.cleartextHost -> (Committed::class).asTypeName().parameterizedBy(typeTranslator(sourceType)) | ||
in protocol.hashHosts -> (CommitmentValue::class).asTypeName().parameterizedBy(typeTranslator(sourceType)) | ||
else -> throw IllegalStateException() | ||
Check warning on line 29 in compiler/src/main/kotlin/io/github/aplcornell/viaduct/backends/commitment/CommitmentCircuitCodeGenerator.kt Codecov / codecov/patchcompiler/src/main/kotlin/io/github/aplcornell/viaduct/backends/commitment/CommitmentCircuitCodeGenerator.kt#L29
|
||
} | ||
} | ||
|
||
override fun storageType(protocol: Protocol, sourceType: ValueType): TypeName { | ||
return super.storageType(protocol, sourceType) | ||
Check warning on line 34 in compiler/src/main/kotlin/io/github/aplcornell/viaduct/backends/commitment/CommitmentCircuitCodeGenerator.kt Codecov / codecov/patchcompiler/src/main/kotlin/io/github/aplcornell/viaduct/backends/commitment/CommitmentCircuitCodeGenerator.kt#L34
|
||
} | ||
|
||
override fun import(protocol: Protocol, arguments: List<Argument>): Pair<CodeBlock, List<CodeBlock>> { | ||
adityanathan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (arguments.isEmpty()) { | ||
return Pair(CodeBlock.of(""), emptyList()) | ||
} | ||
throw UnsupportedCommunicationException(arguments.first().protocol, protocol, arguments.first().sourceLocation) | ||
Check warning on line 41 in compiler/src/main/kotlin/io/github/aplcornell/viaduct/backends/commitment/CommitmentCircuitCodeGenerator.kt Codecov / codecov/patchcompiler/src/main/kotlin/io/github/aplcornell/viaduct/backends/commitment/CommitmentCircuitCodeGenerator.kt#L41
|
||
} | ||
|
||
override fun export(protocol: Protocol, arguments: List<Argument>): Pair<CodeBlock, List<CodeBlock>> { | ||
adityanathan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (arguments.isEmpty()) { | ||
return Pair(CodeBlock.of(""), emptyList()) | ||
} | ||
throw UnsupportedCommunicationException(arguments.first().protocol, protocol, arguments.first().sourceLocation) | ||
Check warning on line 48 in compiler/src/main/kotlin/io/github/aplcornell/viaduct/backends/commitment/CommitmentCircuitCodeGenerator.kt Codecov / codecov/patchcompiler/src/main/kotlin/io/github/aplcornell/viaduct/backends/commitment/CommitmentCircuitCodeGenerator.kt#L48
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
host alice | ||
host bob | ||
host chuck | ||
|
||
circuit fun <> move@Local(host = alice)(a: int[]) -> b: int[] { | ||
return a | ||
} | ||
|
||
circuit fun <> move2@Replication(hosts = {bob, chuck})(a: int[]) -> b: int[] { | ||
return a | ||
} | ||
|
||
fun <> main() -> { | ||
val a@Local(host = alice) = alice.input<int[]>() | ||
val c@Commitment(sender = alice, receivers = {bob, chuck}) = move<>(a) | ||
val d@Replication(hosts = {bob, chuck}) = move2<>(c) | ||
val = bob.output<int[]>(d) | ||
val = chuck.output<int[]>(d) | ||
return | ||
} |
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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
host alice | ||
host bob | ||
host chuck | ||
host david | ||
|
||
circuit fun <> move@Local(host = alice)(a: int[]) -> b: int[] { | ||
return a | ||
} | ||
|
||
circuit fun <> move2@Replication(hosts = {bob, david})(a: int[]) -> b: int[] { | ||
return a | ||
} | ||
|
||
fun <> main() -> { | ||
val a@Local(host = alice) = alice.input<int[]>() | ||
val c@Commitment(sender = alice, receivers = {bob, chuck}) = move<>(a) | ||
val d@Replication(hosts = {bob, david}) = move2<>(c) | ||
val = bob.output<int[]>(d) | ||
val = david.output<int[]>(d) | ||
return | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
host alice | ||
host bob | ||
host chuck | ||
|
||
circuit fun <> move@Commitment(sender = alice, receivers = {bob, chuck})() -> {return} | ||
|
||
fun <> main() -> { | ||
val = move<>() | ||
return | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The receivers need to check with each other they received the same values.