In this paper we analyze the main issues that arise from storing educational recordsin blockchain and propose the architecture of the Disciplina platform – a domain-specificblockchain implementation. The platform is designed to act as a decentralized ledger, withspecial regard for privacy and mechanisms of data disclosure. We present an overview of themain entities, their roles and incentives to support the network. Please note that the projectis a work-in-progress and the descriptions provided are subject to change.

1

Introduction

Recent advances in blockchain technology and decentralized consensus systems open up new possibilities for building untamperable domain-specific ledgers with no central authority. Since thelaunch of Bitcoin [9] blockchains had been primarily used as a mechanism for value transfers. Withthe growth of the Ethereum platform [13], the community realized that by using a chain of blocksand consensus rules one can not only store value and track its movement, but, more generally,store some state and enforce conditions upon which this state can be modified.Bitcoin, Ethereum and other permissionless blockchains were developed with the assumptionthat everyone is free to join the network and validate transactions, that are public. However, theindustry often requires privacy, and thus the permissive solutions with private ledgers came toexist. These solutions include Tendermint [6], Hyperledger [2], Kadena [4] and others.The increased interest and the variety of the blockchain technologies lead to the growth of theirapplication domains. The idea of storing educational records in the blockchain has been circulatingin the press and academic papers for several years. For example, [12] and [3] focus on the onlineeducation and propose to create a system based on the educational smart contracts in a publicledger. Recently, Sony announced a project that aims at incorporating educational records in apermissioned blockchain based on Hyperledger [11]. The ledger is going to be shared betweenmajor offline educational institutes.The main issue these solutions have in common is that they target a certain subset of wayspeople get knowledge. We propose a more general approach that would unite the records of largeuniversities, small institutes, schools and online educational platforms to form a publicly verifiablechain. Contrary to the solutions like Ethereum, we do not aim at proposing a programmableblockchain that fits all the possible applications. Rather, we believe, that we should harnessall the latest knowledge that emerged in the last few years in the fields of consensus protocols,authenticated data structures and distributed computations to offer a new domain-specific ledger.In this paper we introduce Disciplina — the platform based on blockchain technology that aims totransform the way educational records are generated, stored and accessed.

2

Architecture overview

Due to the nature of the platform, it has to operate on sensitive data, such as courses, assignments,solutions and grades. Permissionless blockchains, like Ethereum or EOS, would require disclosing1

this data to the public, whereas the permissive ones, like Hyperledger, lack public verifiability. Ourarchitecture splits the blockchain into two layers: the private layer contains sensitive data, andthe public one contains the information necessary to validate the integrity and authenticity of the

private blocks. The key entities of the proposed blockchain architecture are presented in Figure 1.

Figure 1: Key entities of the Disciplina platformThe private layer is maintained by each Educator independently of others. Educators canbe either large educational institutes, capable of running their own nodes, or some trusted partythat runs the chain for the self-employed teachers and small institutions. This layer containsthe personalized information on the interactions between the students and the Educator. All theinteractions, such as receiving an assignment, submitting solutions, or being graded, are treatedas transactions in the private chain.Students get access to the platform through web and mobile applications. Using the applicationsthey choose Educators, enroll in courses, get assignments and submit solutions. The scores and thecriteria of whether the Student has finished the course successfully are determined by the Educator.The education process from the platform’s perspective is as follows:1. A Student chooses an Educator and a course that she wants to enroll in.2. If the course is offered on a pre-paid basis, the Student uses her app to pay the fee.3. During the course, the Educator provides assignments that the Student has to complete inorder to get the score.4. The Student acquires the assignment, completes it and sends the signed solution back to theEducator (communication between the Student and the Educator happens off-chain).5. The Educator then stores the solution locally, grades it with a score in range [0..100], andtransfers the score with the hash of the solution to the blockchain.6. Upon the completion of the course, the Student acquires a final score based on the scores shegot for her assignments. This final score is also added to the Educator’s chain.Making the Educators’ chains private opens the possibility for Educators to tamper with thedata in their chains. To overcome this issue and make the private transactions publicly verifiable,we introduce the second, public, layer of the blockchain. The public part of the network consistsof Witnesses — the special entities that witness the fact that a private block was produced by anEducator.They do so by writing the authentication information of a private block into the public chain,which is used in the future by an arbitrary Verifier to substantiate a proof of transaction inclusion2

given to it by a Student or an Educator. Witnesses also process public information issued by theEducators, such as announcements that an Educator has started or stopped offering a course ina particular discipline. The Witnesses agree on which public blocks are valid using the specifiedconsensus rules.The Recruiters are the entities interested in gathering data about students from educationalinstitutions. They buy this data from Educators using a secure data disclosure protocol, describedin detail in section 3.7. Validity and security of every data trade is also ensured by Witnesses,because corresponding transactions and actions of each party are also stored in public blockchain.

3

Implementation choices

In this section we describe the proposed architecture in more detail. We present the excerpt onthe internal structure of both public and private chains and the reasoning behind these choices.In order to deduce the internal structure of our system, we first analyze its use-cases. Theoverview of the education process is given in Section 2. The communication between the Studentand the Educator is saved as transactions in the private chain. However, the implementationdetails of this chain mostly depend on the data disclosure process.We will start from analyzing this process and determining the main issues that arise from theneed to disclose and verify the validity of the private blocks. Then we will propose the structureof the private and public blocks that addresses these issues.

3.1

Anonymity and certification

The permissionless nature of our public chain leads to the ability for malevolent students to createeducational institutes in order to get the scores for the courses they did not attend. Moreover,the knowledge students actually get by completing the course, and the conditions upon which thecourse is considered completed, vary significantly between the educational institutions.These issues currently can not be solved solely on the protocol level: they require an externalsource of information to determine the physical existence and the reputation of an Educator.Although we leave the public chain open for the Educators to submit their private block headers,we propose to add a separate layer of reputation and trust on top of the protocol.We do so by disallowing a new Educator to join the network without an approval from anotherEducator. Educators are supposed to rate another Educators basing on off-chain sources of information – such as a publication on an official site of a university, which claims that given Disciplinapublic key is issued by this university. By approving each other, Educators form a web of trust.Ratings of Educators are backed up by ratings of Educators which trust them.

3.2

Activity Type Graph

When a Recruiter makes a request to one of the Educators, the Educator has to provide as minimalset of entries as possible. This set has to be verifiable, which means that the Educator providesthe proof of the data validity along with the data being disclosed.In order to achieve these goals, we divide the data that the Educators store into atomic ActivityTypes. Each Educator maintains a journal of transactions per each Activity Type that the Educatoroffers.All the Activity Types are grouped into courses that are further grouped into larger entitiessuch as subjects and areas of knowledge. This grouping can be stored as the Activity Type GraphGA with the following properties:1◦ GA is a directed graph:GA : V : {Vert}, eout : Vert → {Vert} | rest

The example of the Activity Type Graph (ATG) is shown in Figure 2. The vertex v of thegraph is a leaf if eout (v) = ∅. Otherwise we call it an internal vertex. Every internal vertex of thegraph has a special etc. child (some of these are ommitted in the figure).

Figure 2: An example of the Activity Type Graph. Some of the vertices are not shownThe need for etc. vertices arises from the fact that not all of the Educators teach coursesexactly in leaves — some of them offer general courses that provide just the necessary background.For example, some of the universities teach the basic “Computer science” course, that contains thebasics of the discipline. In this case, when the particular category is hard to define, the universitywould use the etcComputerScience vertex.On the protocol level, the Educators can announce that they teach a particular course, but cannot modify the Activity Type Graph structure. The structure of the graph is maintained by thecore developers and updated upon request from the Educators.For every pair of vertices (v, u), weight(v, u) defines how the score of a course from the fieldof study u affects the summary grade for the field of study v. Let’s define weight(v, u) =(d(u) − d(v) + 1)−1 if u reachable from v, and weight(v, u) = 0 otherwise. The motivation ofthe aforementioned weights is that less specific subject implies the wider knowledge. After that wecan define avgGradessubjectId as a weighted average with weights described above.

3.3

Search queries

An educator can answer one of the following queries:• For a set of pairs (subjectId1 , minGrade1 ), (subjectId2 , minGrade2 ), ..., (subjectn , minGraden )and some Count, find no more than Count students with grades satisfying the following inequalities:avgGradesubjectId1 >= minGrade1 avgGradesubjectId2 >= minGrade2...avgGradesubjectIdn >= minGraden• For the given identifier of a student, return all info about this student.• For given assignment hash, return the document itself.4

3.4

Private chain

Every educator has a private chain. It stores the data about students, and can generate answersfor the queries described above.Private chain comprises of two main data structures:• Set of transactions batched into blocks. Every block contains a list of transactions packedinto a Merkle tree.• Links to the transactions stored in the B+-tree with keys (studentId, studentGrade). Indexesconstructed in such a way that more popular activities go first.The structure of the private block is shown in Figure 3. The block consists of a public headerthat the Educators relay to the Witnesses, and the private body that remains in the educationalinstitute until it receives a data disclosure request.

Figure 3: Private block structureDuring the educational process the Educators emit atomic private transactions. These transactions represent the modifications to the journal of academic achievements (thus, making a transaction means appending the data to the journal). The transactions can be of the following types:• student enrolls in a course;• student gets an assignment;• student submits an assignment;• student gets a grade for an assignment;• student gets a final grade for the course.The first two types should be intiated by a student, and should include student’s signature toprevent spam from partially-honest educator. The structure of the transaction is shown in Figure 4.iLet us denote an i-th transaction in a block as Tpriv. The Educators group the transactionsthat occured during the current block time slot, and construct a Merkle tree [8] for these journalmodifications:iMpriv = mtree({ Tpriv})

(5)

The Educator’s private block body comprises an ordered set of Merkle-authenticated transactions. These transactions are indexed so that the Educator can quickly find a particular transactionthat satisfies some predicate.

5

Figure 4: Transaction structureThe private block header consists of the transactions Merkle root along with the previous blockhash and the information on the Activity Type Graph modifications (ATG delta). The ATG deltapart allows the Educators to inform the Witnesses of the modifications to the courses they teach.An Educator collects private transactions into the blocks with no more than Kmax transactionsper each block. After that, an Educator submits signed block header to the Witnesses so thatprivate transactions can be confirmed by the public chain. Thus, the private blocks form a publiclyverifiable chain of events.

Figure 5: Example of sized Merkle treeTo incentivize Witnesses to include private block headers into the public chain, an Educatorshould pay some amount of coins per each private block. We should take into consideration thatan educator may be both a local tutor and some big university. Depending on that, a numberof transactions per each block, as well as paying capacity, may differ. So the cost of a digestpublication should linearly grow with the size of a block. Let the cost for publishing a public blockheader beCpub (B) = αpub + βpub · Ntr (B)(6), where Ntr (B) is the number of transactions in private block B and αpub and βpub are parametersof the network – a small constant fee and a linear price coefficient accordingly.To achieve the ability to prove the number of transactions in the Merkle tree, we will storeit together with a hash in each node (as shown in Figure 5). The proof will only be valid if theEducator fills in the sizes correcctly, so there is no incentive for Educators to lie about the size ofthe tree.We also consider a possibility for small educators to form pools and release blocks together inorder to reduce costs for each individual educator. See appendix A.2 for details.

6

3.5

Public chain

The Witnesses maintain a public chain – a distributed ledger that contains publicly availableinformation. If one wishes to perform a transaction on the public chain, she has to pay a certainfee that serves two purposes. First of all, the fee incentivizes the Witnesses to participate in thenetwork and issue new blocks. Second, by requiring a fee for each transaction, we protect thepublic ledger from being spammed.We present the structure of the public blocks in Figure 6. The public ledger contains thefollowing information:1. Modification history of the Activity Type Graph.2. Private block headers.3. Account balances and value transfer history.

Figure 6: Public block structureThere are two major ways to store the account balances and other state information: UTXO andaccount-based architectures. UTXO is an unspent transaction output, that contains some predicate– a condition that has to be fulfilled in order to spend the coins. To prove the money ownership,the spender provides a witness – an input that makes the predicate true. Thus, the UTXO-basedarchitecture requires the transactions to be stateless, effectively limiting the application domain [1].The unspent outputs with an associated state can be treated as smart-contracts in the accountbased architectures like Ethereum [13]. The state is stored in an off-chain storage – the statedatabase. The transactions are treated as the modifications of the world state.Disciplina uses an account-based ledger with contracts programmable in Plutus language [7].Each account has an associated state, which comprises the account balance and other information(e. g. log L of a data disclosure contract). The world state is a mapping between accounts and theirstates. In order to make this mapping easily verifiable, we use a structure called the authenticatedAVL+ tree introduced in [10].The recent achievements in the field of consensus protocols, like the provably secure Ouroboros[5], allow us to build a public chain based on the Proof of Stake consensus rules. Thus, we canincrease the transaction speed and drop the need for the expensive mining.

3.6

Fair CV

One of the main goals of the Disciplina platform is to provide a way for the Students to easilyprove their educational records. We propose to duplicate the records in the Student’s digital CV.This CV contains all the records that the parties have generated during the Student’s educationalprocess along with the validity proofs of that data (see Figure 7).In order to prove that some transaction actually occurred in some private block of the concreteEducator, the student has to provide the cryptographic proofs along with the actual data. The7

Figure 7: Student’s authenticated CVcryptographic proof of the inclusion of an element in an authenticated data structure is generallya path of hashes. Let us denote the path of the element e in some authenticated data structure Xas path(e, X). Thus, the Student has to provide the following data:• The Student’s and the Educator’s public keys pkS and pkE .• The course ai and the a private transaction Tpriv with the score.• The Merkle path of the transaction in the journal: Ppriv = path(Tpriv , Mpriv ), where Mprivis a Merkle tree of the transactions in the private block.• The public block number H and the Merkle path of the transaction Tpub that pushed theprivate block into the public chain: Ppub = path(Tpub , Mpub ), where Mpub is a Merkle tree ofthe transactions in the block H.Having this data one can prove the occurrence of a certain transaction in one of the Educator’sprivate blocks without the need to request any data from the Educator during the validationprocess. Thus, any party can check the validity of the Student’s CV for free if the Student wishesto disclose it.Let ρ(e, P ) be the function that substitutes the element e in path P and computes the roothash of the authenticated data structure. Then the validation process is as follows:1. Query the public chain to find the block H and obtain the Merkle root of the transactions:root(Mpub ).2. Check whether ρ(Tpub , Ppub ) = root(Mpub ).3. Check that the public transaction Tpub was signed with the Educator’s public key pkE .4. From the public transaction Tpub obtain the Merkle root of the private transactions: root(Mpriv ).5. Check that ρ(Tpriv , Ppriv ) = root(Mpriv ).These validation steps can prove that an Educator with a public key pkE issued a transactionTpriv in one of its private blocks. One can attribute the pkE to a particular real-world educationalinstitution by checking the Educator’s certificate as described in Section 3.1.

8

3.7

Data Disclosure

Disciplina architecture supports two types of data disclosure requests:1. Request for a set of authenticated private transactions satisfying some predicate (see detailsin Section 3.3)2. Request for object disclosureHere we describe a protocol of fair data trade between the Educator as a seller and someinterested party as a buyer. Despite a few variations the protocol is almost the same for all threetypes of the data disclosure requests. We first lay out the private transactions disclosure protocol.Then we describe modifications to the protocol so that one can apply it to other types of data.The process of data disclosure involves direct communication between a particular Educator E,willing to disclose a part of the data, and an interested party B (e. g. a recruiter), willing to pay forthis data. Suppose E has some data D. In case of private transactions D is a set of authenticatedtransactions, i. e. tuples (Tpriv , Ppriv , H, Ppub ). As shown in Section 3.6 this data along with theeducator’s public key is enough to prove that a certain transaction Tpriv actually occurred in someprivate block of the given educator.The protocol fairness is guaranteed by a contract on the public chain. The contract is able tohold money and is stateful: it is capable of storing a log L with data. All the data that partiessend to the contract is appended to L.1. The buyer B sends a signed search query SigB (Q) directly to the seller E.2. Let D be a set of authenticated transactions relevant for the query Q. E divides D into Nchunks. When disclosing private transaction, one chunk di is a transaction with proofs thatit was included in a certain private block:iiidi : (Tpriv, Ppriv, H (i) , Ppub)

(7)

3. E generates a symmetric key k and encrypts each di with k. Then she makes an array ofencrypted chunks:D = {Ek (d1 ), Ek (d2 ), ..., Ek (dN )}(8)4. E computes the size of the encrypted answer s = sizeof(D ), the cost of this data CD ∼ s,and the Merkle root of the data R = root(mtree(D )).5. E sends SigE (CD , s, R, H(Q)) directly to the buyer.6. If buyer agrees to pay the price, she generates a new keypair (pkB , skB ). Then she initializesthe contract with the data provided by the Seller, search query Q, its own temporary tradepublic key pkB and CD amount of money.7. If E agrees to proceed, she sends a predefined amount of money CE to the contract address.CE is a security deposit: if E tries to cheat, she would lose this money.8. E transfers the encrypted data chunks D directly to the buyer. B computes the Merkleroot R and the size s of the received data D :R = root(mtree(D ))

(9)

s = sizeof(D )

(10)

9. B makes a transaction with a receipt SigB ({R , s }) to the contract address. The partiescan proceed if and only if the following is true:(R = R) ∧ (s = s)Otherwise, the protocol halts.10. E sends SigE (EB (k)) to the contract.11. B decyphers and checks the received data.9

(11)

• In case all the data is correct the Buyer sends a signed accept to the contract.• In case some data chunk ei ∈ D is invalid, B sendsSigB ({ skB , ei , path(ei , mtree(D )) })to the contract. By doing so, B reveals the data chunk di corresponding to the encryptedchunk ei . She also shares proof that ei was indeed part of a Merkle tree with root R.The contract checks the validity of di and decides whether B has rightfully accused Eof cheating.• In case chunks di and dj have duplicate entries, B sendsSigB ({ skB , ei , path(ei , mtree(D )),ej , path(ej , mtree(D )) })to the contract. The contract checks whether di and dj do indeed have duplicate entriesand blames E for cheating if it is true.The contract considers the data chunk di valid if and only if:1. The transaction in di is unique.2. The transaction in di has valid proofs of existence (like described in Section 3.6).3. The transaction in di make the predicate Q true.The on-chain communications of the parties (steps 7, 9, 10, 11) are bounded by a time frameτ . In order for the transaction to be valid, the time ∆t passed since the previous on-chain step hasto be less than or equal to τ . In case ∆t > τ the communication between the parties is consideredover, and one of the protocol exit points is automatically triggered. The protocol exit points aredescribed in detail in Table 1.Table 1: Data disclosure protocol exit pointsCondition

Step

∆t > τ∆t > τR =R

799

s =s

9

∆t > τ

10

∆t > τacceptfrom Brejectfrom B

111111

ConsequenceB, E get their money back because E wasn’t able to correctly transferthe data to B.B, E get their money back because B has received the encrypteddata, but E nas not been able to share the key k for itE gets CE and CD : E correctly shared data to BThe dispute situation. In case B proofs E cheated, E loses hersecurity deposit CE . Otherwise, E receives both CE and CD .

The proposed algorithm (though with some modifications) can be applied to object disclosurerequests. Here we define these modifications:• Q : root(mtree(Object)) – query by the object hash.• di : (chunk , path(chunk , mtree(Object)) – the data being revealed is an object: uncategorized blob of data relevant to a particular transaction. The object is split into chunks of sizeno more than 1 KiB and transferred along with proofs.• Validation: check that a chunk is indeed a part of the object with root Q.

10

4

Future work

The current architecture of the Disciplina platform heavily relies on the fact that a new Educatorshould gain acceptance from other Educator to join the network, and ratings of a new Educatorare determined by other Educators accepting it. However, it is possible that other Educatorswould provide unfair ratings: for example, they could ignore the existence of private teachers, thusmaking their contributions less valuable, or purposefully lower the ratings of competitors enteringthe network.Such problems can be avoided if we carefully integrate the algorithm of rating computationinto our architecture. The ratings would be based on the on-chain sources of information andprovide equal opportunities for both private teachers and large educational institutions. However,integrating the rating system into the arhitecture poses several design challenges that we have tosolve.

5

Conclusion

In this paper we presented the architecture of the Disciplina platform. The described architectureprovides a way to store educational records in the blockchain while preserving the privacy of theserecords. The concepts of private chains and a digital CV make it possible to verify the educationalrecords of a particular person. Educational institutions are connected in a web of trust to providecredibility for each institution and, consequently, to digital CVs of their alumni.We developed our platform not only as the source of trust, but also as a database of the studentsfrom all over the world. We believe that the data that is stored in the system has a value in itself.The need to disclose this data was also addressed in the paper: we described a mechanism for thefair data trade and the measures against the secondary market creation.

In the Section 3.4 we have concluded that the cost of the private block proof publication shoulddepend on the size of the corresponding Merkle tree. This is done in order to scale spendings ofdifferent educators with amount of data they produce and store in their private blockchains.But this solution has a disadvantage: the Witnesses are more incentivized to include proofs fromlarge educators in public blocks rather than from small educators, as proofs from large educatorscontain more fees. If block size is limited, it may lead to delays of inclusion of small educators’proofs in the public blockchain.In order to resolve this problem, small educators can use trusted third-party services (e. g.teachmeplease.com) for interacting with Disciplina platform instead of running Educator nodesby themselves. But this means that third-party service has access to all the educator’s data,including marks and assignments of her students, and also receives all the revenue for trading thisdata. Some small educators might find this option unacceptable.Therefore, we propose a mechanism of educator pools, which allow small educators to delegateblock proof publishing to a third party in a partially trustless way.The idea is the following:• Every small Educator still maintains her own small private chain• When a small Educator forms a block in her private chain, she sends the block header toa third party called pool manager instead of publishing it directly to Witnesses. Anotherdifference is that Educator should also send a separate signature for her ATG delta (if it’snot empty).• A pool manager collects block headers from Educators until total number of transactions inall Educator’s blocks is more than some threshold Kmin .• Then pool manager builds a sized Merkle tree over the list of received Educator’s blockheaders, forming a second-level block (Fig. 8). The header of second-level block gets publishedon the public blockchain. Instead of containing a single ATG delta, the header of this secondlevel block contains a list of separate signed ATG deltas of small educators. We assume thatthis approach would not create a problem of oversized block headers because Educators don’ttypically create and close courses very often, and an average number of ATG deltas in everysingle block header will stay small.1 The

particular keys pkA and skA belonging to the party A are generally deducible from the context

12

Figure 8: Two-level hierarchical sized Merkle tree for a block published by a pool manager• After constructing a second-level block, pool manager sends each of the small Educators apath to their block headers in a second-level sized Merkle tree.• Having this path, each Educator can construct a publicly verifiable proof for any transactionin her private block by simply concatenating this path with a path to transaction in a firstlevel Merkle tree.For every processed block header small educator pays pool manager a fee calculated by thisformula:Cpool (B) = αpool + βpub · Ntr (B)(12)where βpub is a network price coefficient from 6, and αpool is a constant fee set by the pool manager.If a pool manager sets such αpool that αpool < αpub , but αpool N > αpub , then for every publishedsecond-level block a pool manager gains αpool N − αpub coins, while every Educator in pool paysless for the block header publishing then if published directly to Witnesses. Therefore, everyparticipant has an incentive to remain in the pool.Note that a small Educator participating in the pool should slightly change the structure of hisown chain. Every block header should contain a hash of previous one (as described in Section 3.4),but blocks of an Educator participating in the pool are published only as part of second-levelpooled block. So the educator’s block header should contain a header hash of a second-level blockcontaining previous first-level block in educator’s chain instead of header hash of previous first-levelblock.We don’t yet provide a fully trustless solution for pooling. Small Educators should trust a poolmanager to provide correct second-level proofs of their blocks, and in theory an adversarial poolmanager may cheat on Educators by not including their block headers in a published second-levelblock after she received the money. However, we assume that deceiving the small educators andlosing them as a long-term clients is far less profitable than being honest. Nevertheless, we arecurrently working on a fully trustless pooling protocol based on a smart contract which ensuresthat a pool manager cannot deceive any Educator.

A.3A.3.1

Smart-contract implementationAccounts

There are 2 kinds of accounts:• Personal: created for each client, directly belongs to that client;

13

• Robot: created by client, doesn’t belong directly to that client (and anyone else); representssmart contract.Robot account should contain, aside from token mapping:• Data storage for smart contract state;• The code to control the account, compiled to Plutus Core language.The Plutus Core language allows declaring a module with exported (public) methods. Thesemethods will be the public API for the account.One can evaluate the Plutus Core code itself (not just call public methods) if account directlybelongs to her. Personal accounts don’t have any persistent associated code to control them.A.3.2

Scripting

The Plutus language will be used to program Robot nodes. Any interaction with account is donevia Plutus code.The evaluation cost is collected and summed into Fee.“Sandbox run” can be performed, to check costs and programming errors.We will call natively-implemented functions to be called from Plutus Core “NIFs”.Each atomic step of execution has an invocation cost.A.3.3

NIFs

NIF is an action to be invoked on Account. NIF is the only source of changes in Account.Any operation on the Account to be implemented should be represented as a call to NIF ORas a sequence of NIF-calls. This will allow us to reason about security/validity of operations withmore confidence and limit the access and scope of each operation.A.3.4

Transaction

We will cover “simple money transfer” and “data disclosure” transactions in this section.“Simple money transfer” transactions will be implemented as transactions with empty “functioncall” field.Transferral transaction must contain:• Sender signature;• Receiver signature;• Amount and kind of funds transferred (must be non-zero overall);• “Nonce” to prevent double-invocation.• (Optional) textual message for the receiver;• (Optional) function call to be invoked upon transaction approval.• Digest of all other fields, encrypted with Sender private key.Transaction is the only way for accounts to interact.Function call (if present) will contain the name of exported function and arguments to besupplied upon invocation.The function would be invoked like that:function-name(Sender-signature, amount, value1, value2, ..., valueN)On successful code invocation, money will be transmitted to the Target account and the costswill be demanded from the Sender. If the code fails, the transaction is not published as successfuland is rejected.If there is not enough money supplied for the operation or the code raised an error, wholetransaction will fail.If there is no function call in a transaction, the code invocation is assumed successful.The Gas fee for transaction approval will be calculated as sum of costs for atomic actionsperformed.14

A.3.5

Implementation of the data disclosure protocol using Robot account

We assume that we have 2 sides:• Buyer• Seller.“Gas” below is the estimation of the operation cost. The name and the idea are taken fromEthereum. “Fee” is a forfeit to either side trying to deceive the opponent. “Sum” is the price of thedata to be sold.Robot would work as follows. The Buyer invokes a transaction which runs code directly on hisaccount, that constructs a robot with the following exported methods:•

start-trade();

•

accept-encrypted(encrypted-mroot, size);

•

send-encrypted-secret(encrypted-secret);

•

handshake();

•

reject(sk, block, proof-enc);

•

cancel(),

carrying Sum + Fee + Gas amount of currency and some predicate to check the data if applicable.This robot is initialized with the following data:• Cost in tokens;• Size of the encrypted data;• Merkle tree root of encrypted data;• Timeout, after which the account is destroyed;• Sink, a person whom the remaining money will be send on timeout;• Destructor, a procedure to invoke on timeout.Here is the state machine of that Robot-account:(0) Account has just been created."start-trade" from SellerWHEN transferred amount = FeeNotify BuyerAND GOTO 1(1) The trade is started."accept-encrypted(encrypted-mroot, size)" from BuyerIF encrypted Merkle root and size are the same as initially set in Robot state,GOTO 2ELSEGOTO 8Timeout!GOTO 8(2) Data was transferred. Seller encrypts a session key with the Buyer’s public key."send-encrypted-secret(encrypted-secret)" from SellerNotify Buyer(3) Off the band, the symmetric key is sent."reject(sk, block, encrypted-proof)" from Buyer15

GOTO 4"handshake" from BuyerGOTO 5Timeout!GOTO 6(4) Arbitration.The robot performs check.If it finds that Buyer is right (block invalidates proofs OR the predicate fails),GOTO 7else if Seller is rightGOTO 6(5) Cleanup I.(Sum + Fee) is sent to Seller.GOTO 7(6) Cleanup II.All remaining money is sent to Seller.The account is closed.(7) Cleanup III.All remaining money is sent to Buyer.The account is closed.(8) Cleanup VI.Fee is sent to Seller.GOTO 7

A.3.6

Example

Lets assume there are:• Seller, which has declared that he has his students’ Linear Algebra marks for Nov, 2018 worth500 tokens (signed in some private Merkle tree);• Buyer, which has 600 tokens available.• Robot, which is a smart account created by the Buyer.We will consider three cases:• Seller sends nothing at all;• Seller tried to send Buyer encrypted garbage instead of data;• Buyer tried to blame Seller in giving her invalid data with data being completely valid (interms of proofs and predicate).All trades will have same initial part, so we will branch when nessessary. The trades will go asfollows:• The Buyer formulates a predicate to check that data corresponds its description OR usesuniversal truth as predicate.• The Buyer requests the data from the Seller.• The Seller notifies the Buyer of the data price (500 tokens).• The Buyer creates a Robot using the scheme above with 500 tokens and the predicate.16

• The Seller accepts the trade and sends start-trade() to the Robot along with 20 tokensFee.1. Seller sends badly sized data or the Merkle root of the encrypted data does not match:– The size or the Merkle root of the transferred data is invalid.– The trade is stalled until time is out.– On timeout the trade is reverted and money is returned to Buyer.2. Seller tries to send garbage or one of blocks decrypts to garbage:––––

Buyer finds that at least one block is invalid in either form.She invokes reject(sk, block, encrypted-proof) to start arbitration.Robot checks that block falsifies proofs and that Buyer was right.Robot returns all remaining funds to Buyer.

3. Buyer tries to blame Seller with valid data:– Buyer selects the block to call “invalid”.– Then she invokes reject(unencrypted-block, proof) to start arbitration.– Robot performs check-block-and-proof(block, proof) and finds that Buyerwas not right.– Then it sends all 520 tokens to Seller.4. Buyer receives the data and the key, but remains silent:– If the timeout has expired, 520 tokens are sent to Seller.