ethereum / fe

Emerging smart contract language for the Ethereum blockchain.
https://fe-lang.org
Other
1.61k stars 187 forks source link

Implement msg.data #277

Open cburgdorf opened 3 years ago

cburgdorf commented 3 years ago

What is wrong?

We do not yet implement reading msg.data

https://github.com/ethereum/fe/blob/177ee35ba4b12150f5cb14152e066d364b1a0161/compiler/src/yul/mappers/expressions.rs#L438

How can it be fixed

Start here:

https://github.com/ethereum/fe/blob/177ee35ba4b12150f5cb14152e066d364b1a0161/compiler/src/yul/mappers/expressions.rs#L438

Background:

https://docs.soliditylang.org/en/develop/units-and-global-variables.html#block-and-transaction-properties

georgeroman commented 3 years ago

I can take this.

cburgdorf commented 3 years ago

Happy to review a PR!

g-r-a-n-t commented 3 years ago

Hi @georgeroman, thank you very much for volunteering.

There's a bit of a holdup with this issue right now, since we do not support dynamically sized bytes (see #280). Without support for dynamically sized bytes, I'm not quite sure how this will be implemented.

There's some open discussion about bytes support, which you'll see if you follow the linked issue, but I think we can get away with handling bytes the same way we handle strings for the time being.

If you're still interested in taking this on, let me know. Otherwise, we could find something else for you.

georgeroman commented 3 years ago

Thank you for letting me know! In this case, I'll take https://github.com/ethereum/fe/issues/278 as it seems easier to start with. However, I would still be interested in helping out with this one.

g-r-a-n-t commented 3 years ago

Great! That one is alright.

cburgdorf commented 3 years ago

Just citing from https://github.com/ethereum/fe/issues/280#issuecomment-799901764 that there might be a better way to read msg.data using a special cbytes type that could have read or slice APIs to read slices of the calldata into a fixed size array.

sbillig commented 3 years ago

How about something like a decode_calldata function, which is generic in its return type?

impl Msg:
  pub fn decode_calldata<T>(offset: u256 = 0) -> T:
    // magic
(x, y, z): (Array<u8, 10>, u256, address) = Msg::decode_calldata(offset: 32)
// x is Array<u8, 10, Location=Calldata> or Calldata<Array<u8, 10>>

// Get a pointer to some raw bytes (This is a bit weird, I admit. Maybe getting a pointer to raw bytes should be a different fn)
x: Array<u8, 128, Encoding=Static> = Msg::decode_calldata()