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

Contract Calls #47

Merged
merged 10 commits into from
Mar 29, 2023
Merged

Contract Calls #47

merged 10 commits into from
Mar 29, 2023

Conversation

rachel-bousfield
Copy link
Contributor

@rachel-bousfield rachel-bousfield commented Mar 15, 2023

This PR uses the infrastructure from the following to add Wasm contract calls

This PR relies on

Additionally, this PR

  • Introduces the first hostios, call_contract and read_return_data, to use the new wasmer 3.2 FunctionEnvMut::data_and_store_mut function for returning both an env and store.
  • Makes errors more forgiving by treating hard errors as simple reverts. No longer will panicking or otherwise unnaturally suspending execution take all your gas.
  • Makes errors better align with the EVM by returning standard strings such as vm.ErrExecutionReverted.
  • Fixes a minor bug where Arbitrator would label hard errors as reverts. This doesn't matter since error codes aren't part of consensus, but this improves devex.

Base automatically changed from stylus-state-storage to stylus March 16, 2023 06:09
@rachel-bousfield rachel-bousfield marked this pull request as ready for review March 27, 2023 04:39
fn read_return_data(dest: *mut u8);
}

pub fn call(contract: Bytes20, calldata: &[u8], value: Option<Bytes32>, gas: Option<u64>) -> Result<Vec<u8>, Vec<u8>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be useful to add documentation to this function, specifically regarding what the error result contains. In the case the unsafe call to read_return_data fails, what will be included in outs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, I've added some documentation :)

If read_return_data fails, then execution will halt before resuming client execution. So from the user's perspective, this isn't something they need to worry about unless they edit the crate to call read_return_data directly. I've still added a comment on that extern just in case though

};

let contract = env.read_bytes20(contract)?;
let input = env.read_slice(calldata, calldata_len)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels sensible to check the max calldata size here before we do this read operation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a charge for the bytes, so this should be safe now.

However, we likely need to make the Rust => Go data copy lazy to avoid both DOS and uncontrollable gas costs.

Comment on lines +120 to +122
gas -= baseCost
gas = gas - gas/64

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps need validation that this is safe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, added a check

@rachel-bousfield rachel-bousfield merged commit 1a886bc into stylus Mar 29, 2023
@rachel-bousfield rachel-bousfield deleted the stylus-contract-calls branch March 29, 2023 02:16
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

Successfully merging this pull request may close these issues.

2 participants