-
Notifications
You must be signed in to change notification settings - Fork 150
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
Added data transformation documentation #2555
base: spr/master/9557f1ee
Are you sure you want to change the base?
Conversation
6326189
to
c04a9a6
Compare
|
||
It's **not allowed** to write any function call expressions, either builtin, or user-defined. |
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 would make it more verbose, the message of this line isn't obvious to me
call \ | ||
--url http://127.0.0.1:5050 \ | ||
--contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ | ||
--function tuple_fn \ |
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 think it should be this
complex_struct_fn
--contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ | ||
--function tuple_fn \ | ||
--calldata \ | ||
data_transformer_contract::ComplexStruct { \ |
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.
We never show the definition of ComplexStruct
.
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 should be NestedStructWithField
instead, my fault
call \ | ||
--url http://127.0.0.1:5050 \ | ||
--contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ | ||
--function tuple_fn \ |
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 think it should be complex_fn
### Caveats | ||
|
||
Reasoning about calldata serialization logic is not always possible for Cast. **In particular, Cast doesn't verify serialized calldata against the ABI**. | ||
|
||
When given a calldata, Cast first tries to transform it according to the contract ABI. | ||
When failed, in case of type or length mismatch, it will then try to interpret it as an already serialized data. | ||
|
||
Thus, calldata written in hex-encoded form is not always going to be interpreted as a list of felts and treated as serialized. Let's see an example: | ||
|
||
Our `DataTransformerContract` exposes a method with signature: | ||
```rust | ||
fn u256_fn(self: @ContractState, a: u256) { ... } | ||
``` | ||
|
||
We can write: | ||
```shell | ||
$ sncast --account myuser \ | ||
call \ | ||
--url http://127.0.0.1:5050 \ | ||
--contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ | ||
--function u256_fn \ | ||
--calldata 0x10 \ | ||
--block-id latest | ||
``` | ||
|
||
Despite the call data **not being** the proper serialization of an `u256` (which would be `0x10 0x0`), call succeeds. |
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.
Maybe this should be a bit more strongly worded e.g. explicitly warn users to always use type suffixes etc. so their data doesn't become serialized incorrectly
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.
Also it would probably make sense to add a flag that disables data transformation just to be extra sure. This could be a separate issue and tackled by someone else though
docs/src/starknet/index.md
Outdated
Please note the notation of the argument. The default way of passing calldata is a list of hexadecimally encoded field elements - the *serialized* calldata. | ||
To obtain the serialized form of the wished data, one must write a Cairo program calling `Serde::serialize` on subsequent arguments and displaying the results. | ||
|
||
It is also possible to pass calldata in more friendly, human readable form due to the [calldata transformation](./calldata-transformation.md) feature present in Cast. |
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 is also possible to pass calldata in more friendly, human readable form due to the [calldata transformation](./calldata-transformation.md) feature present in Cast. | |
It is also possible to pass calldata in more friendly, human readable form thanks to the [calldata transformation](./calldata-transformation.md) feature present in Cast. |
docs/src/starknet/index.md
Outdated
It is also possible to pass calldata in more friendly, human readable form due to the [calldata transformation](./calldata-transformation.md) feature present in Cast. | ||
|
||
> ⚠️ **Warning** | ||
> Cast will not werify the serialized calldata. Any errors caused by passing improper calldata in a serialized form will originate from the network. |
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.
> Cast will not werify the serialized calldata. Any errors caused by passing improper calldata in a serialized form will originate from the network. | |
> Cast will not verify the serialized calldata. Any errors caused by passing improper calldata in a serialized form will originate from the network. |
c04a9a6
to
985d9dd
Compare
39e1aa9
to
98dac87
Compare
985d9dd
to
78f40e3
Compare
a8be152
to
19e21c3
Compare
78f40e3
to
9257615
Compare
commit-id:f00574d8
9257615
to
5327631
Compare
19e21c3
to
ade2c54
Compare
Stack:
sncast
commands #2548call
,deploy
andinvoke
command handlers #2546u256
andu512
#2545