From dacfd39c6c33525a5a66060c286a0827ae38ecbd Mon Sep 17 00:00:00 2001 From: James Hinshelwood Date: Thu, 12 Dec 2024 15:47:48 +0000 Subject: [PATCH] Always check for call success in `ScillaConnector` (#735) --- .../contracts/ScillaConnector.sol | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/contracts/experimental/ERC20ProxyForZRC2/contracts/ScillaConnector.sol b/contracts/experimental/ERC20ProxyForZRC2/contracts/ScillaConnector.sol index b9bff18e9..3b4bd994a 100644 --- a/contracts/experimental/ERC20ProxyForZRC2/contracts/ScillaConnector.sol +++ b/contracts/experimental/ERC20ProxyForZRC2/contracts/ScillaConnector.sol @@ -25,8 +25,9 @@ library ScillaConnector { ); uint256 argsLength = encodedArgs.length; + bool success; assembly { - let alwaysSuccessForThisPrecompile := call( + success := call( gas(), SCILLA_CALL_PRECOMPILE_ADDRESS, 0, @@ -36,6 +37,7 @@ library ScillaConnector { 0 ) } + require(success); } @@ -61,8 +63,9 @@ library ScillaConnector { ); uint256 argsLength = encodedArgs.length; + bool success; assembly { - let alwaysSuccessForThisPrecompile := call( + success := call( gas(), SCILLA_CALL_PRECOMPILE_ADDRESS, 0, @@ -72,6 +75,7 @@ library ScillaConnector { 0 ) } + require(success); } /** @@ -99,8 +103,9 @@ library ScillaConnector { ); uint256 argsLength = encodedArgs.length; + bool success; assembly { - let alwaysSuccessForThisPrecompile := call( + success := call( gas(), SCILLA_CALL_PRECOMPILE_ADDRESS, 0, @@ -110,6 +115,7 @@ library ScillaConnector { 0 ) } + require(success); } /** @@ -126,8 +132,9 @@ library ScillaConnector { uint256 argsLength = encodedArgs.length; bytes memory output = new bytes(36); + bool success; assembly { - let alwaysSuccessForThisPrecompile := staticcall( + success := staticcall( gas(), SCILLA_STATE_READ_PRECOMPILE_ADDRESS, add(encodedArgs, 0x20), @@ -136,6 +143,7 @@ library ScillaConnector { 32 ) } + require(success); return abi.decode(output, (uint128)); } @@ -154,8 +162,9 @@ library ScillaConnector { uint256 argsLength = encodedArgs.length; bytes memory output = new bytes(36); + bool success; assembly { - let alwaysSuccessForThisPrecompile := staticcall( + success := staticcall( gas(), SCILLA_STATE_READ_PRECOMPILE_ADDRESS, add(encodedArgs, 0x20), @@ -164,6 +173,7 @@ library ScillaConnector { 32 ) } + require(success); return abi.decode(output, (uint32)); } @@ -183,6 +193,8 @@ library ScillaConnector { bool success; bytes memory output = new bytes(128); uint256 output_len = output.length - 4; + + bool success; assembly { success := staticcall( gas(), @@ -218,8 +230,9 @@ library ScillaConnector { uint256 argsLength = encodedArgs.length; bytes memory output = new bytes(36); + bool success; assembly { - let alwaysSuccessForThisPrecompile := staticcall( + success := staticcall( gas(), SCILLA_STATE_READ_PRECOMPILE_ADDRESS, add(encodedArgs, 0x20), @@ -228,6 +241,7 @@ library ScillaConnector { 32 ) } + require(success); return abi.decode(output, (uint128)); } @@ -255,8 +269,9 @@ library ScillaConnector { uint256 argsLength = encodedArgs.length; bytes memory output = new bytes(36); + bool success; assembly { - let alwaysSuccessForThisPrecompile := staticcall( + success := staticcall( gas(), SCILLA_STATE_READ_PRECOMPILE_ADDRESS, add(encodedArgs, 0x20), @@ -265,6 +280,7 @@ library ScillaConnector { 32 ) } + require(success); return abi.decode(output, (uint128)); }