Ver Fonte

doc/spec/contract: deployooor contract spec added

skoupidi há 9 meses atrás
pai
commit
b20a093cc2

+ 6 - 3
doc/src/SUMMARY.md

@@ -89,13 +89,16 @@
 - [Concepts](spec/concepts.md)
 - [Cryptographic Schemes](spec/crypto-schemes.md)
 - [Contracts]()
+  - [Money](spec/contract/money/money.md)
+    - [Model](spec/contract/money/model.md)
+    - [Scheme](spec/contract/money/scheme.md)
   - [DAO](spec/contract/dao/dao.md)
     - [Concepts](spec/contract/dao/concepts.md)
     - [Model](spec/contract/dao/model.md)
     - [Scheme](spec/contract/dao/scheme.md)
-  - [Money](spec/contract/money/money.md)
-    - [Model](spec/contract/money/model.md)
-    - [Scheme](spec/contract/money/scheme.md)
+  - [Deployooor](spec/contract/deploy/deploy.md)
+    - [Concepts](spec/contract/deploy/concepts.md)
+    - [Scheme](spec/contract/deploy/scheme.md)
   - [Vesting](spec/contract/vesting/vesting.md)
 
 # P2P API Tutorial

+ 31 - 0
doc/src/spec/contract/deploy/concepts.md

@@ -0,0 +1,31 @@
+# Concepts
+
+The smart contract deployment process consists of two steps that are
+outlined below:
+
+* **Deploy:** smart contract is initialized on the blockchain.
+* **Lock:** smart contract is finalized and can't be modified
+  further.
+
+## Deploy
+
+User creates a new smart contract and posts it on chain. The provided
+`WASM` bincode will initialize all the database trees required by the
+smart contract. The contract state definition consinst of the current
+contract `WASM` bincode and its database opened trees.
+
+The smart contract state definition can be updated, as long as its
+unlocked.
+
+### Smart Contract Status
+
+* *Unlocked*: the smart contract state definition can be updated.
+* *Locked*: the smart contract is finalized and no more changes are
+   allowed.
+
+## Lock
+
+User can finalize their smart contract state definition on chain,
+locking down the contract, preventing further state changes. This
+action is irreversible and the smart contract state definitions cannot
+be modified afterwards.

+ 13 - 0
doc/src/spec/contract/deploy/deploy.md

@@ -0,0 +1,13 @@
+# Deployooor
+
+## Abstract
+
+This contract enables deployment and management of custom smart
+contracts on chain. Users can create an authority to control the smart
+contract and deploy their custom `WASM` bincodes. Additionally, they
+can update their code or lock the contract so its code is final and
+can't be modified further.
+
+- [Concepts](concepts.md)
+- [Scheme](scheme.md)
+

+ 61 - 0
doc/src/spec/contract/deploy/scheme.md

@@ -0,0 +1,61 @@
+# Scheme
+
+Let $ℙₚ$ be defined as in the section [Pallas and Vesta](../../crypto-schemes.md#pallas-and-vesta).
+
+## Deploy
+
+This function initializes a smart contract deployment.
+
+* Wallet builder: `src/contract/deployooor/src/client/deploy_v1.rs`
+* WASM VM code: `src/contract/deployooor/src/entrypoint/deploy_v1.rs`
+
+### Function Params
+
+Define the deploy params
+$$ \begin{aligned}
+  \t{Params}_\t{Deploy}.WASM &∈ \t𝔹^* \\
+  \t{Params}_\t{Deploy}.PK &∈ ℙₚ \\
+  \t{Params}_\t{Deploy}.IX &∈ 𝔹^* \\
+\end{aligned} $$
+
+```rust
+{{#include ../../../../../src/sdk/src/deploy.rs:deploy-deploy-params}}
+```
+
+### Contract Statement
+
+**Contract deployment status**   whether the contract is locked. If yes then fail.
+
+**WASM bincode validity**   whether the provided `WASM` bincode is valid. If no then fail.
+
+### Signatures
+
+There should be a single signature attached, which uses $\t{PK}$ as the
+signature public key.
+
+## Lock
+
+This function finalizes the smart contract state definition.
+
+* Wallet builder: `src/contract/deployooor/src/client/lock_v1.rs`
+* WASM VM code: `src/contract/deployooor/src/entrypoint/lock_v1.rs`
+
+### Function Params
+
+Define the lock params
+$$ \begin{aligned}
+  \t{Params}_\t{Lock}.PK &∈ \tℙₚ \\
+\end{aligned} $$
+
+```rust
+{{#include ../../../../../src/contract/deployooor/src/model.rs:deploy-lock-params}}
+```
+
+### Contract Statement
+
+**Contract deployment status**   whether the contract is already locked. If yes then fail.
+
+### Signatures
+
+There should be a single signature attached, which uses $\t{PK}$ as the
+signature public key.

+ 2 - 0
src/contract/deployooor/src/model.rs

@@ -29,12 +29,14 @@ pub struct DeployUpdateV1 {
     pub contract_id: ContractId,
 }
 
+// ANCHOR: deploy-lock-params
 /// Parameters for `Deploy::Lock`
 #[derive(Clone, Debug, SerialEncodable, SerialDecodable)]
 pub struct LockParamsV1 {
     /// Public key used to sign the transaction and derive the `ContractId`
     pub public_key: PublicKey,
 }
+// ANCHOR_END: deploy-lock-params
 
 /// State update for `Deploy::Lock`
 #[derive(Clone, Debug, SerialEncodable, SerialDecodable)]

+ 2 - 0
src/sdk/src/deploy.rs

@@ -22,6 +22,7 @@ use darkfi_serial::{SerialDecodable, SerialEncodable};
 
 use crate::crypto::PublicKey;
 
+// ANCHOR: deploy-deploy-params
 /// Parameters for `Deploy::Deploy`
 #[derive(Clone, Debug, SerialEncodable, SerialDecodable)]
 pub struct DeployParamsV1 {
@@ -32,3 +33,4 @@ pub struct DeployParamsV1 {
     /// Serialized deployment payload instruction
     pub ix: Vec<u8>,
 }
+// ANCHOR_END: deploy-deploy-params