2.2.3 Network level defense In addition, the shell is “defensive”. It attempts to connect to many peers across various IP ranges. It detects disconnected peers and bans malicious nodes. To protect against certain denial of service attacks, the protocol provides the shell with context dependent bounds on the size of blocks and transactions. 2.3 Functional representation 2.3.1 Validating the chain We can efficiently capture almost all the genericity of our abstract blockchain structure with the following OCaml types. To begin with, a block header is defined as: type raw_block_header = { pred: Block_hash.t; header: Bytes.t; operations: Operation_hash.t list; timestamp: float; } We are purposefully not typing the header field more strongly so it can represent arbitrary content. However, we do type the fields necessary for the operation of the shell. These include the hash of the preceding block, a list of operation hashes and a timestamp. In practice, the operations included in a block are transmitted along with the blocks at the network level. Operations themselves are represented as arbitrary blobs. type raw_operation = Bytes.t The state is represented with the help of a Context module which encap- sulates a disk-based immutable key-value store. The structure of a key-value store is versatile and allows us to efficiently represent a wide variety of states. module Context = sig type t type key = string list val get: t -> key -> Bytes.t option Lwt.t val set: t -> key -> Bytes.t -> t Lwt.t val del: t -> key -> t Lwt.t (*...*) end To avoid blocking on disk operations, the functions use the asynchronous monad Lwt[5]. Note that the operations on the context are purely functional: get uses the option monad rather than throwing an exception while set and del both return a new Context. The Context module uses a combination of memory caching and disk storage to efficiently provide the appearance of an immutable store. Wecan now define the module type of an arbitrary blockchain protocol: 5

A Self-Amending Crypto-Ledger White Paper - Page 7 A Self-Amending Crypto-Ledger White Paper Page 6 Page 8