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

Add returnType when call other contract #285

Closed
Tommo-L opened this issue Jun 10, 2020 · 3 comments
Closed

Add returnType when call other contract #285

Tommo-L opened this issue Jun 10, 2020 · 3 comments

Comments

@Tommo-L
Copy link
Contributor

Tommo-L commented Jun 10, 2020

Deason

For security reason, it's not safe to call other contract without restrict on the return stack.

bool verify(int a, int b)
{
    CallSomeContract();
    return a > b;
}
//script of CallSomeContract()
PUSH 1 // this hide the parameter b of verify()
PUSH 2 // this hide the parameter a of verify()
RET

We expect CallSomeContract() to return no value. But if it maliciously returns 2 values, then these values will be automatically copied onto our stack, causing us to return wrong results. Original posted at neo-project/neo#1680 (comment)

Solution

Maybe we can use the following format:

public static T Contract.Call<T extends StackItem>(B, method, args)

---------------------------- update 11 June --------------------------------
Using the following format:

[Contract(Hash = "0x0011223344556677889900112233445566778899")]
class AContract
{
    public static extern int Funca();
}

[Contract(Hash = "0x0011223344556677889900112233445566778890")]
class BContract
{
    public static extern int Funcb();
}

class MyContract : SmartContract
{
    public static void MyMethod()
    {
        int a = A.Funca()
        int b = B.Funcb();
        a++;
    }
}

original discussed at neo-project/neo#1680 (comment)

@erikzhang
Copy link
Member

erikzhang commented Jun 12, 2020

AppcallAttribute should be replaced.

@Tommo-L
Copy link
Contributor Author

Tommo-L commented Jun 12, 2020

The parameters of System.Contract.Call/CallEx have been updated.

System.Contract.Call(UInt160 contractHash, ContractParameterType returnType, string method, Array args)
System.Contract.CallEx(UInt160 contractHash, ContractParameterType returnType, string method, Array args, CallFlags callFlags)

@ShawnYun
Copy link
Contributor

According to neo-project/neo#1706 . We need to modify the plan.

@Tommo-L Tommo-L closed this as completed Jun 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants