diff --git a/zkvm/docs/zkvm-spec.md b/zkvm/docs/zkvm-spec.md index bfcc5c76a..9645346a3 100644 --- a/zkvm/docs/zkvm-spec.md +++ b/zkvm/docs/zkvm-spec.md @@ -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. @@ -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 @@ -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. @@ -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 @@ -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. \ No newline at end of file +None at the moment. diff --git a/zkvm/src/ops.rs b/zkvm/src/ops.rs index ee2ae70bc..3e6fc0e09 100644 --- a/zkvm/src/ops.rs +++ b/zkvm/src/ops.rs @@ -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 @@ -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`. @@ -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()?; @@ -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); diff --git a/zkvm/src/program.rs b/zkvm/src/program.rs index 7c5371682..b7bc799b9 100644 --- a/zkvm/src/program.rs +++ b/zkvm/src/program.rs @@ -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); diff --git a/zkvm/src/tx.rs b/zkvm/src/tx.rs index 417d1c783..083f66d6b 100644 --- a/zkvm/src/tx.rs +++ b/zkvm/src/tx.rs @@ -29,8 +29,6 @@ pub enum TxEntry { Input(ContractID), Output(Contract), Data(Vec), - Import, // TBD: parameters - Export, // TBD: parameters } /// Header metadata for the transaction @@ -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!() - } } } } diff --git a/zkvm/src/vm.rs b/zkvm/src/vm.rs index 70adda254..e1d036707 100644 --- a/zkvm/src/vm.rs +++ b/zkvm/src/vm.rs @@ -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)?,