onflow / cadence

Cadence, the resource-oriented smart contract programming language 🏃‍♂️
https://developers.flow.com/cadence
Apache License 2.0
532 stars 139 forks source link

Usage of RLP builtin #3215

Open janezpodhostnik opened 6 months ago

janezpodhostnik commented 6 months ago

Current Behavior

When trying to use the RLP builtin functions I got really confused.

This does not work:

import RLP
//....
RLP.decodeString("...".utf8)
//....

This also does not work:

// import RLP
//....
decodeString("...".utf8)
//....

But (confusingly) this works:

//import RLP
//....
RLP.decodeString("...".utf8)
//....

Expected Behavior

This is a bit confusing, and is not obvious from the docs: https://cadence-lang.org/docs/1.0/language/built-in-functions#rlp

Maybe add an example to the docs, or even allow the import RLP even if it is not doing anything.

IMO, the best solution might actually be so that you have to import RLP...

Steps To Reproduce

I ran this in a go test env:

import RLP

transaction(){
    prepare(signer: auth(Storage, Contracts, Keys, Inbox, Capabilities) &Account) {
        var f: fun(): Void = fun(){}
        f = fun() {
            var i = 0
            while i < 110 {
                i = i + 1
                RLP.decodeString("xxxxxxxxxxxxxxxxxxxxxx".utf8)
            }
        }
        f()
    }
    execute {
        var f: fun(): Void = fun(){}
    }
}

Environment

- Cadence version: 1.0
- Network: any
turbolent commented 6 months ago

We should allow the import and not report an error.

This also applies to other contracts that are part of the standard library, e.g. BLS.