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

feat: BCS deserialization support #33

Closed
wubuku opened this issue Feb 26, 2022 · 0 comments · Fixed by #43
Closed

feat: BCS deserialization support #33

wubuku opened this issue Feb 26, 2022 · 0 comments · Fixed by #43
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@wubuku
Copy link

wubuku commented Feb 26, 2022

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.

@wubuku wubuku added the enhancement New feature or request label Feb 26, 2022
@jolestar jolestar added the help wanted Extra attention is needed label Feb 26, 2022
@jolestar jolestar transferred this issue from movefuns/movefuns Jun 9, 2022
pause125 added a commit to pause125/starcoin-framework that referenced this issue Jun 12, 2022
@jolestar jolestar linked a pull request Jul 1, 2022 that will close this issue
7 tasks
@jolestar jolestar closed this as completed Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants