Skip to content

Commit

Permalink
Merge pull request #16 from fxhash/fix/updated-hashing
Browse files Browse the repository at this point in the history
fix: hashing
  • Loading branch information
stevennevins authored Nov 30, 2023
2 parents 1e9bb85 + e907a68 commit e3e7d80
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/FileSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ contract FileSystem is IFileSystem {
for (uint256 i; i < _inodeChecksums.length; i++) {
if (!inodeExists(_inodeChecksums[i])) revert InodeNotFound();
}
directoryChecksum = keccak256(bytes.concat(bytes1(uint8(InodeType.Directory)), keccak256(concatenatedFiles)));
directoryChecksum = keccak256(bytes.concat(bytes1(uint8(InodeType.Directory)), concatenatedFiles));
if (inodeExists(directoryChecksum)) return directoryChecksum;
inodes[directoryChecksum].directory = Directory(_fileNames, _inodeChecksums);
emit DirectoryCreated(directoryChecksum, _fileNames, _inodeChecksums);
Expand Down Expand Up @@ -135,7 +135,7 @@ contract FileSystem is IFileSystem {
filename = bytes(_fileNames[i]);
if (filename.length == 0) revert InvalidFileName();
if (_containsForbiddenChars(filename)) revert InvalidCharacter();
concatenatedFiles = abi.encodePacked(concatenatedFiles, keccak256(filename), _filePointers[i]);
concatenatedFiles = abi.encodePacked(_filePointers[i], keccak256(filename), concatenatedFiles);
}
}

Expand Down
4 changes: 1 addition & 3 deletions test/FileSystem/CreateDirectory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ contract CreateDirectory is FileSystemTest {
function test_CreateDirectory() public {
bytes32 checksum = fileSystem.createDirectory(fileNames, filePointers);
hashedFiles = fileSystem.concatenateFiles(fileNames, filePointers);
checksum = keccak256(
abi.encodePacked(bytes1(uint8(InodeType.Directory)), keccak256(abi.encodePacked(hashedFiles)))
);
checksum = keccak256(abi.encodePacked(bytes1(uint8(InodeType.Directory)), hashedFiles));
assertTrue(fileSystem.inodeExists(checksum));
}

Expand Down
4 changes: 1 addition & 3 deletions test/FileSystem/ReadDirectory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ contract ReadDirectory is FileSystemTest {
function test_ReadDirectory() public {
fileSystem.createDirectory(fileNames, filePointers);
hashedFiles = fileSystem.concatenateFiles(fileNames, filePointers);
checksum = keccak256(
abi.encodePacked(bytes1(uint8(InodeType.Directory)), keccak256(abi.encodePacked(hashedFiles)))
);
checksum = keccak256(abi.encodePacked(bytes1(uint8(InodeType.Directory)), hashedFiles));

bytes32[] memory pointers;
string[] memory fileNameResults;
Expand Down

0 comments on commit e3e7d80

Please sign in to comment.