Finschia / cosmwasm

Fast and reusable WebAssembly smart contract runtime(and library) for finschia-sdk.
Apache License 2.0
27 stars 14 forks source link

feat: add dynamic callstack for prevent the re-entrancy attack #178

Closed brew0722 closed 2 years ago

brew0722 commented 2 years ago

Description

Closes #155 https://github.com/line/wasmvm/pull/62

about integration test, cannot make the test logic with multiple contracts in the cosmwasm repo. So I tested manually via try_reentrancy msg of dynamic_caller_contract. Reentry is well blocked like this(A->B->A):

{"height":"7","txhash":"066247EDDA6EB99AD88027D3B4B22A67434EBDC65CC87D7BB00E156A1D5865B9","codespace":"wasm","code":5,"data":"","raw_log":"failed to execute message; message index: 0: Error calling the VM: Error executing Wasm: Wasmer runtime error: RuntimeError: func_info:{module_name:dynamic_callee_contract, name:stub_reentrancy, signature:[I32] -\u003e []}, error:Unknown error during call into backend: Some(\"Error executing Wasm: Wasmer runtime error: RuntimeError: func_info:{module_name:dynamic_caller_contract, name:stub_should_never_be_called, signature:[] -\u003e []}, error:User error during call into backend: A contract can only be called once per message.\"): execute wasm contract failed","logs":[],"info":"","gas_wanted":"200000","gas_used":"67989","tx":null,"timestamp":""}

In order to put the above integration tests structurally into code, it need to go into lbm's cli_test. So This will be done after merging into main in the future.

Types of changes

Checklist

brew0722 commented 2 years ago

rebased to squash merged PR(https://github.com/line/cosmwasm/pull/182).