Просмотр исходного кода

Remove obsolete /contract directory.

parazyd 3 лет назад
Родитель
Сommit
c3b4b48820

+ 0 - 1
contract/money/.gitignore

@@ -1 +0,0 @@
-target/*

+ 0 - 23
contract/money/Cargo.toml

@@ -1,23 +0,0 @@
-[package]
-name = "darkfi-money-contract"
-version = "0.4.0"
-authors = ["Dyne.org foundation <foundation@dyne.org>"]
-license = "AGPL-3.0-only"
-edition = "2021"
-
-[workspace]
-
-[lib]
-crate-type = ["cdylib", "rlib"]
-
-[profile.release]
-lto = true
-codegen-units = 1
-overflow-checks = true
-
-[dependencies]
-darkfi-sdk = { path = "../../src/sdk" }
-darkfi-serial = { path = "../../src/serial", features = ["crypto"] }
-
-# Dummy getrandom
-getrandom = { version = "0.2.7", features = ["custom"] }

+ 0 - 39
contract/money/Makefile

@@ -1,39 +0,0 @@
-.POSIX:
-
-WASM_SRC = $(shell find src -type f)
-PROOF_SRC = $(shell find proof -type f -name '*.zk')
-
-# Cargo binary
-CARGO = cargo
-
-# zkas binary
-ZKAS = ../../zkas
-
-# wasm-strip binary (Part of https://github.com/WebAssembly/wabt)
-WASM_STRIP = wasm-strip
-
-# Contract WASM binary
-WASM_BIN = contract.wasm
-
-# ZK circuit binaries
-PROOF_BIN = $(PROOF_SRC:=.bin)
-
-all: $(PROOF_BIN) $(WASM_BIN)
-
-strip: $(WASM_BIN)
-	$(WASM_STRIP) $<
-
-$(WASM_BIN): $(WASM_SRC)
-	$(CARGO) build --release --lib --target wasm32-unknown-unknown
-	cp -f target/wasm32-unknown-unknown/release/*.wasm $@
-
-$(PROOF_BIN): $(PROOF_SRC)
-	$(ZKAS) $(basename $@) -o $@
-
-test: all
-	$(CARGO) test --release -- --nocapture
-
-clean:
-	rm -f $(PROOF_BIN) $(WASM_BIN)
-
-.PHONY: all test clean

+ 0 - 99
contract/money/src/lib.rs

@@ -1,99 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2022 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-use darkfi_sdk::{
-    crypto::{MerkleNode, Nullifier},
-    entrypoint,
-    error::ContractResult,
-    incrementalmerkletree::bridgetree::BridgeTree,
-};
-use darkfi_serial::{deserialize, SerialDecodable, SerialEncodable};
-
-/// Available functions for this contract.
-/// We identify them with the first byte passed in through the payload.
-#[repr(u8)]
-pub enum Function {
-    Transfer = 0x00,
-}
-
-impl From<u8> for Function {
-    fn from(b: u8) -> Self {
-        match b {
-            0x00 => Self::Transfer,
-            _ => panic!("Invalid function ID: {:#04x?}", b),
-        }
-    }
-}
-
-pub mod transfer;
-
-/// `State` represents this contract's state on-chain. The contract's
-/// entrypoint knows its own `ContractId` since it's passed in by the
-/// wasm runtime, so it knows what to request. Retrieval of the state
-/// from the blockchain is done with a host function called `lookup_state`.
-/// For more info, see:
-/// * `darkfi/src/blockchain/statestore.rs`
-/// * ~~~`darkfi/src/runtime/chain_state.rs`~~~
-#[repr(C)]
-#[derive(Clone, SerialEncodable, SerialDecodable)]
-pub struct State {
-    /// The Merkle tree of all coins used by this contract.
-    pub tree: BridgeTree<MerkleNode, 32>,
-    /// List of all previous and current Merkle roots.
-    pub merkle_roots: Vec<MerkleNode>,
-    /// Published nullifiers that have been seen.
-    pub nullifiers: Vec<Nullifier>,
-}
-
-impl State {
-    pub fn is_valid_merkle(&self, merkle_root: &MerkleNode) -> bool {
-        self.merkle_roots.iter().any(|m| m == merkle_root)
-    }
-
-    pub fn nullifier_exists(&self, nullifier: &Nullifier) -> bool {
-        self.nullifiers.iter().any(|n| n == nullifier)
-    }
-}
-
-#[cfg(not(feature = "no-entrypoint"))]
-entrypoint!(process_instruction);
-fn process_instruction(state: &[u8], ix: &[u8]) -> ContractResult {
-    // This is the entrypoint function of the smart contract which gets executed
-    // by the wasm runtime. The `contract_id` passed in is used to lookup the
-    // current state from the ledger using the `lookup_state` function.
-    // `ix` is an arbitrary payload fed into the contract. In this case, the
-    // first byte of the payload is a pointer to a function we with to run, and
-    // the remainter is a serialized `Transaction` object we'll try to deserialize
-    // and work with.
-    let mut state: State = deserialize(state)?;
-
-    match Function::from(ix[0]) {
-        Function::Transfer => {
-            let transaction = deserialize(&ix[1..])?;
-            transfer::exec(&mut state, transaction)?;
-            // If `transfer` succeeded, `state` will contain the updated state, so
-            // we can change it in the VM environment which is accessible by the
-            // host. Then if everything else outside of the wasm execution is
-            // valid, the host can reference this new state and update it on the
-            // ledger.
-            //apply_state(&serialize(&state))?;
-        }
-    }
-
-    Ok(())
-}

+ 0 - 151
contract/money/src/transfer.rs

@@ -1,151 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2022 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-use darkfi_sdk::{
-    crypto::{
-        pedersen::{pedersen_commitment_base, pedersen_commitment_u64, ValueCommit},
-        MerkleNode,
-    },
-    error::{ContractError, ContractResult},
-    incrementalmerkletree::Tree,
-    msg,
-    pasta::{group::Group, pallas},
-    state::Verification,
-};
-
-use super::State;
-
-/// This function is the execution of the `Transfer` functionality.
-pub fn exec(state: &mut State, tx: Transaction) -> ContractResult {
-    // TODO: Clear inputs. Cashier+Faucet logic is bad and needs to
-    // be solved in another better way.
-
-    // Nullifiers in the transaction
-    let mut nullifiers = Vec::with_capacity(tx.inputs.len());
-
-    msg!("Iterating over inputs");
-    for (i, input) in tx.inputs.iter().enumerate() {
-        let merkle_root = input.revealed.merkle_root;
-        let spend_hook = input.revealed.spend_hook;
-        let nullifier = input.revealed.nullifier;
-
-        // The Merkle root is used to know whether this is a coin
-        // that existed in a previous state.
-        if !state.is_valid_merkle(&merkle_root) {
-            msg!("Error: Invalid Merkle root (input {})", i);
-            msg!("Root: {:?}", merkle_root);
-            return Err(ContractError::Custom(30))
-        }
-
-        // Check the spend_hook is satisfied.
-        // The spend_hook says a coin must invoke another contract
-        // function when being spent. If the value is set, then we
-        // check the function call exists.
-        if spend_hook != pallas::Base::zero() {
-            todo!();
-        }
-
-        // The nullifiers should not already exist. This gives us
-        // protection against double-spending.
-        if state.nullifier_exists(&nullifier) || nullifiers.contains(&nullifier) {
-            msg!("Duplicate nulliier found (input {})", i);
-            msg!("Nullifier: {:?}", nullifier);
-            return Err(ContractError::Custom(31))
-        }
-
-        // Add the nullifier to the list of seen nullifiers.
-        nullifiers.push(nullifier);
-    }
-
-    // Verify transaction
-    match tx.verify() {
-        Ok(()) => msg!("Transaction verified successfully"),
-        Err(e) => {
-            msg!("Transaction failed to verify");
-            return Err(e)
-        }
-    }
-
-    msg!("Applying state update");
-    state.nullifiers.extend_from_slice(&nullifiers);
-    for output in tx.outputs {
-        state.tree.append(&MerkleNode::from(output.coin.inner()));
-        state.merkle_roots.push(state.tree.root(0).unwrap());
-    }
-
-    Ok(())
-}
-
-// `Verification` could be a generic trait we implement for doing
-// arbitrary verification in contracts.
-impl Verification for Transaction {
-    fn verify(&self) -> ContractResult {
-        // Must have minimum 1 clear or anon input
-        if self.clear_inputs.len() + self.inputs.len() == 0 {
-            msg!("Error: Missing inputs in transaction");
-            return Err(ContractError::Custom(32))
-        }
-
-        // Also minimum 1 output
-        if self.outputs.is_empty() {
-            msg!("Error: Missing outputs in transaction");
-            return Err(ContractError::Custom(33))
-        }
-
-        // Accumulator for the value commitments
-        let mut valcom_total = ValueCommit::identity();
-
-        // Add values from the clear inputs
-        for input in &self.clear_inputs {
-            valcom_total += pedersen_commitment_u64(input.value, input.value_blind);
-        }
-
-        // Add values from the inputs
-        for input in &self.inputs {
-            valcom_total += input.revealed.value_commit;
-        }
-
-        // Subtract values from the outputs
-        for output in &self.outputs {
-            valcom_total -= output.revealed.value_commit;
-        }
-
-        // If the accumulator is not back in its initial state,
-        // there's a value mismatch.
-        if valcom_total != ValueCommit::identity() {
-            msg!("Error: Missing funds");
-            return Err(ContractError::Custom(34))
-        }
-
-        // Verify that the token commitments match
-        let tokval = self.outputs[0].revealed.token_commit;
-        let mut failed = self.inputs.iter().any(|input| input.revealed.token_commit != tokval);
-        failed = failed || self.outputs.iter().any(|output| output.revealed.token_commit != tokval);
-        failed = failed ||
-            self.clear_inputs.iter().any(|input| {
-                pedersen_commitment_base(input.token_id, input.token_blind) != tokval
-            });
-
-        if failed {
-            msg!("Error: Token ID mismatch");
-            return Err(ContractError::Custom(35))
-        }
-
-        Ok(())
-    }
-}