# BGPcoin: Blockchain-Based Internet Number Resource Authority and BGP Security Solution
## 4 Design of BGPcoin: Roles, Components and Functions
### BGPcoin Resource Register and Trading  
The IP address resource and ASN resource become valid after their registration and then are traced according to their trading records. ASN is a general name asset with the general register and transfer operations in its state period, like the name asset in other blockchain-based naming systems. An AS resource is modeled as:  
\[<a,RIR,owner,stime,veriod>\]  
where \(a\) is the ASN, and once a RIR \(rir\) registers it, this AS resource \(<\!\!a,rir,rir,0,0\!\!>\) will be added to the BGPcoin storage. Then, \(rir\) could allocate this resource to a NIR/LIR/ISP \(ow\) with a valid period \(vpd\), and the state is changed to \(<\!\!a,rir,ow,st,vpd\!\!>\), where \(st\) is the present time. Once the resource is out of the expiration date, the owner could pay an amount of rent and update the period of validity by sending an ASNupdate transaction to the BGPcoin contract. In the BGPcoin contract, we design five states for the IP address resource: Unregistered, Registered, Allocated, Assigned, Binded. The state machine model for the IP address resource, as shown in Figure 2, defines the state transfer rules once some operation is related to the IP address resource. \begin{table}
\begin{tabular}{c c} \hline \hline
**Operation** & **Semantics** \\ \hline IP register & IANA\(\rightarrow\)RIR:\(<IPB,\varnothing>\) \\ IP allocate & xIR\(\rightarrow\)xIR:\(<IPB,\varnothing>\) \\ IP assign & xIR\(\rightarrow\)xIR/ISP:\(<IPB,\varnothing>\) \\ IP revoke & xIR/ISP\(\rightarrow\)xIR:\(<IPB,\varnothing>\) \\ ROA add & xIR/ISP:\(<IPB,ASN>\) \\ ROA delete & xIR:\(<IPB,ASN>\rightarrow<IPB,\varnothing>\) \\ ASN register & xIR:\(<ASN,-,->\) \\ ASN allocate & xIR\(\rightarrow\)ISP:\(<ASN,stime,period>\) \\ ASN update & ISP:\(<ASN,stime^{\prime},period>\) \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Semantics of BGPcoin trading operations. Figure 1: Operators for IP address and AS number resource in BGPcoin. xIR represents one of the following: Regional Internet Registry (RIR), National Internet Registry (NIR) and Local Internet Registry (LIR). We model an IP address resource as:  
\[<\pi,state,RIR,NIR,owner,lease>\]  
where the IP prefix \(\pi\) has four layers of possessors: two authorities \(RIR\) and \(NIR\), one owner and one leasee. The state changes in the state machine according to what kind of transaction happens with the IP prefix, as shown in Algorithm 1. Firstly, IANA registers an IP prefix \(\pi\) to one of five RIRs \(rir\), and the state of this IP address resource is \(<\pi,Registered,rir,0,rir,0>\). Then, \(rir\) allocates this IP address resource to am NIR \(nir\), and the state changed is \(<\pi,Allocated,rir,nir,nir,0>\). The \(nir\) continues to allocate to an LIR \(lir\), as in the state \(<\pi,Allocated,rir,nir,lier,0>\). The end user \(eu\) requests the usuftv of this IP address resource from the owner \(lir\), and the state is changed to \(<\pi,Assigned,rir,nir,lir,eu>\). Once the end user places this IP address resource in service for its one AS, then the state is \(<\pi,Bound,rir,nir,lir,eu>\), and an ROA \((\pi;a)\) is added to the BGPcoin storage, where \(a\) is the ASN hold by the end user \(eu\). ```
Input: BGPcoin contract address \(base\_addr\), IP asset structure \(BGPcoin\_IPchain\) that is stored in the BGPcoin contract, \(\_IPS\) that IANA are going to register with the prefix length \(\_prefixlen\) and \(RIR\) that is the regional Internet registry that registers it.