Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
zkvm: remove import/export instructions (#296)
Browse files Browse the repository at this point in the history
* zkvm: remove import/export instructions

* remove import/export log entries

* bump ci
  • Loading branch information
oleganza authored Apr 26, 2019
1 parent 526a751 commit e9e4311
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 123 deletions.
102 changes: 8 additions & 94 deletions zkvm/docs/zkvm-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,6 @@ following instructions:
* [`issue`](#issue)
* [`retire`](#retire)
* [`log`](#log)
* [`import`](#import)
* [`export`](#export)
See the specification of each instruction for the details of which data is stored.
Expand Down Expand Up @@ -623,23 +621,6 @@ Data entry is added using [`log`](#log) instruction.
T.commit("data", data)
```
#### Import entry
Import entry is added using [`import`](#import) instruction.
```
T.commit("import", proof)
```
#### Export entry
Export entry is added using [`export`](#export) instruction.
```
T.commit("export", metadata)
```
### Merkle binary tree
Expand Down Expand Up @@ -927,17 +908,15 @@ Code | Instruction | Stack diagram |
0x15 | [`borrow`](#borrow) | _qty flv_ → _–V +V_ | Modifies [CS](#constraint-system)
0x16 | [`retire`](#retire) | _value_ → ø | Modifies [CS](#constraint-system), [tx log](#transaction-log)
0x17 | [`cloak:m:n`](#cloak) | _widevalues commitments_ → _values_ | Modifies [CS](#constraint-system)
0x18 | [`import`](#import) | _proof qty flv_ → _value_ | Modifies [CS](#constraint-system), [tx log](#transaction-log), [defers point ops](#deferred-point-operations)
0x19 | [`export`](#export) | _value ???_ → ø | Modifies [CS](#constraint-system), [tx log](#transaction-log)
 |   | |
 | [**Contracts**](#contract-instructions) | |
0x1a | [`input`](#input) | _prevoutput_ → _contract_ | Modifies [tx log](#transaction-log)
0x1b | [`output:k`](#output) | _items... pred_ → ø | Modifies [tx log](#transaction-log)
0x1c | [`contract:k`](#contract) | _items... pred_ → _contract_ |
0x1d | [`log`](#log) | _data_ → ø | Modifies [tx log](#transaction-log)
0x1e | [`signtx`](#signtx) | _contract_ → _results..._ | Modifies [deferred verification keys](#transaction-signature)
0x1f | [`call`](#call) |_contract(P) proof prog_ → _results..._ | [Defers point operations](#deferred-point-operations)
0x20 | [`delegate`](#delegate) |_contract prog sig_ → _results..._ | [Defers point operations](#deferred-point-operations)
0x18 | [`input`](#input) | _prevoutput_ → _contract_ | Modifies [tx log](#transaction-log)
0x19 | [`output:k`](#output) | _items... pred_ → ø | Modifies [tx log](#transaction-log)
0x1a | [`contract:k`](#contract) | _items... pred_ → _contract_ |
0x1b | [`log`](#log) | _data_ → ø | Modifies [tx log](#transaction-log)
0x1c | [`signtx`](#signtx) | _contract_ → _results..._ | Modifies [deferred verification keys](#transaction-signature)
0x1d | [`call`](#call) |_contract(P) proof prog_ → _results..._ | [Defers point operations](#deferred-point-operations)
0x1e | [`delegate`](#delegate) |_contract prog sig_ → _results..._ | [Defers point operations](#deferred-point-operations)
— | [`ext`](#ext) | ø → ø | Fails if [extension flag](#vm-state) is not set.
Expand Down Expand Up @@ -1290,71 +1269,6 @@ Merges and splits `m` [wide values](#wide-value-type) into `n` [values](#value-t
Immediate data `m` and `n` are encoded as two [LE32](#le32)s.
#### import
_proof qty flv_ **import** → _value_
1. Pops [variable](#variable-type) `flv` and commits it to the constraint system.
2. Pops [variable](#variable-type) `qty` and commits it to the constraint system.
3. Pops [data](#data-type) `proof`.
4. Creates a [value](#value-type) with variables `qty` and `flv` for quantity and flavor, respectively.
5. Computes the _flavor_ scalar defined by the [predicate](#predicate) `pred` using the following [transcript-based](#transcript) protocol:
```
T = Transcript("ZkVM.import")
T.commit("extflavor", proof.external_flavor_id)
T.commit("extaccount", proof.pegging_account_id)
flavor = T.challenge_scalar("flavor")
```
6. Checks that the `flv` has unblinded commitment to `flavor` by [deferring the point operation](#deferred-point-operations):
```
flv == flavor·B
```
7. Checks that the `qty` has unblinded commitment to `quantity` by [deferring the point operation](#deferred-point-operations):
```
qty == proof.quantity·B
```
8. Adds an [import entry](#import-entry) with `proof` to the [transaction log](#transaction-log).
9. Pushes the imported value to the stack.
Note: the `proof` data contains necessary metadata to check if the value is pegged on the external blockchain.
It is verified when the transaction is applied to the blockchain state.
TBD: definition of the proof data (quantity, asset id, pegging account, identifier of the pegging transaction)
Fails if:
* `flv` or `qty` are not [variable types](#variable-type),
* `proof` is not a [data type](#data-type).
#### export
_metadata value_ **export** → ø
1. Pops [value](#value-type).
2. Pops [data](#data-type) `metadata`.
3. Computes the local flavor based on the pegging metadata:
```
T = Transcript("ZkVM.import")
T.commit("extflavor", metadata.external_flavor_id)
T.commit("extaccount", metadata.pegging_account_id)
flavor = T.challenge_scalar("flavor")
```
4. Adds two constraints to the constraint system using cleartext quantity and flavor in the metadata:
```
value.qty == metadata.qty
value.flv == flavor
```
5. Adds an [export entry](#export-entry) with `metadata` to the [transaction log](#transaction-log).
TBD: definition of the metadata data (quantity, asset id, pegging account, target address/accountid)
Fails if:
* `value` is not a [non-negative value type](#value-type),
* `metadata` is not a [data type](#data-type).
### Contract instructions
Expand Down Expand Up @@ -1878,4 +1792,4 @@ Also, instead of placing bounds on some received value, we now normally use `bor
Thus, neither of these use cases requires `qty` and `flavor`.
### Open questions
None at the moment.
None at the moment.
22 changes: 7 additions & 15 deletions zkvm/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ pub enum Instruction {
Borrow,
Retire,
Cloak(usize, usize), // M inputs, N outputs
Import,
Export,
Input,
Output(usize), // payload count
Contract(usize), // payload count
Expand Down Expand Up @@ -78,18 +76,16 @@ pub enum Opcode {
Borrow = 0x15,
Retire = 0x16,
Cloak = 0x17,
Import = 0x18,
Export = 0x19,
Input = 0x1a,
Output = 0x1b,
Contract = 0x1c,
Log = 0x1d,
Signtx = 0x1e,
Call = 0x1f,
Input = 0x18,
Output = 0x19,
Contract = 0x1a,
Log = 0x1b,
Signtx = 0x1c,
Call = 0x1d,
Delegate = MAX_OPCODE,
}

const MAX_OPCODE: u8 = 0x20;
const MAX_OPCODE: u8 = 0x1e;

impl Opcode {
/// Converts the opcode to `u8`.
Expand Down Expand Up @@ -184,8 +180,6 @@ impl Instruction {
let n = program.read_size()?;
Ok(Instruction::Cloak(m, n))
}
Opcode::Import => Ok(Instruction::Import),
Opcode::Export => Ok(Instruction::Export),
Opcode::Input => Ok(Instruction::Input),
Opcode::Output => {
let k = program.read_size()?;
Expand Down Expand Up @@ -249,8 +243,6 @@ impl Instruction {
encoding::write_u32(*m as u32, program);
encoding::write_u32(*n as u32, program);
}
Instruction::Import => write(Opcode::Import),
Instruction::Export => write(Opcode::Export),
Instruction::Input => write(Opcode::Input),
Instruction::Output(k) => {
write(Opcode::Output);
Expand Down
2 changes: 0 additions & 2 deletions zkvm/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ impl Program {
def_op!(drop, Drop);
def_op!(dup, Dup, usize);
def_op!(eq, Eq);
def_op!(export, Export);
def_op!(expr, Expr);
def_op!(import, Import);
def_op!(input, Input);
def_op!(issue, Issue);
def_op!(log, Log);
Expand Down
10 changes: 0 additions & 10 deletions zkvm/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ pub enum TxEntry {
Input(ContractID),
Output(Contract),
Data(Vec<u8>),
Import, // TBD: parameters
Export, // TBD: parameters
}

/// Header metadata for the transaction
Expand Down Expand Up @@ -249,14 +247,6 @@ impl MerkleItem for TxEntry {
TxEntry::Data(data) => {
t.commit_bytes(b"data", data);
}
TxEntry::Import => {
// TBD: commit parameters
unimplemented!()
}
TxEntry::Export => {
// TBD: commit parameters
unimplemented!()
}
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions zkvm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ where
Instruction::Borrow => self.borrow()?,
Instruction::Retire => self.retire()?,
Instruction::Cloak(m, n) => self.cloak(m, n)?,
Instruction::Import => unimplemented!(),
Instruction::Export => unimplemented!(),
Instruction::Input => self.input()?,
Instruction::Output(k) => self.output(k)?,
Instruction::Contract(k) => self.contract(k)?,
Expand Down

0 comments on commit e9e4311

Please sign in to comment.