From 5dd1e3c1aa1c9011fff943be505b1dff6b9025fd Mon Sep 17 00:00:00 2001 From: kent-3 <100624004+kent-3@users.noreply.github.com> Date: Fri, 30 Aug 2024 09:20:05 -0400 Subject: [PATCH] try fix payload hashing --- .../public-gateway/test/Contract.t.sol | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/TNLS-Gateways/public-gateway/test/Contract.t.sol b/TNLS-Gateways/public-gateway/test/Contract.t.sol index dc24e60..efff965 100644 --- a/TNLS-Gateways/public-gateway/test/Contract.t.sol +++ b/TNLS-Gateways/public-gateway/test/Contract.t.sol @@ -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) { @@ -372,4 +383,4 @@ contract ContractTest is Test { (,bool tempCompleted) = gateway.tasks(1); assertEq(tempCompleted, true); } -} \ No newline at end of file +}