stellar / rs-soroban-env

Rust environment for Soroban contracts.
Apache License 2.0
60 stars 40 forks source link

Include __check_auth contract instance in footprint when recording #1443

Open leighmcculloch opened 1 month ago

leighmcculloch commented 1 month ago

The env in simulation should include in the footprint contracts that get __check_auth called on them.

@heytdep shared on Discord (link) a transaction built for testnet and run through simulation once. The transaction involves custom auth. The built footprint did not include the contract instance for the custom auth contract.

Transaction:

AAAAAgAAAADhz6YxvqUP4OzxQMYMXFdJcuXYfbIigQtRCbRieQQIUwBw7lEADzfWAAAAFwAAAAAAAAAAAAAAAQAAAAAAAAAYAAAAAAAAAAHsJEGI2Q6jK3qVUCXQJahn2qmm/p2zfU1LlyRUHLDrDQAAAAZzdWJtaXQAAAAAAAQAAAASAAAAARPWiWvcm/7XCKZeqYmBA9eqSG40dtKWG0Evyy8k28PXAAAAEgAAAAET1olr3Jv+1wimXqmJgQPXqkhuNHbSlhtBL8svJNvD1wAAABIAAAABE9aJa9yb/tcIpl6piYED16pIbjR20pYbQS/LLyTbw9cAAAAQAAAAAQAAAAEAAAARAAAAAQAAAAMAAAAPAAAAB2FkZHJlc3MAAAAAEgAAAAHXkotywnA8z+r365/0701QSlWouXn8m0UOoshCtNHOYQAAAA8AAAAGYW1vdW50AAAAAAAKAAAAAAAAAAAAAAAABfXhAAAAAA8AAAAMcmVxdWVzdF90eXBlAAAAAwAAAAIAAAABAAAAAQAAAAET1olr3Jv+1wimXqmJgQPXqkhuNHbSlhtBL8svJNvD1wshA28ulzCuAA9EpgAAABAAAAABAAAAAQAAABEAAAABAAAAAgAAAA8AAAAKcHVibGljX2tleQAAAAAADQAAACDhz6YxvqUP4OzxQMYMXFdJcuXYfbIigQtRCbRieQQIUwAAAA8AAAAJc2lnbmF0dXJlAAAAAAAADQAAAEBKkZFDmoKA8oVB8jL9k2RZkVGU0xeEv1raeVCVAGwaJ5yCgydMnKuPBTJuOknAyqXg2UWcC+kda6t8UNPwWFgMAAAAAAAAAAHsJEGI2Q6jK3qVUCXQJahn2qmm/p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/g+DKXgbUkGVrnrFl0Om00L

Ref: 61eb459b99abbb92f5c566092be8fbf916fc44f149adb6228cb33a66582ad4b3 on testnet

Custom auth requires the use of simulation twice, and if simulation was used twice with the above transaction the contract instance would have been identified in the second pass.

However, it seems reasonable that simulation would identify as much of the footprint as possible on each path, and that the contract instance would be included in the footprint in the first pass. There is already enough data available to the simulation that the custom auth contract would need to be included, at least in the read-only, because the env knows the auth will be called and is being simulated.

dmkozh commented 1 month ago

However, it seems reasonable that simulation would identify as much of the footprint as possible on each path

I don't mind adding that, but this only will help if a custom account happens to only use the instance storage.

I think it's probably about time to implement the mock signature mechanism that allows for single pass simulation in recording mode.

leighmcculloch commented 1 month ago

this only will help if a custom account happens to only use the instance storage

The couple custom auth contracts I've written so far happen to only use instance storage. I think given the category of contract instance storage is highly likely for custom auth, but I agree, this issue isn't a solution for the issue @heytdep experienced.

I opened this issue because this feels more like a bug to me. The system isn't completely constructing what is logically part of the known/expected footprint.

This issue doesn't remove the need to do a second pass on simulation though.