Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve how to estimate what to pay for Oracle requests/callbacks #3163

Closed
gsmachado opened this issue Feb 23, 2024 · 7 comments
Closed

Improve how to estimate what to pay for Oracle requests/callbacks #3163

gsmachado opened this issue Feb 23, 2024 · 7 comments
Labels
Discussion Initial issue state - proposed but not yet accepted

Comments

@gsmachado
Copy link
Contributor

gsmachado commented Feb 23, 2024

Summary or problem description

Imagine that you have a smart contract with two methods:

public class CallOracleContract {

    ...

    public static final StdLib stdLib = new StdLib();
    public static final OracleContract oracle = new OracleContract();

    public static void request(String url, String filter, int gasForResponse) {
        oracle.request(url, filter, "callback", null, gasForResponse);
    }

    public static void callback(String url, Object userData, int responseCode, ByteString response) throws Exception {
        if (Runtime.getCallingScriptHash() != oracle.getHash()) {
            throw new Exception("No authorization");
        }
        ByteString serialized = stdLib.serialize(new CustomResponseStruct(url, responseCode, response));
        Storage.put(ctx, responseKey, serialized);
    }

    ...

}

Before calling the request method, how can I estimate how much GAS the callback cost that I can accurately specify to the request method (more specifically, the gasForResponse param)?

It's not possible to call invokescript or other methods because the first line of callback uses Runtime.getCallingScriptHash(), even if the developer knows what the response will look like (i.e., the size of it).

Do you have any solution you want to propose?

Instead of providing an accurate way to estimate how much GAS the callback would cost, a better solution would be to issue a "refund" back to those who requested the Oracle call. For example, if a higher amount was specified on the gasForResponse param, then the remainder will be refunded.

FYI: @shargon @Jim8y @superboyiii @mialbu

@gsmachado gsmachado added the Discussion Initial issue state - proposed but not yet accepted label Feb 23, 2024
@shargon
Copy link
Member

shargon commented Feb 23, 2024

I vote for refund

@lock9
Copy link
Contributor

lock9 commented Feb 23, 2024

Refund or slippage. I remember that there was some issue with refunds. Was it a security problem? I can't recall it

@shargon
Copy link
Member

shargon commented Feb 23, 2024

Refund or slippage. I remember that there was some issue with refunds. Was it a security problem? I can't recall it

If the oracle sign more data to waste the gas, you will lose all of them

@roman-khimov
Copy link
Contributor

roman-khimov commented Feb 25, 2024

Duplicates #1982 (I'd close this one because of that).

Related to #2806. But still requires an additional mechanism since it's an additional transaction executed in its own context.

@shargon
Copy link
Member

shargon commented Feb 25, 2024

Duplicates #1982 (I'd close it because of that).

Related to #2806. But still requires an additional mechanism since it's an additional transaction executed in its own context.

I like to see that my opinion was the same hahah #1982 (comment)

@vncoelho
Copy link
Member

Good, refund is a good feature and solution.

@roman-khimov
Copy link
Contributor

In the game of duplicates, older ones win to me, let's move this discussion into #1982.

@roman-khimov roman-khimov closed this as not planned Won't fix, can't repro, duplicate, stale Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Initial issue state - proposed but not yet accepted
Projects
None yet
Development

No branches or pull requests

5 participants