# Integrating Merkle Trees with Transformer Networks for Secure Financial Computation
## 3 Materials and Method
### Merkle-Transformer
#### 3.3.4 Verifiable Secure Transformer Inference Model  
Apart from the verifiable computation module based on the Merkle tree, another core component is the verifiable secure Transformer model. This module aims to efficiently process financial data while providing a mechanism to verify the data processing procedure,  
Figure 4: Illustration of the MatrixSplit method. Initially, the matrix is divided into multiple continuous submatrices using a continuous slicing approach, with each submatrix containing a portion of consecutive rows or columns from the original matrix. Subsequently, the disjoint slicing technique is applied to further partition the matrix into non-overlapping smaller matrix blocks, each composed of a specific region from the original matrix. These matrix blocks are assigned individual hash values, serving as unique identifiers for leaf nodes in the modified Merkle tree. By constructing the modified Merkle tree, effective validation of individual matrix blocks can be performed without the need to validate the entire integrity of the matrix. This approach is particularly valuable in large-scale data processing scenarios, significantly improving validation efficiency while supporting parallel processing and incremental updates.  
ensuring data security and integrity throughout the computation process. The verifiable secure Transformer model, in its design, incorporates the fundamental architecture of the original Transformer model, consisting of multiple self-attention layers and feed-forward networks, with added verifiability. Each layer of the model generates an intermediate output, which is used not only for computing the input of the next layer but also for generating the Merkle tree, facilitating comprehensive data integrity verification.  
This self-attention mechanism allows the model to consider the influence of all other inputs while processing each input, thereby capturing long-distance data dependencies. Following the self-attention layer is the feed-forward network, which further processes the output of the self-attention layer. Feed-forward networks typically consist of two linear transformations with an activation function, such as ReLU [31] or GELU [32], in between, and are mathematically expressed as follows:  
\[\text{FFN}(x)=\max(0,xW_{1}+b_{1})W_{2}+b_{2} \tag{11}\]  
Here, \(W_{1}\), \(W_{2}\), and \(b_{1}\), \(b_{2}\) represent the weights and bias terms of the network layer, respectively. To achieve verifiability, an additional step is added to the output of each layer: the computation of its hash value, which is then integrated as a node in the Merkle tree. This means that at every layer of the model, outputs are produced not only for computation in the subsequent layer but also for validating data integrity. In the financial computation tasks addressed in this paper, the verifiable secure Transformer model offers numerous advantages. Firstly, it improves the efficiency and accuracy of financial data processing, as the Transformer model is capable of effectively handling long sequence dependencies. Secondly, the model enhances the security of data processing, as any unauthorized alteration to the data will be reflected in the root hash value of the Merkle tree and can be rapidly detected. Finally, this design supports the scalability and flexibility of the model, as it allows for the addition of new data processing layers or adjustments to existing ones while maintaining the validity of existing data verifications.