Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delegatecall causes execution error. #235

Closed
Subway2023 opened this issue Feb 25, 2025 · 1 comment · Fixed by paritytech/polkadot-sdk#7729 or #243
Closed

Delegatecall causes execution error. #235

Subway2023 opened this issue Feb 25, 2025 · 1 comment · Fixed by paritytech/polkadot-sdk#7729 or #243
Assignees

Comments

@Subway2023
Copy link

Resolc version: 0.1.0-dev.9+commit.82ab39d.llvm-18.1.8

contract C {
    function delegateToLibrary() external returns (bool) {
        address testAddress=0x0000000000000000000000000000000000000000;
        (bool success, ) = testAddress.delegatecall(
            abi.encodeWithSignature("test()")
        );
        return success;
    }
}

Run with resolc

I have set up an execution environment that can directly execute the bytecode generated by revive compilation.

compile

resolc --solc solc test.sol --combined-json hashes,bin,abi -o /tmp/tmpdh_0t_pr --overwrite

execute

revive/target/debug/revive-runner 50564d00009509000000000000010700c14000c000400480bb0a000000000e0000001c0000002a000000370000004400000054000000640000006f0000008100000063616c6c5f646174615f636f707963616c6c5f646174615f6c6f616463616c6c5f646174615f73697a6564656c65676174655f63616c6c7265665f74696d655f6c65667472657475726e5f646174615f636f707972657475726e5f646174615f73697a657365616c5f72657475726e7365745f696d6d757461626c655f6461746176616c75655f7472616e73666572726564051102876a0463616c6c8771066465706c6f790688aa1e02877a5d0076007b009a00040134014a015c0180011f02300256028102a902160323039003cf034c046f04d4040605d2050b06be0600072b0754077107790764798b7a103307520a41330a000001ac8a39c8980883871f8477e054370000010a330732003908000002ae78143d0700000264783307200002c8870732003307200002c88707320032009511f07b10087b1584750133073308501002a73e070800020a02013e071000023b0520000351050750100409501006e6009511c07b10387b15307b16289515408411e064163307403308205010086bff5107b3003308080002210358000221035000022103480002140700000000000000807b68103e076000029517e08477e07b67186471491718491710491708490783770a0901826a1882a71082a81882a90882aad49808d4a707d4870752074b33078000330850100a01ff510749826710837780007b6718330833090a01390814000251080d330740000383770a080133078000330850100cd1fe510719330782681833090a07013307330850100ebbfe5207040081681033070133093300100a07019511e0fe7b1018017b1510017b160801951520018411e0641633074033082050101285fe5107a30033090800023308100002210358000221035000027b68383908100002140700000000000000803e076000027b693021034800025418035f8367800033080a010180679c00977720140800000000d1a7329bab87419517e08477e07b67286471491718491710491708490783770a0901826a2882a71082a81882a90882aad49808d4a707d4870752070c82673881775517041233073308501014e6fd5207de03003307a000330820501016d5fd5107f38268304928b8004928b0004928a8004928a000f8a8fd6d33078000330820501018affd5107cd826830492890004928880049288000140700000000000000047b87980033074033082050101a84fd5107a2826830491850491848491840140700000000000000c07b87583307800033082050101c5cfd51077aff826730827890007b6838827880007b6828827898007b6820827788007b67180a04014926a8004926a0008267186f778268206f8a8268286f888269386f99d49808d47a09d48909989920d48707977720d497074826b00052071fff7b6a3883a83307a00050101eeffc51070dff33073308501020e2fc510700ff4826c0004926f800ff4926f000ff4926e800ff4926e000ff9567a0009777209877208269309598a000978820988820826b3897bb20d48b0b9798209888209569c000979920d4890c836ae0003308ff3309ff0a037b67380a06015207dd0033074033082050102275fc510793fe826a3082a74882a85882a94082aa506f7b6f87d4b708d4a9096f99d49808988820d4b909979920d49808520865fe83773308207b672850102436fc510754fe826738887901826830826728c8780878891f46181e46181d46181c46181b46181a46181946181846181746181646181546181446181346181246181146181046180f46180e46180d46180c46180b46180a4618094618084618074618064618054618044618034618024618017b68384608330820501026b9fb5107d7fd81683833092033070a070a0628050a06017b672833074033082050102896fb5107b4fd826a3082a75882a85082a94882aa406f727b62206f837b63186f947b64106fac7b6c0882682895871fd887088477e0957920d87907c8780ad88a0bda770b4916587b6c787b64707b63687b62607b69407b6a489567609568407b6b5050102a3c01826808826718d48707826910826820d49808d47808988820d49707977720d4870752072efd8167203308207b6750102cfffa51071dfd8267308268c887078268286f8878781846171746171646171546171446171346171246171146171046170f46170e46170d46170c46170b46170a461709461708461707461706461705461704461703461702461701460798893878791f98893078791e98892878791d98892078791c98891878791b98891078791a9888087878190a0601826810826908d498081409e0ffffff00000000826a20d89a09826a1894a994897b6728510972fc826728987720520768fc82678377208168287b67187b682050102e33fa510751fc826730826818be87078268287a6800018368000133090a050181670001826820ac872dfc288bfd81683033070133093300300a07019511d87b10207b15187b16108273188274108279088270828c828218828508828a1095c61fd8c60bc8b507d85705dabb05c85a08d8a80a8466e07b1008c86000d86006c8970bc86b0cd37c0bd87c05dab605c8480bc8b505d8b506d88b07c83202c8a208c88707c876068e678e58db6708d465078ecbdb780b520b72821708d87007d39c08d89c09da8709d84507d33608d8360ada870ad34507d48707da790a520a4b7b1c7b100833074033082050103247f9510799006f6733080800026f59821a6faa821b086fbb3e0b6000023e0a5800023e095000023e074800028210208215188216109511283200330820330750103405f9510757330508000221032000022103180002210310000221030800024e487b71330704330820501036daf851072c4815200000004148151c48151848151448151048150c4815084815043308243307501038b1f85207040083583307013309240a07330733003a28e3f8330750103adef833070150103cd6f800a58424092a2414524825a5223484444892a424440821049090a424d5242949a29044ea9050a390522b64521a1111290911420809018484881a0920494a524d9292244585180949440444421211014412922401241222914824d28894524a92241129425488082184481249922492484a23099124a9a4244994844892244992244992244992244992941049559384489294524a9224499224499290244992249242a4a42449922449922449929224499224699200925422899224449244d44824294d922495244992244992244992a492922449922449494214aa14420849520a092184004948204992a490259514120200 9b32a7d1
thread 'main' panicked at crates/runner/src/main.rs:168:9:
assertion `left == right` failed: contract execution result mismatch: Exec { result: ContractResult { gas_consumed: Weight { ref_time: 106829783, proof_size: 4574 }, gas_required: Weight { ref_time: 106829783, proof_size: 4574 }, storage_deposit: StorageDeposit::Charge(0), result: Err(Module(ModuleError { index: 3, error: [6, 0, 0, 0], message: Some("CodeNotFound") })) }, wall_time: 2.061607ms }
  left: true
 right: false
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Run with remix

0x0000000000000000000000000000000000000000000000000000000000000001
@xermicus
Copy link
Member

Thanks for reporting this! Currently our runtime returns with an error if there is no contract behind the target address which is inconsistent with what the EVM does. This change will fix it: paritytech/polkadot-sdk#7729

github-merge-queue bot pushed a commit to paritytech/polkadot-sdk that referenced this issue Feb 26, 2025
This PR changes the behavior of delegate calls when the callee is not a
contract account: Instead of returning a `CodeNotFound` error, this is
allowed and the caller observes a successful call with empty output.

The change makes for example the following contract behave the same as
on EVM:

```Solidity
contract DelegateCall {
    function delegateToLibrary() external returns (bool) {
        address testAddress = 0x0000000000000000000000000000000000000000;
        (bool success, ) = testAddress.delegatecall(
            abi.encodeWithSignature("test()")
        );
        return success;
    }
}
```

Closes paritytech/revive#235

---------

Signed-off-by: xermicus <[email protected]>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
xermicus added a commit that referenced this issue Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants