Skip to content

Commit 257ab95

Browse files
committed
remove sorting
1 parent 1c24a7f commit 257ab95

2 files changed

Lines changed: 6 additions & 23 deletions

File tree

src/Verifier.sol

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -137,28 +137,11 @@ contract PlutoAttestationVerifier {
137137
string memory sessionId,
138138
ProofData[] memory data
139139
) public pure returns (bytes32) {
140-
// Sort the data array by key (simple bubble sort for demonstration)
141-
ProofData[] memory sortedData = new ProofData[](data.length);
142-
for (uint256 i = 0; i < data.length; i++) {
143-
sortedData[i] = data[i];
144-
}
145-
146-
// Bubble sort by key
147-
for (uint256 i = 0; i < sortedData.length; i++) {
148-
for (uint256 j = 0; j < sortedData.length - 1 - i; j++) {
149-
if (keccak256(bytes(sortedData[j].key)) > keccak256(bytes(sortedData[j + 1].key))) {
150-
ProofData memory temp = sortedData[j];
151-
sortedData[j] = sortedData[j + 1];
152-
sortedData[j + 1] = temp;
153-
}
154-
}
155-
}
156-
157140
// Build the hash incrementally
158141
bytes memory hashData = abi.encodePacked(version, issuedAt, nonce, sessionId);
159142

160-
for (uint256 i = 0; i < sortedData.length; i++) {
161-
hashData = abi.encodePacked(hashData, sortedData[i].key, sortedData[i].value);
143+
for (uint256 i = 0; i < data.length; i++) {
144+
hashData = abi.encodePacked(hashData, data[i].key, data[i].value);
162145
}
163146

164147
return keccak256(hashData);

test/Verifier.t.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ contract PlutoAttestationExample is Test {
4141
// Create the proof data array
4242
string[] memory keys = new string[](2);
4343
string[] memory values = new string[](2);
44-
keys[0] = "a";
45-
keys[1] = "c";
46-
values[0] = "10";
47-
values[1] = "\"d\"";
44+
keys[0] = "c";
45+
keys[1] = "a";
46+
values[0] = "\"d\"";
47+
values[1] = "10";
4848

4949
PlutoAttestationVerifier.ProofData[] memory proofData = verifier.createProofDataArray(keys, values);
5050

0 commit comments

Comments
 (0)