Skip to content

Commit

Permalink
Merge branch 'tari-script' into sw_refactorr_utxo_scanner_db
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler authored Jul 4, 2021
2 parents e738b3b + 2c9f699 commit d76768d
Show file tree
Hide file tree
Showing 200 changed files with 2,300 additions and 6,708 deletions.
288 changes: 214 additions & 74 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ and performing mining:
2021-02-26 11:28:19.687855700 [tari_mining_node::miner] INFO Mining thread 2 stopped
2021-02-26 11:28:19.688251200 [tari_mining_node] INFO Miner 2 found block header BlockHeader { hash: [...], version: 1,
height: 8493, prev_hash: [...], timestamp: Some(Timestamp { seconds: 1614331698, nanos: 0 }), output_mr: [...],
range_proof_mr: [...], total_kernel_offset: [...], nonce: 8415580256943728281, pow: Some(ProofOfWork { pow_algo: 2,
witness_mr: [...], total_kernel_offset: [...], nonce: 8415580256943728281, pow: Some(ProofOfWork { pow_algo: 2,
pow_data: [] }), kernel_mmr_size: 24983, output_mmr_size: 125474 } with difficulty 7316856839
```

Expand Down
151 changes: 109 additions & 42 deletions RFC/src/Glossary.md

Large diffs are not rendered by default.

180 changes: 93 additions & 87 deletions RFC/src/RFC-0201_TariScript.md

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions RFC/src/RFC-0202_TariScriptOpcodes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# RFC-0202/TariScriptOpcodes

## Tari Script Opcodes
## TariScript Opcodes

![status: draft](theme/images/status-draft.svg)

Expand Down Expand Up @@ -61,11 +61,11 @@ examples and applicaitons.
## Introduction


## Tari Script semantics
## TariScript semantics

The proposal for TariScript is straightforward. It is based on Bitcoin script and inherits most of its ideas.

The main properties of Tari script are
The main properties of [TariScript] are

* The scripting language is stack-based. At redeem time, the UTXO spender must supply an input stack. The script runs by
operating on the stack contents.
Expand All @@ -74,7 +74,7 @@ The main properties of Tari script are
on the stack. The script fails if the stack is empty, or contains more than one element, or aborts early.
* It is not Turing complete, so there are no loops or timing functions.
* The opcodes enforce type safety. e.g. A public key cannot be added to an integer scalar. Errors of this kind MUST cause
the script to fail. The Rust implementation of Tari Script automatically applies the type safety rules.
the script to fail. The Rust implementation of [TariScript] automatically applies the type safety rules.

### Failure modes

Expand Down Expand Up @@ -112,7 +112,7 @@ The full list of [Error codes](#error-codes) is given below.

## Opcodes

Tari Script opcodes range from 0 to 255 and are represented as a single unsigned byte. The opcode set is
[TariScript] opcodes range from 0 to 255 and are represented as a single unsigned byte. The opcode set is
limited to allow for the applications specified in this RFC, but can be expanded in the future.

### Block height checks
Expand Down Expand Up @@ -348,7 +348,7 @@ If `ELSE` is encountered, instructions are executed until `ENDIF` is reached.

## Serialisation

Tari Script and the execution stack are serialised into byte strings using a simple linear parser. Since all opcodes are
TariScript and the execution stack are serialised into byte strings using a simple linear parser. Since all opcodes are
a single byte, it's very easy to read and write script byte strings. If an opcode has a parameter associated with it,
e.g. `PushHash` then it is equally known how many bytes following the opcode will contain the parameter.

Expand Down Expand Up @@ -570,3 +570,5 @@ or Bob can spend the output.

Thanks to [@philipr-za](https://github.com/philipr-za) and [@SWvheerden](https://github.com/SWvheerden) for their input
and contributions to this RFC.

[TariScript]: Glossary.md#tariscript
2 changes: 1 addition & 1 deletion applications/tari_app_grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2018"
tari_common_types = { version = "^0.8", path = "../../base_layer/common_types"}
tari_core = { path = "../../base_layer/core"}
tari_wallet = { path = "../../base_layer/wallet"}
tari_crypto = { git = "ssh://[email protected]/tari-project/tari-crypto.git", branch = "main" }
tari_crypto = { git = "ssh://[email protected]/tari-project/tari-crypto.git", branch = "main" } #switch back to official after merge
tari_comms = { path = "../../comms"}

chrono = "0.4.6"
Expand Down
38 changes: 22 additions & 16 deletions applications/tari_app_grpc/proto/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,25 @@ message BlockHeader {
// This is the UTXO merkle root of the outputs
// This is calculated as Hash (txo MMR root || roaring bitmap hash of UTXO indices)
bytes output_mr = 6;
// This is the MMR root of the range proofs
bytes range_proof_mr = 7;
// This is the MMR root of the the output witness data
bytes witness_mr = 7;
// This is the MMR root of the kernels
bytes kernel_mr = 8;
// This is the Merkle root of the inputs in this block
bytes input_mr = 9;
// Total accumulated sum of kernel offsets since genesis block. We can derive the kernel offset sum for *this*
// block from the total kernel offset of the previous block header.
bytes total_kernel_offset = 9;
bytes total_kernel_offset = 10;
// Nonce increment used to mine this block.
uint64 nonce = 10;
uint64 nonce = 11;
// Proof of work metadata
ProofOfWork pow = 11;
ProofOfWork pow = 12;
// Kernel MMR size
uint64 kernel_mmr_size = 12;
uint64 kernel_mmr_size = 13;
// Output MMR size
uint64 output_mmr_size = 13;
uint64 output_mmr_size = 14;
// Sum of script offsets for all kernels in this block.
bytes total_script_offset = 14;
bytes total_script_offset = 15;
}

// Metadata required for validating the Proof of Work calculation
Expand Down Expand Up @@ -102,7 +104,7 @@ message HistoricalBlock {
}


// The NewBlockHeaderTemplate is used for the construction of a new mineable block. It contains all the metadata for the block that the Base Node is able to complete on behalf of a Miner.
// The NewBlockHeaderTemplate is used for the construction of a new mine-able block. It contains all the metadata for the block that the Base Node is able to complete on behalf of a Miner.
message NewBlockHeaderTemplate {
// Version of the block
uint32 version = 1;
Expand Down Expand Up @@ -164,11 +166,9 @@ message TransactionInput {
bytes script = 4;
// The script input data, if any
bytes input_data = 5;
// The block height that the UTXO was mined
uint64 height = 6;
// A signature with k_s, signing the script, input data, and mined height
Signature script_signature = 7;
// The offset pubkey, K_O
ComSignature script_signature = 7;
// The offset public key, K_O
bytes script_offset_public_key = 8;
}

Expand All @@ -186,7 +186,7 @@ message TransactionOutput {
bytes hash = 4;
// Tari script serialised script
bytes script = 5;
// Tari script offset pubkey, K_O
// Tari script offset public key, K_O
bytes script_offset_public_key = 6;
// UTXO signature with the script offset private key, k_O
Signature sender_metadata_signature = 7;
Expand Down Expand Up @@ -227,6 +227,14 @@ message Signature {
bytes signature = 2;
}

// Define the explicit ComSignature implementation for the Tari base layer. A different signature scheme can be
// employed by redefining this type.
message ComSignature {
bytes public_nonce_commitment = 1;
bytes signature_u = 2;
bytes signature_v = 3;
}

/// Consensus Constants response
message ConsensusConstants {
/// The min height maturity a coinbase utxo must have
Expand Down Expand Up @@ -308,8 +316,6 @@ message UnblindedOutput {
bytes script = 4;
// Tari script input data for spending
bytes input_data = 5;
// The block height that the UTXO was mined
uint64 height = 6;
// Tari script private key
bytes script_private_key = 7;
// Tari script offset pubkey, K_O
Expand Down
Loading

0 comments on commit d76768d

Please sign in to comment.