Move.

帖子

分享您的知识。

Dominikus .
Mar 15, 2025
专家问答

How to ensure secure module object access and mutation?

I developed a module with a DonutShop containing a Balance. I want to share this module without risking unauthorized manipulation of Balance. Can other modules directly alter the Balance if I only use getters/setters within the module?

  • Move CLI
1
1
分享
评论
.

答案

1
Bolke .
Mar 16 2025, 01:49

正确. 一个对象只能由存在于创建该对象的同一模块中的函数进行突变. 但是,仅将 getter 和 setter 放在同一个模块中不足以完全保护对象的状态. 您还必须实现限制对这些功能的访问的机制. 一种常见的方法是使用 AdminCap 模式,这涉及创建基于能力的访问控制系统. 这样可以确保只有授权实体才能调用某些函数,从而防止未经授权地操纵对象的状态. 查看 AdminCap 模式 了解更多信息.

1
评论
.

你知道答案吗?

请登录并分享。

Move is an executable bytecode language used to implement custom transactions and smart contracts.

148帖子231答案
Sui.X.Peera.

赚取你的 1000 Sui 份额

获取声誉积分,并因帮助 Sui 社区成长而获得奖励。

奖励活动五月
我们使用 cookie 确保您在我们的网站上获得最佳体验。
更多信息