-
Notifications
You must be signed in to change notification settings - Fork 27
Conversation
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>> { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)?; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
gas -= baseCost | ||
gas = gas - gas/64 | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
This PR uses the infrastructure from the following to add Wasm contract calls
This PR relies on
Additionally, this PR
call_contract
andread_return_data
, to use the newwasmer 3.2
FunctionEnvMut::data_and_store_mut
function for returning both an env and store.vm.ErrExecutionReverted
.