Skip to content

Commit

Permalink
Update the docs (#515)
Browse files Browse the repository at this point in the history
* Add `char` to the list of Sophia types

* Move `Chain.ttl` to stdlib docs instead of Sophia types

* Add a note about `Chain.ttl` being a special case

* Make `Call.gas_left` a constant instead of a zero-argument function

* Move the function `Int.mulmod` to its right place in stdlib docs

* Move the function `Crypto.poseidon` to its right place in stdlib docs

* Fix typos in 'sophia_stdlib.md'

* Add `bytes_t` to `utype()` in the type checker
  • Loading branch information
ghallak authored Nov 12, 2024
1 parent 4a59486 commit b892a9f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/sophia_features.md
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ Sophia has the following types:
| Type | Description | Example |
|----------------------|---------------------------------------------------------------------------------------------|--------------------------------------------------------------|
| int | A 2-complement integer | ```-1``` |
| char | A single character (the underlying representation is an integer) | ```'g'```
| address | æternity address, 32 bytes | ```Call.origin``` |
| bool | A Boolean | ```true``` |
| bits | A bit field | ```Bits.none``` |
Expand All @@ -555,7 +556,6 @@ Sophia has the following types:
| event | An append only list of blockchain events (or log entries) | ```datatype event = EventX(indexed int, string)``` |
| hash | A 32-byte hash - equivalent to `bytes(32)` | |
| signature | A signature - equivalent to `bytes(64)` | |
| Chain.ttl | Time-to-live (fixed height or relative to current block) | ```FixedTTL(1050)``` ```RelativeTTL(50)``` |
| oracle('a, 'b) | And oracle answering questions of type 'a with answers of type 'b | ```Oracle.register(acct, qfee, ttl)``` |
| oracle_query('a, 'b) | A specific oracle query | ```Oracle.query(o, q, qfee, qttl, rttl)``` |
| contract | A user defined, typed, contract address | ```function call_remote(r : RemoteContract) = r.fun()``` |
Expand Down
58 changes: 36 additions & 22 deletions docs/sophia_stdlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,6 @@ Call.gas_price : int

The gas price of the current call.

#### mulmod
```
Int.mulmod : (a : int, b : int, q : int) : int
```

Combined multiplication and modulus, returns `(a * b) mod q`.

#### fee
```
Call.fee : int
Expand All @@ -501,7 +494,7 @@ The fee of the current call.

#### gas_left
```
Call.gas_left() : int
Call.gas_left : int
```

The amount of gas left for the current call.
Expand All @@ -513,6 +506,20 @@ Values and functions related to the chain itself and other entities that live on

#### Types

##### ttl

Time-to-live (fixed height or relative to current block).

Note that this type is a special case, where the type `ttl` is inside the
`Chain` scope, but the constrctors `FixedTTL(int)` and `RelativeTTL(int)` are
not. Meaning that the type `ttl` should be qualified with `Chain` when it is
used (i.e. `Chain.ttl`), but the constructors should not be qualified (i.e.
`FixedTTL(1050)` should be used rather than `Chain.FixedTTL(1050)`).

```
Chain.ttl = FixedTTL(int) | RelativeTTL(int)
```

##### tx
```
record tx = { paying_for : option(Chain.paying_for_tx)
Expand Down Expand Up @@ -573,7 +580,7 @@ the current generation.

##### block_height
```
Chain.block_height : int"
Chain.block_height : int
```

The height of the current block (i.e. the block in which the current call will be included).
Expand Down Expand Up @@ -732,23 +739,14 @@ Chain.gas_limit : int
The gas limit of the current block.


##### network\_id
##### network_id
```
Chain.network\_id : string
Chain.network_id : string
```

The network id of the chain.


#### poseidon
```
Crypto.poseidon(x1 : int, x2 : int) : int
```

Hash two integers (in the scalar field of BLS12-381) to another integer (in the scalar
field of BLS12-281). This is a ZK/SNARK-friendly hash function.


##### spend
```
Chain.spend(to : address, amount : int) : unit
Expand All @@ -769,7 +767,7 @@ The timestamp of the current block (unix time, milliseconds).
### Char

#### to_int
```
```
Char.to_int(c : char) : int
```

Expand All @@ -780,7 +778,7 @@ Returns the UTF-8 codepoint of a character

```
Char.from_int(i : int) : option(char)
```
```

Opposite of [to_int](#to_int). Returns `None` if the integer doesn't correspond to a single (normalized) codepoint.

Expand Down Expand Up @@ -839,6 +837,15 @@ Crypto.blake2b(x : 'a) : hash
Hash any object to blake2b


#### poseidon
```
Crypto.poseidon(x1 : int, x2 : int) : int
```

Hash two integers (in the scalar field of BLS12-381) to another integer (in the scalar
field of BLS12-281). This is a ZK/SNARK-friendly hash function.


#### verify_sig
```
Crypto.verify_sig(msg : bytes(), pubkey : address, sig : signature) : bool
Expand Down Expand Up @@ -881,6 +888,13 @@ Verifies a standard 64-byte ECDSA signature (`R || S`).

### Int

#### mulmod
```
Int.mulmod : (a : int, b : int, q : int) : int
```

Combined multiplication and modulus, returns `(a * b) mod q`.

#### to\_str
```
Int.to_str(n : int) : string
Expand Down
1 change: 1 addition & 0 deletions src/aeso_ast_infer_types.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
-type utype() :: {fun_t, aeso_syntax:ann(), named_args_t(), [utype()] | var_args, utype()}
| {app_t, aeso_syntax:ann(), utype(), [utype()]}
| {tuple_t, aeso_syntax:ann(), [utype()]}
| {bytes_t, aeso_syntax:ann(), non_neg_integer() | any}
| aeso_syntax:id() | aeso_syntax:qid()
| aeso_syntax:con() | aeso_syntax:qcon() %% contracts
| aeso_syntax:tvar()
Expand Down

0 comments on commit b892a9f

Please sign in to comment.