Skip to content

Commit

Permalink
Fix kettle addr padding (#52)
Browse files Browse the repository at this point in the history
* Fix kettle address in contextGet

* More

* Skip Chatgpt key if not found
  • Loading branch information
ferranbt authored Feb 26, 2024
1 parent a09bca6 commit 7b8c66d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/Context.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ library Context {
}

function kettleAddress() internal returns (address) {
bytes memory addr = Suave.contextGet("kettleAddress");
return abi.decode(addr, (address));
bytes memory _bytes = Suave.contextGet("kettleAddress");

address addr;
assembly {
addr := mload(add(_bytes, 20))
}

return addr;
}
}
8 changes: 7 additions & 1 deletion src/forge/ContextConnector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ contract ContextConnector {
if (keyHash == keccak256(abi.encodePacked("confidentialInputs"))) {
msgContent = confidentialInputs;
} else if (keyHash == keccak256(abi.encodePacked("kettleAddress"))) {
msgContent = abi.encode(kettleAddress);
// pad the address to the rigth to 32 bytes
bytes20 addr = bytes20(kettleAddress);
bytes memory paddedAddress = new bytes(32);
for (uint256 i = 0; i < 20; i++) {
paddedAddress[i] = addr[i];
}
msgContent = paddedAddress;
} else {
revert("Invalid context key");
}
Expand Down
3 changes: 3 additions & 0 deletions test/protocols/ChatGPT.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ contract ChatGPTTest is Test, SuaveEnabled {
function getChatGPT() public returns (ChatGPT chatgpt) {
// NOTE: tried to do it with envOr but it did not worked
try vm.envString("CHATGPT_API_KEY") returns (string memory apiKey) {
if (bytes(apiKey).length == 0) {
vm.skip(true);
}
chatgpt = new ChatGPT(apiKey);
} catch {
vm.skip(true);
Expand Down

0 comments on commit 7b8c66d

Please sign in to comment.