Skip to content

Conversation

@blockchaindevsh
Copy link
Collaborator

@blockchaindevsh blockchaindevsh commented Nov 13, 2024

This PR prepares SoulGasToken contract so that if:

  1. IS_BACKED_BY_NATIVE is true
  2. a whitelisted contract is used as tx.to

then SoulGasToken balance can be used as msg.value.

@blockchaindevsh blockchaindevsh changed the title add allowSgtValue/disallowSgtValue to SGT contracts add allowSgtValue/disallowSgtValue to SGT contract Nov 13, 2024
@qzhodl
Copy link

qzhodl commented Nov 18, 2024

Is there an issue to track the motivation and background for this?

Additionally, in many cases, the EthStorage contract might be called by a dApp contract to store data, rather than being the direct transaction target. Can we also support this scenario?

@blockchaindevsh
Copy link
Collaborator Author

blockchaindevsh commented Nov 18, 2024

Is there an issue to track the motivation and background for this?

I updated the description above.

Additionally, in many cases, the EthStorage contract might be called by a dApp contract to store data, rather than being the direct transaction target. Can we also support this scenario?

@qizhou What's your opinion? The implementation will be much trickier if we want to support indirect caller.

I'm not sure if we should give SoulGasToken so much flexibility.

@blockchaindevsh
Copy link
Collaborator Author

I pushed the tests in this PR, since it depends on the contract change.

@qizhou
Copy link

qizhou commented Nov 19, 2024

Is there an issue to track the motivation and background for this?

I updated the description above.

Additionally, in many cases, the EthStorage contract might be called by a dApp contract to store data, rather than being the direct transaction target. Can we also support this scenario?

@qizhou What's your opinion? The implementation will be much trickier if we want to support indirect caller.

I'm not sure if we should give SoulGasToken so much flexibility.

The indirect caller is tricker, but Qiang is right: the EthStorage contract is mostly called by the contracts.

One solution that comes to my mind is:

  • EthStorage contract can transfer SGT balance: call chargeFrom(addr, amount) returns (amountCharged). In the call, it will charge maximum amountCharged <= SGT balance from tx.origin (msg.sender does not have the SGT), then burn the SGT, and send the value to the contract)
  • A whitelist to allow which contracts can call chargeFrom()

@blockchaindevsh
Copy link
Collaborator Author

blockchaindevsh commented Nov 19, 2024

Is there an issue to track the motivation and background for this?

I updated the description above.

Additionally, in many cases, the EthStorage contract might be called by a dApp contract to store data, rather than being the direct transaction target. Can we also support this scenario?

@qizhou What's your opinion? The implementation will be much trickier if we want to support indirect caller.
I'm not sure if we should give SoulGasToken so much flexibility.

The indirect caller is tricker, but Qiang is right: the EthStorage contract is mostly called by the contracts.

One solution that comes to my mind is:

  • EthStorage contract can transfer SGT balance: call chargeFrom(addr, amount) returns (amountCharged). In the call, it will charge maximum amountCharged <= SGT balance from tx.origin (msg.sender does not have the SGT), then burn the SGT, and send the value to the contract)
  • A whitelist to allow which contracts can call chargeFrom()

I see how it works, but the trust model is a bit different from ethereum's convention in that evil contracts can upgrade and spend user's SGT balance without permission. But since the permission is whitelisted, this concern should be controllable since we can revoke the whitelist if bad things happen.

@blockchaindevsh
Copy link
Collaborator Author

blockchaindevsh commented Nov 19, 2024

@qizhou @qzhodl Added a function: chargeFromOrigin(uint256 amount) returns (uint256 amountCharged) in b1d4c1e.

Copy link

@qizhou qizhou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. This seems to be simplest change to allow storage contract to charge SGT without changing op-geth.

if (balance >= amount) {
amountCharged = amount;
} else {
amountCharged = balance;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a bit odd that if the amount to be charged exceeds the balance, we still attempt to charge it instead of returning 0.

How will the EthStorage contract call this method? Based on my understanding, the EthStorage contract will first check if msg.value is sufficient. If not, it will call chargeFromOrigin(amountNeeded - msg.value). If the balance is still insufficient, it will revert.

Copy link
Collaborator Author

@blockchaindevsh blockchaindevsh Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chargeFromOrigin may charge less than requested, and the remaining amount is expected to be charged from native balance by the caller contract. The caller contract can revert if it can't charge from native balance.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I prefer charging SGT first in EthStorage and then charging native balance so that it may provider better UX.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new issue has been opened to track the corresponding changes: ethstorage/storage-contracts-v1#122

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants