move icon indicating copy to clipboard operation
move copied to clipboard

[Bug] Module republish ends with wrong execution result

Open zekun000 opened this issue 3 years ago • 1 comments

Before publish a module, vm checks if it’s abi compatible with existing one. (https://github.com/diem/move/blob/180a066094704b2411d3970758b2a05d2e406213/language/move-vm/runtime/src/runtime.rs#L115) vm has a loader that caches the deserialized module if it’s loaded before otherwise it loads from the data cache. (https://github.com/diem/move/blob/180a066094704b2411d3970758b2a05d2e406213/language/move-vm/runtime/src/loader.rs#L841) a successful module publish goes to data cache directly but does not invalidate the loader’s cache. (https://github.com/diem/move/blob/180a066094704b2411d3970758b2a05d2e406213/language/move-vm/runtime/src/runtime.rs#L193) to reproduce the bug, imagine there’re 3 txn tries to publish the same module with different version V1, V2, V3. V1 is compatible with V2 and V3, but V2 is not compatible with V3. if they’re executed in a single block, [V1, V2, V3], the following happens

  • vm publishes V1 to data cache
  • vm loads V1 in loader cache to do compatibility check with V2
  • vm publishes V2 to data cache
  • vm loads V1 (instead of V2 !!) from loader cache to do compatibility check with V3 and wrongly passes the check and publishes it

zekun000 avatar May 03 '22 03:05 zekun000

We encountered this bug in the starcoin project, when upgrading the module, there is a cache incoherence bug, we provide a method to clear all the loader's code cache.

/// Clear vm runtimer loader's cache to reload new modules from state cache
pub fn empty_loader_cache(&self) -> VMResult<()> {
self.session.runtime.loader.empty_cache()
}

https://github.com/starcoinorg/move/blob/starcoin-main/language/move-vm/runtime/src/move_vm_adapter.rs#L220

Wait for @vgao1996 's new Move VM’s Ownership Model to resolve this cache incoherence bug.

jolestar avatar May 03 '22 03:05 jolestar