Skip to content

Commit

Permalink
fix: Reuse encodeAddressToBase64 to avoid calling it too many times t…
Browse files Browse the repository at this point in the history
…o prevent error
  • Loading branch information
ltfschoen committed Dec 17, 2024
1 parent 96282cb commit 1b0b47e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 12 additions & 8 deletions packages/hardhat/contracts/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ contract Gateway is Ownable, Utils {
function requestValue(uint256 _callbackSelector, uint32 _callbackGasLimit) external payable onlyOwner returns (uint256 requestId) {
console.log("------ Gateway.requestValue");

bytes28 senderAddressBase64 = encodeAddressToBase64(address(msg.sender));

requestId = taskId;

// TODO: optionally add guard to verify value of _callbackSelector if necessary
Expand Down Expand Up @@ -537,7 +539,7 @@ contract Gateway is Ownable, Utils {
// If the Gateway contract by the Secret team was used instead then we would need a way to upgrade that contract
// to allow us to set an `owner`-like value that could be used to restrict calls to functions like this.
'","user_address":"', address(msg.sender),
'","user_key":"', encodeAddressToBase64(address(msg.sender)),
'","user_key":"', senderAddressBase64,
'","callback_address":"', address(msg.sender),
'"'
);
Expand All @@ -548,7 +550,7 @@ contract Gateway is Ownable, Utils {
'{"data":"{\\"callbackSelector\\":',
uint256toBytesString(_callbackSelector),
payload_info,
encodeAddressToBase64(address(msg.sender)), //callback_address
senderAddressBase64, //callback_address
// callback selector should be a hex value already converted into base64 to be used
// as callback_selector of the request_value function in the Secret contract
'","callback_selector":"', uint256toBytesString(_callbackSelector),
Expand All @@ -572,14 +574,14 @@ contract Gateway is Ownable, Utils {
// TODO - make `user_key` a unique key different from `user_pubkey`
// FIXME - `Error: Transaction reverted without a reason` occurs the 3rd time that
// `encodeAddressToBase64` is called in this function
// bytes memory userKey = bytes.concat(encodeAddressToBase64(address(msg.sender))); // equals AAA= in base64
bytes memory userKey = bytes.concat(senderAddressBase64); // equals AAA= in base64

console.log("2");

// ExecutionInfo struct
ExecutionInfo memory executionInfo = ExecutionInfo({
// user_key: userKey, // FIXME - use this instead when resolve issue
user_key: emptyBytes,
user_key: userKey, // FIXME - use this instead when resolve issue
// user_key: emptyBytes,
// FIXME: use of `secret_gateway_signer_pubkey` does not compile, what alternative to use?
// user_pubkey: uint256toBytesString(secret_gateway_signer_pubkey),
user_pubkey: emptyBytes, // Fill with 0 bytes
Expand Down Expand Up @@ -620,9 +622,11 @@ contract Gateway is Ownable, Utils {
/// @param _callbackGasLimit The gas limit for the callback
/// @return requestId The request ID for the random words

function retrievePubkey(uint256 _callbackSelector, uint32 _callbackGasLimit) external payable returns (uint256 requestId) {
function retrievePubkey(uint256 _callbackSelector, uint32 _callbackGasLimit) external payable onlyOwner returns (uint256 requestId) {
console.log("------ Gateway.retrievePubkey");

bytes28 senderAddressBase64 = encodeAddressToBase64(address(msg.sender));

requestId = taskId;

// TODO: optionally add guard to verify value of _callbackSelector if necessary
Expand Down Expand Up @@ -653,7 +657,7 @@ contract Gateway is Ownable, Utils {
'}","routing_info":"', routing_info,
'","routing_code_hash":"', routing_code_hash,
'","user_address":"', address(msg.sender),
'","user_key":"', encodeAddressToBase64(address(msg.sender)),
'","user_key":"', senderAddressBase64,
'","callback_address":"', address(msg.sender),
'"'
);
Expand All @@ -663,7 +667,7 @@ contract Gateway is Ownable, Utils {
'{"data":"{\\"callbackSelector\\":',
uint256toBytesString(_callbackSelector),
payload_info,
encodeAddressToBase64(owner), //callback_address
senderAddressBase64, //callback_address
'","callback_selector":"OLpGFA==","callback_gas_limit":', // 0x38ba4614 hex value already converted into base64, callback_selector of the fulfillRandomWords function
uint256toBytesString(_callbackGasLimit),
'}'
Expand Down
2 changes: 0 additions & 2 deletions packages/secret-contracts-scripts/src/evm/requestValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ async function unsafeRequestValue() {
const taskDestinationNetwork = await gatewayContract.task_destination_network();
console.log("taskDestinationNetwork: ", taskDestinationNetwork);

// FIXME: The below does not provide a response using this script. It does however work if done via Remix
//
// Previously in the gateway evm contract onlyOwner was set to be whoever created the contract in its
// constructor (e.g. the `DEPLOYER_ADDRESS`) with `owner = msg.sender` but `setSecretContractInfo`
// function in the gateway evm contract only allows `onlyOwner` to call it, but the caller is using
Expand Down

0 comments on commit 1b0b47e

Please sign in to comment.