Skip to content

Commit

Permalink
try fix payload hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
kent-3 committed Aug 30, 2024
1 parent 3b058b2 commit 5dd1e3c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions TNLS-Gateways/public-gateway/test/Contract.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,20 @@ contract ContractTest is Test {
Helper Functions
//////////////////////////////////////////////////////////////*/

function getPayloadHash(bytes memory _payload) public pure returns (bytes32) {
return keccak256(abi.encodePacked(_payload));
// return keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes32(_payload.length), _payload));
// function getPayloadHash(bytes memory _payload) public pure returns (bytes32) {
// return keccak256(abi.encodePacked(_payload));
// // return keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes32(_payload.length), _payload));
// }

function getPayloadHash(bytes memory _payload) public pure returns (bytes32 payloadHash) {
assembly {
// Take scratch memory for the data to hash
let data := mload(0x40)
mstore(data,"\x19Ethereum Signed Message:\n32")
mstore(add(data, 28), keccak256(add(_payload, 32), mload(_payload)))
payloadHash := keccak256(data, 60)
mstore(0x40, add(data, 64))
}
}

function getResultHash(bytes memory _result) public pure returns (bytes32) {
Expand Down Expand Up @@ -372,4 +383,4 @@ contract ContractTest is Test {
(,bool tempCompleted) = gateway.tasks(1);
assertEq(tempCompleted, true);
}
}
}

0 comments on commit 5dd1e3c

Please sign in to comment.