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

zkvm: rename mintime to locktime, remove maxtime #467

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion accounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ and then be able to obtain a utxo proof in order to be able to spend the funds.

Confirms payment details.
Selects utxos to cover the payment amount
Forms a transaction with maxtime=min(sender's exptime, receiver exptime).
Forms a transaction.
Send back the ReceiverReply that allows constructing a contract ID.

ReceiverReply ------->
Expand Down
3 changes: 1 addition & 2 deletions accounts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ fn basic_accounts_test() {
});
let header = TxHeader {
version: 1u64,
mintime_ms: 0u64,
maxtime_ms: u64::max_value(),
locktime_ms: 0u64,
};

// Build the UnverifiedTx
Expand Down
3 changes: 1 addition & 2 deletions blockchain/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,7 @@ mod tests {
tx: Tx {
header: TxHeader {
version: 9,
mintime_ms: 10,
maxtime_ms: 11,
locktime_ms: 10,
},
program: vec![12; 34],
signature: Signature {
Expand Down
3 changes: 1 addition & 2 deletions blockchain/src/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ impl Mempool {
self.entries.len()
}

/// Updates timestamp and re-applies txs to filter out the outdated ones.
/// Updates timestamp.
pub fn update_timestamp(&mut self, timestamp_ms: u64) {
self.timestamp_ms = timestamp_ms;
self.update_mempool(None);
}

/// Updates the state of the blockchain and removes conflicting transactions.
Expand Down
3 changes: 0 additions & 3 deletions blockchain/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,6 @@ impl<D: Delegate> Node<D> {
/// Obviously, a multi-party signing, SCP or any other decentralized consensus algorithm
/// would have a different API.
pub fn create_block(&mut self, timestamp_ms: u64, signing_key: SigningKey) {
// Note: we don't need to do that if all tx.maxtime's are 1-2 blocks away.
// TODO: rethink whether we actually need the maxtime at all. It is not needed for relative timelocks in paychans,
// and it is not helping with clearing up the mempool spam.
let timestamp_ms = core::cmp::max(timestamp_ms, self.delegate.tip().0.timestamp_ms);
self.mempool.update_timestamp(timestamp_ms);

Expand Down
6 changes: 1 addition & 5 deletions blockchain/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,7 @@ pub fn check_tx_header(
block_version: u64,
) -> Result<(), BlockchainError> {
check(
timestamp_ms >= tx_header.mintime_ms,
BlockchainError::BadTxTimestamp,
)?;
check(
timestamp_ms <= tx_header.maxtime_ms,
timestamp_ms >= tx_header.locktime_ms,
BlockchainError::BadTxTimestamp,
)?;
if block_version == 1 {
Expand Down
3 changes: 1 addition & 2 deletions blockchain/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ fn dummy_tx(utxo: UTXO, bp_gens: &BulletproofGens) -> (BlockTx, UTXO) {
});
let header = TxHeader {
version: 1u64,
mintime_ms: 0u64,
maxtime_ms: u64::max_value(),
locktime_ms: 0u64,
};
let utx = Prover::build_tx(program, header, &bp_gens).unwrap();

Expand Down
6 changes: 2 additions & 4 deletions demo/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,7 @@ impl Wallet {
});
let header = zkvm::TxHeader {
version: 1u64,
mintime_ms: 0u64,
maxtime_ms: u64::max_value(),
locktime_ms: 0u64,
};

// Build the UnverifiedTx
Expand Down Expand Up @@ -531,8 +530,7 @@ impl Wallet {
});
let header = zkvm::TxHeader {
version: 1u64,
mintime_ms: 0u64,
maxtime_ms: u64::max_value(),
locktime_ms: 0u64,
};

// Build the UnverifiedTx
Expand Down
2 changes: 1 addition & 1 deletion demo/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function highlightZkvmOpcodes() {
$(".highlight-zkvm").html(function(){
var text = $(this).html();
text = " " + text + " ";
text = text.replace(/(\W)(push|drop|dup:\d+|roll:\d+|const|var|alloc|mintime|maxtime|expr|neg|add|mul|eq|range|and|or|not|verify|unblind|issue|borrow|retire|cloak:\d+:\d+|input|output:\d+|contract:\d+|log|call|signtx|signid)/mg,
text = text.replace(/(\W)(push|drop|dup:\d+|roll:\d+|const|var|alloc|locktime|expr|neg|add|mul|eq|range|and|or|not|verify|unblind|issue|borrow|retire|cloak:\d+:\d+|input|output:\d+|contract:\d+|log|call|signtx|signid)/mg,
"$1<span class=\"zkvm-op\">$2</span>");
return text;
})
Expand Down
2 changes: 1 addition & 1 deletion demo/templates/network/block_show.html.tera
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
&nbsp;
<strong>Version:</strong> {{tx.header.version}}
&nbsp;
<strong>Time bounds:</strong> [{{tx.header.mintime_ms}}; {{tx.header.maxtime_ms}}]
<strong>Lock time:</strong> {{tx.header.locktime_ms}}
</code>
</td>
</tr>
Expand Down
4 changes: 2 additions & 2 deletions demo/templates/nodes/show.html.tera
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
&nbsp;
<strong>Version:</strong> {{tx.header.version}}
&nbsp;
<strong>Time bounds:</strong> [{{tx.header.mintime_ms}}; {{tx.header.maxtime_ms}}]
<strong>Lock time:</strong> {{tx.header.locktime_ms}}
</code>
</td>
</tr>
Expand Down Expand Up @@ -202,7 +202,7 @@
&nbsp;
<strong>Version:</strong> {{tx.header.version}}
&nbsp;
<strong>Time bounds:</strong> [{{tx.header.mintime_ms}}; {{tx.header.maxtime_ms}}]
<strong>Lock time:</strong> {{tx.header.locktime_ms}}
</code>
</td>
</tr>
Expand Down
3 changes: 1 addition & 2 deletions token/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ mod tests {
let bp_gens = BulletproofGens::new(256, 1);
let header = TxHeader {
version: 0u64,
mintime_ms: 0u64,
maxtime_ms: 0u64,
locktime_ms: 0u64,
};
// TBD: figure out better + more robust signing mechanism
let gens = PedersenGens::default();
Expand Down
2 changes: 1 addition & 1 deletion zkvm/docs/zkvm-blockchain.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ Outputs:
Procedure:
1. Let `txresults` be an empty list of tuples.
2. For each transaction `tx` in `txs`:
1. Verify `tx.mintime_ms <= timestamp_ms <= tx.maxtime_ms`.
1. Verify `tx.locktime_ms <= timestamp_ms`.
2. If `version == 1`, verify `tx.version == 1`.
3. [Execute](zkvm-spec.md#vm-execution) `tx` to produce transaction log `txlog`.
4. Compute transaction ID `txid` from the [header entry](zkvm-spec.md#header-entry) of `tx` and from `txlog`.
Expand Down
99 changes: 45 additions & 54 deletions zkvm/docs/zkvm-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ZkVM defines a procedural representation for blockchain transactions and the rul
* [Base points](#base-points)
* [Pedersen commitment](#pedersen-commitment)
* [Verification key](#verification-key)
* [Time bounds](#time-bounds)
* [Lock time](#lock-time)
* [Contract ID](#contract-id)
* [Anchor](#anchor)
* [Transcript](#transcript)
Expand Down Expand Up @@ -119,7 +119,7 @@ using [`output`](#output) and [`input`](#input) instructions.
Custom logic is represented via programmable [**constraints**](#constraint-type)
applied to [**variables**](#variable-type) and [**expressions**](#expression-type)
(linear combinations of variables). Variables represent quantities and flavors of values,
[time bounds](#time-bounds) and user-defined secret parameters. All constraints are arranged in
[lock time](#lock-time) and user-defined secret parameters. All constraints are arranged in
a single [constraint system](#constraint-system) which is proven to be satisfied after the VM
has finished execution.

Expand Down Expand Up @@ -328,7 +328,7 @@ Used to encode lengths of [strings](#string-type), sizes of [contract payloads](
### LE64

A non-negative 64-bit integer encoded using little-endian convention.
Used to encode [value quantities](#value-type) and [timestamps](#time-bounds).
Used to encode [value quantities](#value-type) and [locktime](#lock-time).


### Scalar
Expand Down Expand Up @@ -392,13 +392,14 @@ using the primary [base point](#base-points) `B`: `P = x·B`.
Verification keys are used to construct [predicates](#predicate) and verify [signatures](#transaction-signature).


### Time bounds
### Lock time

Each transaction is explicitly bound to a range of _minimum_ and _maximum_ time.
Each bound is in _milliseconds_ since the Unix epoch: 00:00:00 on 1 Jan 1970 (UTC),
represented by an unsigned 64-bit integer.
Time bounds are available in the transaction as [expressions](#expression-type) provided by the instructions
[`mintime`](#mintime) and [`maxtime`](#maxtime).
Each transaction is explicitly bounded by a _minimum timestamp_, called _lock time_.
The timestamp is defined in _milliseconds_ since the Unix epoch: 00:00:00 on 1 Jan 1970 (UTC),
encoded as an little-endian unsigned 64-bit integer.

Lock time is available in the transaction as [expression](#expression-type) provided by the instruction
[`locktime`](#locktime).


### Contract ID
Expand Down Expand Up @@ -563,7 +564,7 @@ Transaction is a structure that contains all data and logic
required to produce a unique [transaction ID](#transaction-id):

* Version (uint64)
* [Time bounds](#time-bounds) (pair of [LE64](#le64)s)
* [Lock time](#lock-time)
* [Program](#program-type)
* [Transaction signature](#transaction-signature) (64 bytes)
* [Constraint system proof](#constraint-system-proof) (variable-length array of points and scalars)
Expand Down Expand Up @@ -603,12 +604,11 @@ Entries are committed to the [transcript](#transcript) using the following schem

#### Header entry

Header commits the transaction version and [time bounds](#time-bounds) using the [LE64](#le64) encoding.
Header commits the transaction version and [lock time](#lock-time) using the [LE64](#le64) encoding.

```
T.append("tx.version", LE64(version))
T.append("tx.mintime", LE64(mintime))
T.append("tx.maxtime", LE64(maxtime))
T.append("tx.locktime", LE64(locktime))
```

#### Input entry
Expand Down Expand Up @@ -804,7 +804,7 @@ The ZkVM state consists of the static attributes and the state machine attribute

1. [Transaction](#transaction):
* `version`
* `mintime` and `maxtime`
* `locktime`
* `program`
* `tx_signature`
* `cs_proof`
Expand Down Expand Up @@ -939,36 +939,35 @@ Code | Instruction | Stack diagram |
0x05 | [`const`](#var) | _scalar_ → _expr_ |
0x06 | [`var`](#var) | _point_ → _var_ | Adds an external variable to [CS](#constraint-system)
0x07 | [`alloc`](#alloc) | ø → _expr_ | Allocates a low-level variable in [CS](#constraint-system)
0x08 | [`mintime`](#mintime) | ø → _expr_ |
0x09 | [`maxtime`](#maxtime) | ø → _expr_ |
0x0a | [`expr`](#expr) | _var_ → _expr_ | Allocates a variable in [CS](#constraint-system)
0x0b | [`neg`](#neg) | _expr1_ → _expr2_ |
0x0c | [`add`](#add) | _expr1 expr2_ → _expr3_ |
0x0d | [`mul`](#mul) | _expr1 expr2_ → _expr3_ | Potentially adds multiplier in [CS](#constraint-system)
0x0e | [`eq`](#eq) | _expr1 expr2_ → _constraint_ |
0x0f | [`range`](#range) | _expr_ → _expr_ | Modifies [CS](#constraint-system)
0x10 | [`and`](#and) | _constr1 constr2_ → _constr3_ |
0x11 | [`or`](#or) | _constr1 constr2_ → _constr3_ |
0x12 | [`not`](#not) | _constr1_ → _constr2_ | Modifies [CS](#constraint-system)
0x13 | [`verify`](#verify) | _constraint_ → ø | Modifies [CS](#constraint-system)
0x14 | [`unblind`](#unblind) | _V v_ → _V_ | [Defers point ops](#deferred-point-operations)
0x08 | [`locktime`](#locktime) | ø → _expr_ |
0x09 | [`expr`](#expr) | _var_ → _expr_ | Allocates a variable in [CS](#constraint-system)
0x0a | [`neg`](#neg) | _expr1_ → _expr2_ |
0x0b | [`add`](#add) | _expr1 expr2_ → _expr3_ |
0x0c | [`mul`](#mul) | _expr1 expr2_ → _expr3_ | Potentially adds multiplier in [CS](#constraint-system)
0x0d | [`eq`](#eq) | _expr1 expr2_ → _constraint_ |
0x0e | [`range`](#range) | _expr_ → _expr_ | Modifies [CS](#constraint-system)
0x0f | [`and`](#and) | _constr1 constr2_ → _constr3_ |
0x10 | [`or`](#or) | _constr1 constr2_ → _constr3_ |
0x11 | [`not`](#not) | _constr1_ → _constr2_ | Modifies [CS](#constraint-system)
0x12 | [`verify`](#verify) | _constraint_ → ø | Modifies [CS](#constraint-system)
0x13 | [`unblind`](#unblind) | _V v_ → _V_ | [Defers point ops](#deferred-point-operations)
 |   | |
 | [**Values**](#value-instructions) | |
0x15 | [`issue`](#issue) | _qty flv data pred_ → _contract_ | Modifies [CS](#constraint-system), [tx log](#transaction-log), [defers point ops](#deferred-point-operations)
0x16 | [`borrow`](#borrow) | _qty flv_ → _–V +V_ | Modifies [CS](#constraint-system)
0x17 | [`retire`](#retire) | _value_ → ø | Modifies [CS](#constraint-system), [tx log](#transaction-log)
0x18 | [`cloak:m:n`](#cloak) | _widevalues commitments_ → _values_ | Modifies [CS](#constraint-system)
0x19 | [`fee`](#fee) | _qty_ → _widevalue_ | Modifies [CS](#constraint-system), [tx log](#transaction-log)
0x14 | [`issue`](#issue) | _qty flv data pred_ → _contract_ | Modifies [CS](#constraint-system), [tx log](#transaction-log), [defers point ops](#deferred-point-operations)
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 | [`fee`](#fee) | _qty_ → _widevalue_ | 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 | [`call`](#call) |_contract(P) proof prog_ → _results..._ | [Defers point operations](#deferred-point-operations)
0x1f | [`signtx`](#signtx) | _contract_ → _results..._ | Modifies [deferred verification keys](#transaction-signature)
0x20 | [`signid`](#signid) |_contract prog sig_ → _results..._ | [Defers point operations](#deferred-point-operations)
0x21 | [`signtag`](#signtag) |_contract prog sig_ → _results..._ | [Defers point operations](#deferred-point-operations)
0x19 | [`input`](#input) | _prevoutput_ → _contract_ | Modifies [tx log](#transaction-log)
0x1a | [`output:k`](#output) | _items... pred_ → ø | Modifies [tx log](#transaction-log)
0x1b | [`contract:k`](#contract) | _items... pred_ → _contract_ |
0x1c | [`log`](#log) | _data_ → ø | Modifies [tx log](#transaction-log)
0x1d | [`call`](#call) |_contract(P) proof prog_ → _results..._ | [Defers point operations](#deferred-point-operations)
0x1e | [`signtx`](#signtx) | _contract_ → _results..._ | Modifies [deferred verification keys](#transaction-signature)
0x1f | [`signid`](#signid) |_contract prog sig_ → _results..._ | [Defers point operations](#deferred-point-operations)
0x20 | [`signtag`](#signtag) |_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 @@ -1056,21 +1055,13 @@ Fails if `P` is not a valid [point](#point).
This is different from [`var`](#var): the variable created by `alloc` is _not_ represented by an individual Pedersen commitment and therefore can be chosen freely when the transaction is constructed.


#### mintime

**mintime** → _expr_

Pushes an [expression](#expression-type) `expr` corresponding to the [minimum time bound](#time-bounds) of the transaction.

The one-term expression represents time bound as a weight on the R1CS constant `1` (see [`const`](#const)).

#### maxtime
#### locktime

**maxtime** → _expr_
**locktime** → _expr_

Pushes an [expression](#expression-type) `expr` corresponding to the [maximum time bound](#time-bounds) of the transaction.
Pushes an [expression](#expression-type) `expr` corresponding to the [lock time](#lock-time) of the transaction.

The one-term expression represents time bound as a weight on the R1CS constant `1` (see [`const`](#const)).
The one-term expression represents timestamp as a weight on the R1CS constant `1` (see [`const`](#const)).

#### expr

Expand Down Expand Up @@ -1539,7 +1530,7 @@ A [Transaction](#transaction) is serialized as follows:

```
SerializedTx = TxHeader || LE32(len(Program)) || Program || Signature || Proof
TxHeader = LE64(version) || LE64(mintime) || LE64(maxtime)
TxHeader = LE64(version) || LE64(locktime)
Program = <len(Program) bytes>
Signature = <64 bytes>
Proof = <14·32 + len(InnerProductProof) bytes>
Expand Down Expand Up @@ -1695,7 +1686,7 @@ To _initiate_ a force-close, the program `P1` does:

To construct such program `P1`, users first agree on the final distribution of balances via the program `P2`.

The final-distribution program `P2`:1. Checks that `tx.mintime >= exptime` (can be done via `range:24(tx.mintime - exptime)` which gives 6-month resolution for the expiration time)
The final-distribution program `P2`:1. Checks that `tx.locktime >= exptime` (can be done via `range(tx.locktime - exptime)`)
2. Creates `borrow`/`output` combinations for each party with hard-coded predicate for each output.
3. Leaves the payload value and negatives from `borrow` on the stack to be consumed by the `cloak` instruction.

Expand Down
Loading