# MDA-Based Approach for Blockchain Smart Contract Development
## 4 Application of the MDAsmartCD Method for Development of Hackathon Certificate Issuing Solution
### The Metrics of the Developed HackChain Models and the Generated Code
The defined Ethereum PSM and Hyperledger Fabric PSM were used to generate the _HackChain_ Solidity smart contract and Go chaincode, respectively. To evaluate whether the generated smart contracts meet the requirements defined in Blockchain CIM, both the Go chaincode and the Solidity smart contract were tested using the same test scenarios (test \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Transformation Result: Ethereum PSM** & **Transformation Result: Hyperledger Fabric PSM** \\ \hline
**Element** & **Element Count** & **Element** & **Element Count** \\ \hline \multicolumn{4}{c}{**Smart Contract Structure**} \\ \hline <<contract>> & 1 & <<chaincode>> & 1 \\ <<variable>> & 2 & <<variable>> & 1 \\ <<mapping>> & 1 & <<structure>> & 2 \\ <<struct>> & 1 & <<field>> & 18 \\ <<member>> & 12 & <<function>> & 2 \\ <<enum>> & 1 & <<argument>> & 16 \\ <<function>> & 2 & inherited <<function>> & 18 \\ <<parameter>> & 12 & inherited <<structure>> & 3 \\ <<event>> & 1 & inherited <<variable>> & 5 \\ inherited <<function>> & 27 & & \\ inherited <<variable>> & 6 & & \\ inherited <<event>> & 3 & & \\ \hline \multicolumn{4}{c}{**Smart Contract Behaviour**} \\ \hline State & 3 & State & 3 \\ Transition & 4 & Transition & 4 \\ Effect & 1 & Effect & 1 \\ Guard & 2 & Guard & 2 \\ \hline \hline \end{tabular}
\end{table} 
Table 3: _HackChain_ Blockchain PSM metrics. cases are provided in the [[https://github.com/m-jurgelaiitis/MDAsmartCD](https://github.com/m-jurgelaiitis/MDAsmartCD)]([https://github.com/m-jurgelaiitis/MDAsmartCD](https://github.com/m-jurgelaiitis/MDAsmartCD)) accessed on 26 December 2022). Furthermore, the generated smart contracts were unit tested using the supplied smart contract unit tests to the ERC721 standard. Furthermore, both generated smart contracts were analysed for vulnerabilities. The generated Go chaincode was evaluated using HFCCT [41], a framework for the detection of Hyperledger Fabric smart contracts. The framework enables the detection of 17 types of common vulnerabilities, and no issues were detected during the _HackChain_ Go chaincode evaluation. The generated Solidity _HackChain_ smart contract was evaluated with the Slither [42] static code analysis tool, which is used for automated vulnerability detection, optimisation detection, code understanding analysis, and assisted code review. Slither checks 80 vulnerabilities, and no high, medium, or low issues were found in the generated Solidity smart contract. The _HackChain_ smart contract Solidity and Go chaincode metrics were calculated using the Lizard [43] code complexity analysing tool and are presented in Table 4. The presented analysis results encompass metrics such as the NLOC (normalised lines of code), CCN (cyclomatic complexity number), token (token count which refers a number of code blocks, expressions, annotations, methods, and object access), and parameters (parameter count of functions). For both smart contract and chaincode, the code metrics do not include the inherited elements from the ERC 721 standard. The _HackChain_ Go chaincode functions have a higher cyclomatic complexity number compared to the _HackChain_ Solidity smart contract functions (Figure 23). A higher CCN means more complex code, which is more difficult to read and understand. In _HackChain.go_, a higher complexity can be attributed to language specifics, as in _Go_, for querying the ledger data, additional calls to _ctx Transaction-ContextInterface_ are required, which also come with additional error handling wrappers.