# Block Collider BEAM
All events in the blockchain universe can be expressed in NRG (energy). This is the over all design philosophy of the multichain scripting language.
## Core operations
Below you can find an overview of all the OP_CODE functions explained during the '_30 Days of After Target_' Telegram event **starting January 21^st^ 2019**
::: info
This document can be edited by anyone. (Use the switch-mode buttons on top of this page to enter edit mode.) [[Ctrl+Alt+E]](https://hackmd.io/iKS_unJvTCGD85vk9Hek2Q?edit). Changes will be visible in real-time for anyone. You can **document your changes in the comment section next to [the main title](#).** (Click the speech balloon.) Feel free to contribute.
:::
:::info
**Looking for Official Resources ?** (whitepaper, telegram, docs,...) Scroll to bottom or [click here](#Other-Official-Resources) to jump to 'Other Official Resources'.
:::
___
### OP_MONOID
The first operation is called “OP_MONOID”. This “opcode” **must be the first argument in your script** and is the first of several which introduce set theory logic into the multichain. Monoids pull the operating context off of the stack and allow any address to spend the NRG value as long as it runs the Monoid script first. Once a sequence of transactions start operating in the monadic set you can create amazing decentralized applications which behave like as if they were on their own chain without adding the bloat of a new blockchain.
#### How do I use it?
The implications of OP_MONOID are far reaching. The first: using Monoids to settle and resolve partial orders. Unlike atomic swaps which create inefficient markets. Monadic settlements allow takers to take some of an order. OP_MONOID is designed to enable settlement between thousands of parties in a single transaction.
Questions: https://web.telegram.org/#/im?p=%40schnorr
___
### OP_EMERGENCY
“*Do what you can, with what you have, where you are.*” ~ TR
The second operation is “OP_EMERGENCY”. The function represents an event flag which means that it signals miners to evaluate the transaction in a specific context--generally no fees. The function requires setting an expiration block height when the OP_EMERGENCY is no longer active, an optional Super Collider reference, and a event public key. The event public key is determined by the non-governmental organization (NGO) or sovereign nation and provided by their own communication channels.
#### How do I use it?
As globalisation continues and communication becomes more efficient we can greatly improve the way we as the human race handle hurricanes, refugees, earthquakes and other calamities. When included in BEAM script, OP_EMERGENCY allows miners to support an event by adding the transaction for free, prioritizing the addition of the transaction into the miner’s block or some other benefit captured in the message. The public key can be arbitrarily set by the NGO nation but in order to prevent any form of spoofing the NGO can deploy a short lived Super Collider whose latest block hash can be included in this field preventing bad agents from free-riding benefits alloted to the specific OP_EMERGENCY.
---
### OP_TAKERPAIR
“*...my dream is to contribute to open source software projects even from within an immobile body. That will be a life very much worth living.*” ~ HF
The third operation is “OP_TAKERPAIR”. The function requires the input of four arguments, the first two arguments are the outpoint referencing the callback of the operation and the next two are the takers spending address and the deposit address of two connected blockchains. The connected chains are inherited from the OP_MAKERCOLL referenced in the OP_CALLBACK which restricts their set type defined in the making transaction.
#### How do I use it?
OP_TAKERPAIR is a bound operation which means it must be included with OP_CALLBACK and a order type such as “OP_MAKERCOLL” or “OP_MAKERAUCT”. The operation is used to create marketplaces of between blockchains or data feeds connected to the Block Collider or Super Collider in which it is used. OP_TAKERPAIR orders support partial orders, incomplete order types, and schnorr based anonymous transactions.
---
### OP_NONCELOCKBL
“*Conformity is the jailer of freedom and the enemy of growth.*” ~ JFK
The fourth operation is “OP_NONCELOCKBL”. It is critical for use in logistics, transaction miners, insurance linked securities--any event where the real world event is unlocked by providing some level of work to spend. The function requires the input of two arguments, the first argument is a signature signing the work and hash provided and the second is the minimum distance threshold that must be a achieved.
#### How do I use it?
OP_NONCELOCKBL is a very useful tool for setting unique events for transaction mining on Overline or over the network. For example, if a pool of NRG was held in an insurance council event and the council did not meet in a timely manner a to reimburse policy holders a failsale NONCELOCKBL could be allowed to spend the NRG within a window of time proving that either a miner had enough CPU power to capitalize on the event or that enough policyholders got together to mine together to unlock the NRG in the event the council failed to convene.
___
### OP_X
“*Success consists of going from failure to failure without loss of enthusiasm.*” ~ WC
The fifth operation is “OP_X”. OP_X is a dictionary tool which allows new external data protocols to be added which would traditionally trigger a hard fork on a multichain. The function takes two arguments, the id of the dictionary to be used and the data (up to 64 characters) which is processed by the dictionary and subsequently by the nodes or miners supporting the dictionary.
#### How do I use it?
OP_X is first used by vanity addresses to simplify trade through human readable addresses 12 characters addresses. These addresses can also be exchanged. OP_X is also used to incorporate the entire Mathematics Subject Classification dictionary allowing academics to submit research to request grants or build upon previous work. A dictionary is also used by supporting nodes which interact over the FIX protocol allowing traditional turret data streams to consume and post orders to Block Collider.
___
### OP_MONAD
“*All potential energy exists in the ether. It may vibrate, and it may rotate, but as regards locomotion it is stationary—the most stationary body we know: absolutely stationary, so to speak; our standard of rest.*” ~ OL
The sixth operation is “OP_MONAD”. This is a bound function meaning that it requires specific operations to also be included in the script. The operations required for OP_MONAD are “OP_MONOID” and or “OP_CALLBACK”. OP_MONAD defines a nested section of the script which means that all the operations after OP_MONAD until OP_ENDMONAD are pushed onto a separate stack. One of the output scripts of the given script matches the stack exactly of OP_MONAD.
#### How do I use it?
OP_MONAD is used to require a separate operation to be a part of any spending transaction. In BORDERLESS operations OP_MONAD is used to have uncollateralized operations automatically return to the counterparty of the trade regardless of whichever part spends the collateralized NRG. OP_MONAD protects isomorphism for NRG value which was injected into the script in a monadic operation. OP_MONAD could be considered the inverse of OP_MONOID in that OP_MONAD an endofunctor (typed output) and OP_MONOID is the set creating functor (typed input). For more information on Monoids/Monads: https://www.youtube.com/watch?v=DiisKQAkGM4
___
### OP_MINUNITVALUE
“Look deep into nature, and then you will understand everything better.” ~ AE
The seventh operation is “OP_MINUNITVALUE”. The function takes one argument, a numeral value. The value defines a unique equality constraint among the outputs. When the operation is run each output value when the value is the divisor must be equivalent. The restraint could be compared to how OP_MONAD locks in a required script among the outputs. OP_MINUNITVALUE assigns how the outputs divide the NRG captured in the contract.
#### How do I use it?
OP_MINUNITVALUE is most commonly used in collateralized NRG events such as those found in chain-to-chain interoperability contracts. For example, if a two individuals are participating in the BTC-ETH marketplace on Borderless the OP_MINUNITVALUE is set to “2” when the Maker and Taker have matched. This ensures that when the maker or taker spend the value of collateralized NRG they each receive their respective NRG back.
___
### OP_BLAKE2BLC
"*Thus, a good man, though a slave, is free; but a wicked man, though a king, is a slave. For he serves, not one man alone, but, what is worse, as many masters as he has vices.*" ~ SA
The eighth operation is “OP_BLAKE2BLC”. The function takes one argument, a string. The string is then hashed twice with two forms of the BLAKE2B hash, in order BLAKE2BL then BLAKE2BLS. The operation returns a 40 character string.
#### How do I use it?
BLAKE2 consistently shows performance gains over the traditional SHA256 and SHA328 and Keccak hashing algorithms. In many use cases especially when operating in a 64 bit environment these gains can be 200%. OP_BLAKE2BLC is a compressed form of a double BLAKE2BL hash which decreases the size and therefore fees of all transactions which use it. To learn more about Blake2: https://blake2.net/acns/slides.html
___
### OP_CHECKSIGNOPUBKEY
*"The supreme art of war is to subdue the enemy without fighting.""* ~ ST
The ninth operation is “OP_CHECKSIGNOPUBKEY”. The function takes two arguments, message and a signature. From these it rebuilds a Schnorr Signature based cryptographically sound public key. The operation is used in classic lock/unlock transactions of Block Colliders.
#### How do I use it?
OP_CHECKSIGNOPUBKEY allows users to lock transactions to specific public key combinations without revealing the public key until the transaction claimant provides a spending output. The transaction can become zero-knowledge if the underlying message included is also a public key. Most importantly two parties can confirm a transaction knowing only the source or the destination. The operation is lite and the proof does not requires a full-node sync to confirm.
___
### OP_MARK
“*A good atmosphere and smart people can accomplish a lot.*” ~ JS
The tenth operation is “OP_MARK”. The function a.k.a. takes three arguments, the expiration block height, the blockchain or dataset key, and a public key in address form. The operation uses a an additional fee function called the “window fee”. This fee is calculated based on the size of the window of the operation as set by the expiration block height and an multiplier unique to the operation.
#### How do I use it?
OP_MARK enables users to establish individual marketplace operations which require events to take place on a given blockchain. For example, a shipping company could sell the transport of a product to a destination based on the address given by OP_MARK and a custom smart contract on Ethereum. Or an initial coin offering could specify the award value for deposits to a specific Bitcoin transaction. Most commonly OP_MARK allows the sale of individual good or products for a fixed value.
___
### OP_DEPSET
*"The human spirit, driven by an invincible force, will never cease to ask: What is beyond?"* ~ LP
The eleventh operation is “OP_DEPSET”. The function three numeral arguments the shift operator, the deposit height, and the settlement height. The operator is in a class of operations which use elements from the operating environment which includes the input transaction, outputs, and callback references. OP_DEPSET adds the shift operator to the multichain height at which the transaction has entered the block and adds the resulting number to both the deposit and settlement height. OP_DEPSET returns a numeral indicating which the window in which the current evaluation is being run.
'0' FALSE no start block or outpoint block provided
'1' TRUE deposit settlement restrictions lifted
'2' DEPOSIT transaction operating within deposit window
'3' SETTLE transaction operating within settlement window
#### How do I use it?
OP_DEPSET allows users to define windows of block heights for time relevant logic. While the operation can be used in many ways, the most common use case became the name of the operator or “the deposit and settlement” windows of a trading operation between blockchains. For example, a Market Maker defines different operations to enforce how quickly an order on Borderless (or any other marketplace on Block Collider) is settled.
___
### OP_ENVOUTPOINTUNIT
"*Reality is merely an illusion, albeit a very persistent one.*" ~ AE
The twelfth operation is “OP_ENVOUTPOINTUNIT”. This operations does not take an argument and is an environment operator indicated by “ENV” prepending the variable pulled from the environment, in this case “OUTPOINT UNIT”. Every transaction has BTC value operator like Bitcoin, however multichains have both an NRG value and unit operator which restricts outputs to be divisible by the UNIT.
#### How do I use it?
OP_ENVOUTPOINTUNIT is used to add spending rules on transactions. For instance an insurance policy of NRG which is forcibly split into NRG payouts of a minimum unit size. Or it can be used to enforce that outputs return captured collateral in collateralized NRG transactions.
___
### OP_CHECKSIG
“Low-level programming is good for the programmer's soul.” ~ JC
The thirteenth operation is OP_CHECKSIG. BEAM is built on Bitcoin script as a necessary extension to provide multichain logic, however OP_CHECKSIG harkens back it’s roots as original, uncompressed implementation of Bitcoin’s script’s OP_CHECKSIG - it takes a signature and compressed public key arguments and validates that input data match the signature of a public key provided.
#### How to use it
OP_CHECKSIG can be used to lock transactions to a specific public key which is provided as one argument of the opcode. OP_CHECKSIG returns truthy value back onto stack so e.g. OP_VERIFY is suggested to be used for successful BEAM script verification.
___
### OP_PROMISE
*“Look to the past and remember no empire rises that sooner or later won't fall.”* ~ AS
The fourteenth operation is OP_PROMISE. The operation takes four arguments a partial signature, an optional R proof, blockchain to watch, and the tx hash acting as a solution. OP_PROMISE can be used with Schnorr signatures making one or more parties watching the transaction capable of determining the PROMISE’ validity without revealing the solution or the check itself to the entire blockchain. Traditionally a sizable NRG sum is awarded to the individual who can provide the TX hash and R pattern. OP_PROMISE is commonly triggered by miners who are already monitoring the respective connected chain.
#### How to use it
OP_PROMISE allows users to create incentives for miners or rovers to create and submit a complete full signature executing a given transaction on the connected blockchain. This has a wide array of uses, most notably is to create “Bleeding” transactions which trigger in the even a transaction does or does not happen. Learn more about Bleeding transactions: https://docs.blockcollider.org/docs/bleed
___
### OP_DATATOHASH
*"The lessons of competition are lessons for life."* ~ RK
The fifteenth operation is OP_DATATOHASH. The operation takes five arguments, [optional/default 0] threshold numeral, [optional/default 0] hashing algorithm, an address string, partial solution string, and a complete solution hashed with the given hashing algorithm.
In short OP_DATATOHASH creates a communal competition for the discovery of the solution to a particular hash. There are two modes of the operation’s execution…
MODE 1: Threshold.
If the threshold is given the distance between the sum of the hash of the hashing algorithm, address string, and partial solution is compared to the string given as the hex sum. If this is below the threshold and the partial solution hashed is equivalent to hex summed string the operation returns the address string. Otherwise the operation returns false.
MODE 2: Challenge.
If the BLAKE2 hashing algorithm, sum of the address, and the partial solution is equal to the provided sum hash the operation the address string is returns. If not it returns a false.
#### How to use it
The operation draws inspiration from Bitcoin’s pay to hash where if a solution is provided which equates to the given hash the Bitcoin is unlocked. In practice however, this allows the miner to steal the solution reward sending it to the miner’s address. OP_DATATOHASH on the other hand allows miners to organize to discover the hash of solution. When a discovery is made the miners can also mine for with the solution to achieve a threshold which makes stealing the transaction irrelevant or untimely. The given owner address can also be a Schnorr public key which when combined with a set of addresses incentivizing pools of miners to seek the solution to the hash.
___
### OP_VERIFY
*“Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better. “* ~ ED
The sixteenth operation is OP_VERIFY. It goes back to event Bitcoin script roots – Forth and other stack-based languages. Usually an operation leaves result of its computation on the stack. OP_VERIFY consumes the topmost item on the stack and checks if the value on the stack is zero. If so, it terminates the script with failure.
#### How to use it
OP_VERIFY is used for checking the result of a previous operation - use it wherever you want to check result of previous opcode(s) operation result.
___
### OP_FIX
*“ A vision without a strategy remains an illusion.”* ~ LB
The seventeenth operation is OP_FIX. The operation a supported service flag (SSF) which means that it is used by external APIs or protocols such as FIX, HTX, or TOR. All SSF operations must have a minimum of one argument but may scale up to 16 depending on the external service the operation references. OP_FIX which will be released in the third quarter of 2019, this network wide optional upgrade enables nodes with FIX2 and FIX-GLA high speed trading functionality to interact with decentralized marketplaces built on Block Collider.
Block Collider’s OP_FIX syntax come from the standard defined by the CBOE Futures Exchange which can be viewed here: http://cdn.batstrading.com/resources/membership/CBOE_FUTURES_EXCHANGE_FIX_SPECIFICATION.pdf
#### How to use it
OP_FIX allows traditional data feeds and order book operations to be implemented into trading systems with minimal software overhead. Multichains incentivization of timely updates of the blockchains they contain make them ideal for organizations making data driven decisions. Nodes on Block Collider that enable OP_FIX can stream data automatically from all decentralized marketplaces operating on Block Collider without any data processing. Bringing fair, open, and performant trading tools to consumers is the logical evolution of global borderless markets.
___
### OP_ENVOUTPOINTHASH
"I know in my heart that man is good. That what is right will always eventually triumph. And there's purpose and worth to each and every life." ~ RR
The eighteenth operation is OP_ENVOUTPOINTHASH. This operations does not take an argument and is an environment operator indicated by “ENV” prepending the variable pulled from the environment, in this case “OUTPOINT HASH”. When queried the operation returns the hash of the transaction from the value has been transferred.
#### How to use it
Users can restrict the context from which certain operations run. For example, a transaction could be written which requires the amount to be spent from a particular address. This is useful to add an additional protection to MONAD operations which leave the logic context of the chain. Since these have side effects which are difficult to calculate for new programers they can restrict spending of the transaction manually by locking it to a specific outpoint hash.
___
### OP_CALLBACK
*“from one thing, know ten thousand things”* ~ MM
The nineteenth operation is OP_CALLBACK. The OP_CALLBACK operation is in the bound class of operations such as OP_TAKERPAIR or OP_MAKERCOLL. OP_CALLBACK takes only two arguments, outpoint transaction hash and the index of the output in reference. OP_CALLBACKs are restricted to hierarchical operations otherwise BEAM would be capable of loops and or turing complete.
#### How to use it
OP_CALLBACK allows users to spend NRG locked in a OP_MONAD operation. The hash and index serves as a reference for the compiler to inject and evaluate the script at that location into the in the current operating context. The initial use of OP_CALLBACK is to support partial orders unlike Atomic Swaps which force the complete transfer of value. In a broad scope users can reference any monadic code in Block Collider.
___
### OP_ENVOUTPOINTLOCKTIME
*"If a machine is expected to be infallible, it cannot also be intelligent."* ~ AT
The twentieth operation is OP_ENVOUTPOINTLOCKTIME. This operations does not take an argument and is an environment operator indicated by “ENV” prepending the variable pulled from the environment, in this case “OUTPOINT LOCKTIME”. When queried the operation returns the locktime numeral of the transaction referenced.
#### How to use it
“Lock time” means that the transaction cannot be valid until a certain time. Uniquely the operation can be used to restrict transactions that spend it with special case lengths of time. For example, if a service must be performed the lock time can return NRG back to a escrow account until a given lock time elapsed and the funds can be released. Or users can signal an attractive rate NRG rate to the open marketplace but restrict uses from spending the benefit of this pair until a height which would draw more liquid NRG if needed.
___
### OP_ENVOUTPOINTVALUE
*“A dream doesn't become reality through magic; it takes sweat, determination and hard work. “* ~ CJ
The twenty-first operation is OP_ENVOUTPOINTVALUE. This operations does not take an argument and is an environment operator indicated by “ENV” prepending the variable pulled from the environment, in this case “OUTPOINT VALUE”. When queried the operation returns the value numeral of the transaction referenced.
#### How to use it
This operation is critical when creating complex assets which require a threshold of value to execute a given operation. For example, a transaction may promise an attractive pair if it is given NRG liquidity of a minimum value. The BEAM script ensures that before the transaction can be spent (thereby becoming an outpoint of the spending transaction) that a given threshold is achieved. Another use case is when hosting a multichain coin offering which requires an amount of NRG in order to make claims of a given asset.
___
### OP_Q
*“If the whole universe has no meaning, we should never have found out that it has no meaning: just as, if there were no light in the universe and therefore no creatures with eyes, we should never know it was dark. Dark would be without meaning.”* ~ CSL
The twenty-second operation is OP_Q. This operation takes four arguments, previousHash a string, dataBytes a numeral, dataHash a string hash of the data requested, and networkAddress which is optional, an IP or the category to be broadcast. This operation is part of INFINITE QUERY which is enabled on machines that have local storage. The networkAddress when used acts to validate the source of the document or assist in routing the document to it’s requestors destination. OP_Q transactions do to not modify the stack which means that they are added to the output script of a transaction (which is one NRG fee) and then that transaction is spent (triggering the evaluation of the OP_Q). To prevent bandwidth abuse OP_Q memory is limited to the last 2000 blocks of the network which adds a timeliness to the data being requested or cascaded through the network.
#### How to use it
OP_Q in it’s most simple form is a method by which a peer could query the network for data which matches a given size and category. OP_Q differs from a traditional data storage network in that there are NRG fees to request it and no guarantee the document will be received. However, uniquely, the protocol cascades the query which means that if any node does have the document in question they cascade it to local peers. In this way it creates a reverse ‘attention’ economy in that the query if resolved correctly the result becomes a broadcast propagated through the network OP_Q as a result is like a ‘push notification’ for decentralized networks. In other words you can pay for the attention of the network so long as you were truthful regarding the size and hash of the data which you want them to be aware of.
Notably OP_Q includes a previous hash and next hash which allows chunked requests. The peer can use these hashes to determine the bandwidth of the peer requesting the data and respond accordingly. In theory this could allow entire open source operating systems to be transmitted through the network.
___
___
## Overwiew Table
| Operation | Arguments |
| -------- | ---------- |
| OP_MONOID | ... |
| OP_EMERGENCY | - Expiration block height (required)<br>- Super Collider reference (optional)<br> - An event public key. () |
| OP_TAKERPAIR | the first two arguments are the outpoint referencing the callback of the operation and the next two are the takers spending address and the deposit address of two connected blockchains. |
| OP_NONCELOCKBL | - A signature signing the work and hash provided (required). <br>- The minimum distance threshold that must be a achieved. (required) |
| OP_X | - The id of the dictionary to be used<br>- The data (up to 64 characters) which is processed by the dictionary and subsequently by the nodes or miners supporting the dictionary.|
| OP_MONAD | (OP_ENDMONAD) |
| OP_MINUNITVALUE | The function takes one argument, a numeral value. |
|OP_BLAKE2BLC| The function takes one argument, a string. |
| OP_CHECKSIGNOPUBKEY | - Message <br> - Signature|
|OP_MARK| - Expiration block height<br> - Blockchain or dataset key<br> - Public key in address form.|
|OP_DEPSET|- Shift operator<br>- Deposit height<br>- Settlement heigh|
|OP_ENVOUTPOINTUNIT|(none)|
|OP_CHECKSIG|a signature and compressed public key|
| ...|...|
|(TODO)|
___
## Other Official Resources
- Telegram: http://www.t.me/blockcollideradvanced
- Docs: https://docs.blockcollider.org/docs
- Whitepaper: http://blockcollider.org/whitepaper
- Email Campaign Archive (An overview off all newsletters sent by team): https://us16.campaign-archive.com/home/?u=1ab67a42a7e778dc48c55d3b9&id=73e1cc758f