trufflesuite / ganache-ui

Personal blockchain for Ethereum development
https://www.trufflesuite.com/ganache
MIT License
4.65k stars 795 forks source link

Out of memory error when executing send() without enough gas (when running Ganache 2.5.4 on darwin) #4991

Open CoHuK opened 1 year ago

CoHuK commented 1 year ago

Making a transfer to a contract with not enough gas is crashing a server with out of memory error.

Example Solidity script that reproduces the error:

//SPDX-License-Identifier: MIT

pragma solidity ^0.8.17;

contract Sender {
    receive() external payable {}

    function withdrawTransfer(address payable _to) public {
        _to.transfer(10);
    }
}

contract ReceiverAction {
    uint public balanceReceived;

    function balance() public view returns(uint) {
        return address(this).balance;
    }

    receive() external payable {
        balanceReceived += msg.value;
    }
}

Steps: 1) Send some (10+) Wei to Sender contract 2) Use withdrawTransfer function with the address of ReceiverAction contract

PLATFORM: darwin GANACHE VERSION: 2.5.4

EXCEPTION:

Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed
    at ChildProcess.send (internal/child_process.js:678:16)
    at /webpack:/src/integrations/ethereum/common/services/EthereumChainService.js:81:21
    at new Promise (<anonymous>)
    at EthereumChainService_EthereumChainService.startServer (/webpack:/src/integrations/ethereum/common/services/EthereumChainService.js:70:14)
    at ethereum_Ethereum.startServer (/webpack:/src/integrations/ethereum/index.js:155:23)
    at integrations_IntegrationManager.startServer (/webpack:/src/integrations/index.js:98:27)
    at IpcMainImpl.<anonymous> (/webpack:/src/main/index.js:626:30)
CoHuK commented 1 year ago

Exception after transaction attempt:


[18:48:14]  5: 0x110853375 v8::internal::Heap::StartIdleIncrementalMarking(v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) 

[/Applications/Ganache.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]

[18:48:14]  6: 0x110854a0d v8::internal::Heap::StartIdleIncrementalMarking(v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) 

[/Applications/Ganache.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]

[18:48:14]  7: 0x110851109 v8::internal::Heap::CreateFillerObjectAt(unsigned long, int, v8::internal::ClearRecordedSlots, v8::internal::ClearFreedMemoryMode) 

[/Applications/Ganache.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
[18:48:14]  8: 0x11084e95a v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) 
[/Applications/Ganache.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
[18:48:14]  9: 0x11085a70a v8::internal::Heap::PromotedExternalMemorySize() 
[/Applications/Ganache.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
[18:48:14] 10: 0x11085a791 v8::internal::Heap::PromotedExternalMemorySize() 
[/Applications/Ganache.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
[18:48:14] 11: 0x110828717 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) 
[/Applications/Ganache.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
[18:48:14] 12: 0x110b8cd7f v8::internal::RegExp::CompileForTesting(v8::internal::Isolate*, v8::internal::Zone*, v8::internal::RegExpCompileData*, v8::base::Flags<v8::internal::JSRegExp::Flag, int>, v8::internal::Handle<v8::internal::String>, v8::internal::Handle<v8::internal::String>, bool) 
[/Applications/Ganache.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
[18:48:14] 13: 0x111136af9 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) 
[/Applications/Ganache.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
[18:48:14] 
[18:48:14] <--- Last few GCs --->
[18:48:14] 
[18:48:14] 
[20497:0x7f91a8008000]   177031 ms: Mark-sweep 4094.9 (4100.8) -> 4094.4 (4101.0) MB, 3528.8 / 0.0 ms  (average mu = 0.098, current mu = 0.002) allocation failure scavenge might not succeed
[18:48:14] 
[20497:0x7f91a8008000]   180675 ms: Mark-sweep 4095.2 (4101.0) -> 4094.7 (4101.2) MB, 3634.2 / 0.0 ms  (+ 0.0 ms in 12 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 3643 ms) (average mu = 0.051, current mu = 0.003) all
[18:48:14] 
[18:48:14] <--- JS stacktrace --->
[18:48:14] 
[18:48:14] ==== JS stack trace =========================================
[18:48:14] 
[18:48:14]     0: ExitFrame 
[pc: 0x111136af9]
[18:48:14] Security context: 0x08fc8b159581 <JSObject>
[18:48:14]     1: promisify 
[0x8fc7ebd0861] 
[internal/util.js:~258] 
[pc=0xba7111df073](this=0x08fcfc82ef71 <Object map = 0x8fcc88bf629>,0x08fc48a47081 <JSBoundFunction (BoundTargetFunction 0x8fc14c85ef9)>)