package octez-libs
A package that contains multiple base libraries used by the Octez suite
Install
Dune Dependency
Authors
Maintainers
Sources
tezos-octez-v20.1.tag.bz2
sha256=ddfb5076eeb0b32ac21c1eed44e8fc86a6743ef18ab23fff02d36e365bb73d61
sha512=d22a827df5146e0aa274df48bc2150b098177ff7e5eab52c6109e867eb0a1f0ec63e6bfbb0e3645a6c2112de3877c91a17df32ccbff301891ce4ba630c997a65
doc/src/octez-libs.tezos-sapling/core_sig.ml.html
Source file core_sig.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
(*****************************************************************************) (* *) (* Open Source License *) (* Copyright (c) 2019-2020 Nomadic Labs <contact@nomadic-labs.com> *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) (* to deal in the Software without restriction, including without limitation *) (* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) (* and/or sell copies of the Software, and to permit persons to whom the *) (* Software is furnished to do so, subject to the following conditions: *) (* *) (* The above copyright notice and this permission notice shall be included *) (* in all copies or substantial portions of the Software. *) (* *) (* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) (* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) (* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) (* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) (* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) (* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************) (** Reference specification is version 2020.1.2 https://github.com/zcash/zips/blob/master/protocol/sapling.pdf *) (** Each instance of the Sapling protocol should be identified by a unique string identifier which is used as anti-replay. It should typically contain a chain identifier and the identifier of a smart-contract. **) module type T_bytes = sig type t val to_bytes : t -> bytes val of_bytes_exn : bytes -> t end module type T_encoding = sig type t val encoding : t Data_encoding.t end module type T_encoding_bytes = sig include T_bytes include T_encoding with type t := t end module type T_encoding_compare = sig include T_encoding val compare : t -> t -> int end (** Spending keys allow to spend and derive viewing keys. It contains key material and information to derive deterministically more spending keys using the zip-32 standard (equivalent of bip-32 for ZCash). See spec section 3.1 **) module type Spending_key = sig include T_encoding (** Outgoing viewing keys allow to keep track of spendings from a key. This feature is optional, a payer can decide to not keep track of its outgoing transactions. **) type ovk val of_bytes : bytes -> t option val to_bytes : t -> bytes (** Generate a key from a 32 byte uniformly random seed. The source of randomness should be of cryptographic quality. **) val of_seed : bytes -> t (** [derive_key k n] derives the nth key from [k] **) val derive_key : t -> int32 -> t (** Returns the next available index from a key **) val child_index : t -> int32 val b58check_encoding : t Tezos_crypto.Base58.encoding end (** Viewing keys allow to see incoming and outgoing transactions without giving the ability to spend. Stored in the zip-32 format. **) module type Viewing_key = sig type spending_key include T_encoding val of_bytes : bytes -> t option val to_bytes : t -> bytes val of_sk : spending_key -> t (** Indexes to derive addresses. Starting from [default_index], the following addresses can be derived with [index_succ] **) type index val compare_index : index -> index -> int val default_index : index val index_succ : index -> index val index_to_int64 : index -> int64 val index_of_int64 : int64 -> index val index_encoding : index Data_encoding.t (** To be given to the payer. Does not appear on the blockchain. Different addresses can be derived from one key which is necessary to prevent a loss of anonymity because of several payers colluding. e.g. two payers can conclude that they are paying the same person if they send money to the same address. **) type address val address_encoding : address Data_encoding.t val address_b58check_encoding : address Tezos_crypto.Base58.encoding (** Returns a new address and a new index to be used for the next address generation. **) val new_address : t -> index -> index * address (** A dummy address can be generated to create dummy inputs or outputs of value 0. Note that tokens sent to dummy addresses are lost! **) val dummy_address : unit -> address (** Incoming viewing keys can be used to see transactions received to any address generated from this key. This feature is not enforced by the protocol, a payer could spend tokens on-chain and transmit to the recipient invalid information. The recipient should always check the received transactions with its ivk. **) type ivk val to_ivk : t -> ivk type ovk val ovk_of_xfvk : t -> ovk end module type Wallet = sig module Spending_key : Spending_key module Viewing_key : Viewing_key with type spending_key := Spending_key.t end module type Hash = sig (** Pedersen's Commitment of a transaction output (i.e. address and value). A merkle tree is formed with the existing commitment and filled with a default uncommitted value **) type commitment include T_encoding_compare include T_bytes with type t := t val uncommitted : height:int -> t (** Hash function to compute the merkle tree (Pedersen's hash on JubJub curve). Height is the height we are hashing at in the merkle tree. **) val merkle_hash : height:int -> t -> t -> t (** Hashes and commitments are the same object but are given different types to avoid confusing nodes and leaves. **) val of_commitment : commitment -> t val to_commitment : t -> commitment end module type UTXO = sig (** Ciphertexts are encrypted information used to retrieve payments and can be decrypted with full keys or just ovk. They can be stored on-chain or transmitted off-chain from payer to recipient. **) type ciphertext (** A commitment is the equivalent of a transaction output, with the important difference of not leaking any information. Must be stored on chain. **) type commitment (** Commitment value. The value of a transaction output is committed (Pedersen's commitment) separately. **) type cv type hash (** Nullifiers are used to invalidated a commitment, that is marking it as spent. However they can't be linked to the commitment that they invalidate. Nullifiers are derived from a commitment and a secret key using a pseudo random function. **) type nullifier (** Randomised signature keys. All inputs are signed with a randomised version of a secret key. **) type rk (** Zero knowledge proofs needed to spend a transaction outputs. See spec section 4.15 **) type spend_proof (** Signature needed to spend tokens. Computed with a randomised version of the secret key and verifies under a randomised version of the public key. Signs a hash of an input concatenated with an optional anti-replay string. **) type spend_sig (** Zero-knowledge proof needed to create money. See spec section 4.15 **) type output_proof (** Contains the necessary information to spend tokens (except the root which we include in the transaction). **) type input = { cv : cv; nf : nullifier; rk : rk; proof_i : spend_proof; signature : spend_sig; } val input_encoding : input Data_encoding.t (** Contains the necessary information to create tokens. **) type output = { cm : commitment; proof_o : output_proof; ciphertext : ciphertext; } val output_encoding : output Data_encoding.t (** Ties a transaction to a balance (difference between the tokens created and spent). Proves with the commitment values that sum of values of inputs minus sums of values of output equals balance. **) type binding_sig val binding_sig_encoding : binding_sig Data_encoding.t (** Transaction that is sent to a verifier. The root corresponds to a merkle tree where the inputs are present. Even if this root can in principle be very old, a verifier may keep only the last n known roots considering anything older as invalid. [bound_data] is arbitrary data that gets signed by the Sapling keys and can typically be used to connect the Sapling protocol to another one. For example it can contain the recipient address of an unshield operation. The memo_size field is checked at encoding and encoding to be the real memo size of all outputs. A transaction leaks the balance between inputs and outputs and the number of inputs and outputs. Note that the number of inputs is limited to 5208 and number of outputs to 2019, by a check in the encoding. This is important to avoid invalidating a proof over the balance as described in section 4.12 of the spec. *) type transaction = { inputs : input list; outputs : output list; binding_sig : binding_sig; balance : int64; root : hash; bound_data : string; } (** The encoding enforces the limits on number of inputs and outputs. *) val transaction_encoding : transaction Data_encoding.t (** Maximum amount of shielded tokens. This value is imposed by librustzcash. **) val max_amount : int64 val valid_amount : int64 -> bool module Legacy : sig type transaction_new = transaction (* This type is for backward compatibility with a previous definition of [transaction] which didn't have any [bound_data]. *) type transaction = { inputs : input list; outputs : output list; binding_sig : binding_sig; balance : int64; root : hash; } val transaction_encoding : transaction Data_encoding.t val cast : transaction -> transaction_new end end (** Regroups what needs to be exposed to a Validator **) module type Validator = sig (** Loads the ZCash parameters for Groth16, searching them in: - [/usr/share/zcash-params] - [${OPAM_SWITCH_PREFIX}/share/zcash-params] - [${HOME}/.zcash-params] Only Sapling's parameters are loaded, not Sprout's. This function must be called before any of the proving and verification functions requiring a context. Usually you should not need to call this function directly as it is done by the fist call to `with_\{proving,verification\}_ctx`. However you can call this function in order to: - pay its cost upfront and have more predictable latency later - make sure that the parameters are present in the system and avoid a failure later. *) val init_params : unit -> unit module Ciphertext : sig include T_encoding val get_memo_size : t -> int end module Commitment : sig include T_encoding_bytes val valid_position : int64 -> bool end module CV : T_encoding module Hash : Hash with type commitment := Commitment.t module Nullifier : T_encoding_compare module UTXO : UTXO with type ciphertext := Ciphertext.t and type commitment := Commitment.t and type cv := CV.t and type hash := Hash.t and type nullifier := Nullifier.t module Verification : sig (** A verification context. Stores information involving the commitment values of inputs and outputs and it is used to verify the binding_sig. A context should created with [init], passed to [check_spend] for all inputs and [check_output] for all outputs, passed to [final_check] and finally freed with [free]. **) type t val with_verification_ctx : (t -> 'a) -> 'a (** Checks the zero-knowledge proof for spending money, the spend_sig, and stores info in the context. String is the anti-replay. **) val check_spend : t -> UTXO.input -> Hash.t -> string -> bool (** Checks the zero-knowledge proof for creating money and stores information in the context **) val check_output : t -> UTXO.output -> bool (** Utilise the context to check the balance. String is the anti-replay string. **) val final_check : t -> UTXO.transaction -> string -> bool end end (** A Diffie-Hellman key exchange is done between the payer and the recipient to encrypt the ciphertext. This can be done off or on chain. **) module type DH_esk = sig type esk (** Generate a random scalar to be used by the sender for DH. **) val esk_random : unit -> esk end module type Commitment = sig (** Randomness used for the commitment. **) type rcm type viewing_key_address include T_encoding_bytes val compute : viewing_key_address -> amount:int64 -> rcm -> t val valid_position : int64 -> bool end module type CV = sig include T_encoding val of_bytes : bytes -> t option end (** See spec section 3.8 **) module type Nullifier = sig type rcm type viewing_key_address type viewing_key include T_encoding_compare val compute : viewing_key_address -> viewing_key -> amount:int64 -> rcm -> position:int64 -> t end module type Rcm = sig include T_encoding val random : unit -> t val assert_valid : t -> unit end (** Signatures for Client/Validator/Storage + some functions used in tests *) module type Client = sig include Wallet module Rcm : Rcm module Nullifier : Nullifier with type rcm := Rcm.t and type viewing_key_address := Viewing_key.address and type viewing_key := Viewing_key.t module Commitment : Commitment with type rcm := Rcm.t and type viewing_key_address := Viewing_key.address module CV : CV include Validator with module Commitment := Commitment and module CV := CV and module Nullifier := Nullifier module DH : DH_esk module Proving : sig (** A proving context. Stores information about the commitment values and is used for the binding_sig. A context should created with [init], passed to [spend_proof] for all inputs and [output_proof] for all outputs, passed to [make_binding_sig] and finally freed with [free]. **) type t (** Randomness to randomise the signature key. **) type ar val with_proving_ctx : (t -> 'a) -> 'a val ar_random : unit -> ar (** String is the anti-replay. **) val spend_sig : Spending_key.t -> ar -> CV.t -> Nullifier.t -> UTXO.rk -> UTXO.spend_proof -> string -> UTXO.spend_sig val spend_proof : t -> Viewing_key.t -> Spending_key.t -> Viewing_key.address -> Rcm.t -> ar -> amount:int64 -> root:Hash.t -> witness:Bytes.t -> CV.t * UTXO.rk * UTXO.spend_proof val output_proof : t -> DH.esk -> Viewing_key.address -> Rcm.t -> amount:int64 -> CV.t * UTXO.output_proof (** See spec section 4.12 **) val make_binding_sig : t -> UTXO.input list -> UTXO.output list -> balance:int64 -> bound_data:string -> string -> UTXO.binding_sig end module Forge : sig module Input : sig (** Necessary infos to create spend some money belonging to our key. **) type t = { rcm : Rcm.t; pos : int64; amount : int64; address : Viewing_key.address; } include T_encoding with type t := t val compare : t -> t -> int (** Decrypt a ciphertext to create a input. The decryption can fail if the description key is incorrect or the ciphertext is incorrect. The returned bytes are a memo added by the sender **) val of_ciphertext : pos:int64 -> Ciphertext.t -> Viewing_key.t -> (Bytes.t * t) option (** Same as of_ciphertext but requires only the ovk. **) val of_ciphertext_out : pos:int64 -> Ciphertext.t -> Spending_key.ovk -> Commitment.t -> (Bytes.t * t) option (** Check that a commitment corresponds to an input **) val check_cm : t -> Commitment.t -> bool end (** Necessary information to create tokens. **) module Output : sig type t = {address : Viewing_key.address; amount : int64; memo : Bytes.t} (** Creates a ciphertext that the recipient can use to spend his tokens, and our ovk can see as spent tokens. **) val to_ciphertext : t -> CV.t -> Viewing_key.t -> Rcm.t -> DH.esk -> Ciphertext.t * Commitment.t (** Same as to_ciphertext but does not allow the ovk to decrypt (ie. [of_ciphertext_out] will return None). **) val to_ciphertext_without_ovk : t -> Rcm.t -> DH.esk -> CV.t -> Ciphertext.t * Commitment.t end end end
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>