You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to submit data of a complex struct to a chain contract, the current public(scirpt) fun is limited in the arguments it can accept.
If the chain has BCS deserialization support, this problem is much easier to solve. You can submit a vector to the on-chain contract, and the on-chain contract will deserialize the vector to a struct.
It may be that direct support for deserializing vector to struct is not necessarily desirable given security concerns. It may be sufficient to support only a few basic types of deserialization methods. It is up to the developer of the on-chain contract to use these basic deserialization methods as needed to implement deserialization of complex structs.
For example, the BcsDeserializer class of com.novi.serde, a dependency package for BCS serialization/deserialization introduced by Starcoin Java SDK, supports deserialize_bool, deserialize_u64, deserialize_u128, deserialize_u8vector and other methods.
In some projects where we are trying to get around the current limitation that Move language does not support mapping, a general solution is that we need to pass the "state" of the off-chain (which is sometimes a complex data structure) and state proof into the on-chain contract for verification. The off-chain component serializes the "state" as vector(bytes), which is fine. The on-chain contract receives the "state" and proof, then uses SMT root hash to verify it. After the verification, it needs to deserialize the bytes because the next some business logic may need to use it.
The text was updated successfully, but these errors were encountered:
Feature Request
链上合约需要 BCS 反序列化支持。
Describe the Feature Request
当想要提交一个比较复杂的 struct 的信息给链上合约,当前的 public(scirpt) fun 能接受的参数是受到限制的。
如果链上有 BCS 反序列化支持的话,这个问题就容易解决很多。可以提交一个 vector 给到链上合约,链上合约合约将这个 vector 反序列化为 struct 即可。
When trying to submit data of a complex struct to a chain contract, the current public(scirpt) fun is limited in the arguments it can accept.
If the chain has BCS deserialization support, this problem is much easier to solve. You can submit a vector to the on-chain contract, and the on-chain contract will deserialize the vector to a struct.
Describe Preferred Solution
考虑到安全性问题,可能直接支持将 vector 反序列化为 struct 不一定可取。也许只需要支持一些基本类型的反序列方法即可。由链上合约的开发者视需要使用这些基础的反序列化方法来实现复杂 struct 的反序列化。
比如,Starcoin Java SDK 引入的关于 BCS 序列化/反序列化的依赖包 com.novi.serde 的 BcsDeserializer 类,支持 deserialize_bool、deserialize_u64、deserialize_u128、deserialize_u8vector 等方法。
It may be that direct support for deserializing vector to struct is not necessarily desirable given security concerns. It may be sufficient to support only a few basic types of deserialization methods. It is up to the developer of the on-chain contract to use these basic deserialization methods as needed to implement deserialization of complex structs.
For example, the BcsDeserializer class of com.novi.serde, a dependency package for BCS serialization/deserialization introduced by Starcoin Java SDK, supports deserialize_bool, deserialize_u64, deserialize_u128, deserialize_u8vector and other methods.
Additional Context
这个特性会很有用。
在一些项目中,我们试图绕过当前 Move lang 不支持 mapping 的限制,一个通用解决方案是,我们需要将链下的“状态”(这个状态有时候还是挺复杂的一个数据结构)以及状态证明传入链上合约进行校验。链下组件将“状态”序列化为 vector(bytes),这个没有问题。链上合约收到“状态”和证明后,使用 SMT 对它进行校验,校验通过之后还需要将 bytes 反序列化出来,因为接下里的业务逻辑可能需要使用它。
This feature can be very useful.
In some projects where we are trying to get around the current limitation that Move language does not support mapping, a general solution is that we need to pass the "state" of the off-chain (which is sometimes a complex data structure) and state proof into the on-chain contract for verification. The off-chain component serializes the "state" as vector(bytes), which is fine. The on-chain contract receives the "state" and proof, then uses SMT root hash to verify it. After the verification, it needs to deserialize the bytes because the next some business logic may need to use it.
The text was updated successfully, but these errors were encountered: