Skip to content

Commit

Permalink
sigmaboolean
Browse files Browse the repository at this point in the history
  • Loading branch information
glasgowm148 committed Oct 5, 2023
1 parent 6142554 commit 785e47f
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 12 deletions.
92 changes: 82 additions & 10 deletions docs/dev/scs/types/sigmaboolean.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,88 @@
# SigmaBoolean

SigmaBoolean is a fundamental component in the world of SigmaScript and SigmaDsl, serving as an algebraic data type for sigma proposition expressions. This data type enables developers to work with boolean-like logic for sigma propositions, and it's worth noting that SigmaBoolean is a recursive data structure, adding complexity to its parsing process.

## Understanding the Structure of SigmaBoolean

To comprehend SigmaBoolean better, let's delve into its structure:

```scala
/** Represents the algebraic data type of sigma proposition expressions.
*
*/
trait SigmaBoolean {
/** A unique identifier for the node class, used during serialization. */
val opCode: OpCode
/** Returns the size of the proposition tree (number of nodes). */
def size: Int
}
```
Within this structure, `opCode` serves as an identifier for the node class, especially during the serialization process. Concurrently, the `size` method provides a means to determine the size of the proposition tree in terms of its nodes.


Check out [Values.scala](https://github.com/ScorexFoundation/sigmastate-interpreter/blob/develop/interpreter/shared/src/main/scala/sigmastate/Values.scala#L745) for full details


## Serializing SigmaBoolean from a P2PK Address

Serializing SigmaBoolean from a P2PK address is a key process in Ergo blockchain development. This process enables the creation and execution of sophisticated smart contracts. Through the encoding of SigmaBoolean from a P2PK address, developers can articulate intricate contract conditions, bolster privacy features, ensure seamless interoperability, tailor contract logic, enhance security auditing measures, and facilitate cross-platform compatibility.

Serializing SigmaBoolean from a P2PK (Pay-to-Public-Key) address involves several steps:

1. **Decode P2PK Address**: Begin by decoding the P2PK address using Base58 encoding.

2. **Extract Public Key Bytes**: From the decoded data, remove the first byte, retain the last 4 bytes, and prepend it with `0xCD, 0x03`.

3. **Incorporate Instruction Code**: Integrate the `ProveDlog` instruction code with the public key bytes by prepending "08cd" to the bytes. This produces a serialized SigmaBoolean value.

To obtain the ErgoTree, prepend `0x00` (header byte) to the serialized SigmaBoolean.

### Serialization using Fleet (TypeScript)

Here's how you can serialize SigmaBoolean using Fleet in TypeScript:

```typescript
// Extract the public key from the encoded address
const pk = ErgoAddress.fromBase58("address_here").getPublicKeys()[0];

// For base64 encoding (typically required for ergopay):
const encodedProp = base64.encode(SSigmaProp(SGroupElement(pk)).toBytes());

// Without base64 encoding:
const encodedProp = SSigmaProp(SGroupElement(pk)).toHex();
```

### Serialization with bs58 (TypeScript)

Alternatively, you can use bs58 for serialization in TypeScript:

```typescript
const decodedBuffer = bs58.decode(ergoAddress);
const rawBytes = Uint8Array.from(decodedBuffer);
const slicedBytes = rawBytes.subarray(2, rawBytes.length - 4);
const combinedBytes = new Uint8Array([0xCD, 0x03, ...slicedBytes]);
const sigmaBoolean = Buffer.from(combinedBytes).toString('base64');
```

## Data Serialization in SigmaState

Within the SigmaState framework, data serialization is crucial, including the serialization and deserialization of SigmaBoolean, which is handled as follows:

```scala
/** Algebraic data type of sigma proposition expressions.
* Values of this type are used as values of SigmaProp type of SigmaScript and SigmaDsl
*/
trait SigmaBoolean {
/** Unique id of the node class used in serialization of SigmaBoolean. */
val opCode: OpCode
/** Size of the proposition tree (number of nodes). */
def size: Int
}
...
case SSigmaProp =>
val p = v.asInstanceOf[SigmaProp]
SigmaBoolean.serializer.serialize(sigmaPropToSigmaBoolean(p), w)
...
case SSigmaProp =>
SigmaDsl.SigmaProp(SigmaBoolean.serializer.parse(r))
...
```

From [Values.scala](https://github.com/ScorexFoundation/sigmastate-interpreter/blob/develop/interpreter/shared/src/main/scala/sigmastate/Values.scala#L745)
Key points to note:

1. **Serialization**: The serialization of `SigmaBoolean` is accomplished using the `SigmaBoolean.serializer.serialize` method.

2. **Deserialization**: During deserialization, when encountering the `SSigmaProp` type, the `SigmaBoolean.serializer` is employed to parse and deserialize the sigma proposition from the provided reader `r`.

3. **Type Matching**: The type `SSigmaProp` specifically represents sigma propositions in the provided code, and its serialization and deserialization are managed with precision.
6 changes: 4 additions & 2 deletions docs/node/conf/conf-wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,16 @@ This setting determines whether to use the pre-EIP3 key derivation scheme or not
```conf
dustLimit = null
```
This sets the minimum amount of tokens that can be in a transaction output. If it's set to null, there's no minimum limit.
This sets the minimum amount of tokens that can be in a transaction output. If it's set to null (default), there's no minimum limit.

with `dustLimit = 1000000`` the node wallet will skip boxes to self having less than .001 ERG

## Maximum and Optimal Inputs
```conf
maxInputs = 100
optimalInputs = 3
```
The `maxInputs` setting determines the maximum number of inputs a transaction can have. The `optimalInputs` setting specifies the preferred number of inputs for a transaction.
The `maxInputs` setting determines the maximum number of inputs a transaction can have. The `optimalInputs` setting specifies the preferred number of inputs for a transaction. This allows you to merge dust when doing payments.

## Test Mnemonic and Keys Quantity
```conf
Expand Down

0 comments on commit 785e47f

Please sign in to comment.