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

avoid evm.call for SGT #10

Merged
merged 3 commits into from
Oct 12, 2024
Merged

Conversation

blockchaindevsh
Copy link

This PR addresses this issue.

The related test(mocked) is here.

@qizhou
Copy link

qizhou commented Oct 9, 2024

Should we use SoulGasToken contract to test? This will make sure the storage layout in test is consistent with op-geth in prod.

@blockchaindevsh
Copy link
Author

blockchaindevsh commented Oct 10, 2024

Should we use SoulGasToken contract to test? This will make sure the storage layout in test is consistent with op-geth in prod.

It's a good idea, but seems Host.LoadContract doesn't support contract with construct parameters yet.

@qizhou
Copy link

qizhou commented Oct 11, 2024

Should we use SoulGasToken contract to test? This will make sure the storage layout in test is consistent with op-geth in prod.

It's a good idea, but seems Host.LoadContract doesn't support contract with construct parameters yet.

I think you can create a test contract which inherts SoulGasToken with default ctor parameter.

@blockchaindevsh
Copy link
Author

Should we use SoulGasToken contract to test? This will make sure the storage layout in test is consistent with op-geth in prod.

It's a good idea, but seems Host.LoadContract doesn't support contract with construct parameters yet.

I think you can create a test contract which inherts SoulGasToken with default ctor parameter.

OK, I was thinking of using the exact same contract for testing.

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.

Looks good to me. Very clean and efficiency way!

}
const (
// should keep it in sync with the balances field of SoulGasToken contract
balancesSlot = uint64(51)
Copy link

Choose a reason for hiding this comment

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

I am thinking whether we can get the slot by an external call as

 function getSlot() public pure returns (uint256) {
        uint256 slot;
        assembly {
            slot := _balances.slot
        }
        return slot;
    }

but definitively, it requires a lot of changes of code

Copy link
Author

Choose a reason for hiding this comment

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

Gotcha, I think we can add a test in the monorepo that automatically checks for this.

return parseSoulBalanceResp(ret)
}
var value common.Hash
current.Sub(current, amount).FillBytes(value[:])
Copy link

Choose a reason for hiding this comment

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

Can we use uint256.MustFromBig(current.Sub(current, amount)).Bytes32()? This will address the uncertainty of the endianness issue.

Copy link
Author

@blockchaindevsh blockchaindevsh Oct 11, 2024

Choose a reason for hiding this comment

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

Great suggestion! Done, and the test also changed to Bytes32().

if err != nil {
return fmt.Errorf("GetSoulBalance error:%v", err)
}
have := st.GetSoulBalance(st.msg.From)
if have, want := have.ToBig(), new(big.Int).Sub(balanceCheck, st.msg.Value); have.Cmp(want) >= 0 {
if have, want := st.state.GetBalance(st.msg.From).ToBig(), st.msg.Value; have.Cmp(want) < 0 {
Copy link

Choose a reason for hiding this comment

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

Does this mean that even if the sender has enough soul gas, it will still return an error if there isn’t enough native gas token?

Copy link
Author

@blockchaindevsh blockchaindevsh Oct 11, 2024

Choose a reason for hiding this comment

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

No, that issue is to be fixed by modifying ValidateTransactionWithState to also consider SGT balance. I'll create a separate PR after merging this one.

Copy link

Choose a reason for hiding this comment

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

In what situation that the msg is from 0x0 address?

Copy link
Author

@blockchaindevsh blockchaindevsh Oct 12, 2024

Choose a reason for hiding this comment

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

When called from here or here. Basically those APIs that doesn't require signature, in that case user can specify arbitrarily.

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