Skip to content

Commit

Permalink
Updated call semantics (#56)
Browse files Browse the repository at this point in the history
- Update pallet-revive dependency
- Implement calls according to pallet-revive call semantics
- Switch to the new return data API in pallet revive and get rid of return data buffer
- Remove a bunch of resulting dead code
  • Loading branch information
xermicus authored Sep 28, 2024
1 parent 066acc4 commit 6585973
Show file tree
Hide file tree
Showing 24 changed files with 1,001 additions and 886 deletions.
940 changes: 478 additions & 462 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ log = { version = "0.4" }
# polkadot-sdk and friends
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
scale-info = { version = "2.11.1", default-features = false }
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "71c768a9e1a467c629adc68423e47e37c855cd77" }
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "c77095f51119d2eccdc54d2f3518bed0ffbd6d53" }

# llvm
[workspace.dependencies.inkwell]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/bit_length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub const BIT_LENGTH_ETH_ADDRESS: usize =
pub const BIT_LENGTH_WORD: usize = crate::byte_length::BYTE_LENGTH_WORD * BIT_LENGTH_BYTE;

/// Bit length of the runtime value type.
pub const BIT_LENGTH_VALUE: usize = crate::byte_length::BYTE_LENGTH_VALUE * BIT_LENGTH_BYTE;
pub const BIT_LENGTH_VALUE: usize = BIT_LENGTH_WORD;

/// Bit length of thre runimte block number type.
pub const BIT_LENGTH_BLOCK_NUMBER: usize =
Expand Down
16 changes: 8 additions & 8 deletions crates/integration/codesize.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"Baseline": 878,
"Computation": 4305,
"DivisionArithmetics": 39774,
"ERC20": 53405,
"Events": 1693,
"FibonacciIterative": 2917,
"Flipper": 3570,
"SHA1": 32557
"Baseline": 912,
"Computation": 4413,
"DivisionArithmetics": 40689,
"ERC20": 54374,
"Events": 1726,
"FibonacciIterative": 3015,
"Flipper": 3612,
"SHA1": 32865
}
61 changes: 52 additions & 9 deletions crates/integration/contracts/Call.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,62 @@

pragma solidity ^0.8;

contract Call {
function value_transfer(address payable destination) public payable {
destination.transfer(msg.value);
}
/* runner.json
{
"differential": true,
"actions": [
{
"Upload": {
"code": {
"Solidity": {
"contract": "Callee"
}
}
}
},
{
"Instantiate": {
"code": {
"Solidity": {
"contract": "Caller"
}
}
}
},
{
"Call": {
"dest": {
"Instantiated": 0
},
"value": 123,
"data": "1eb16e5b000000000000000000000000d8b934580fce35a11b58c6d73adee468a2833fa8"
}
},
{
"Call": {
"dest": {
"Instantiated": 0
},
"data": "5a6535fc00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004cafebabe00000000000000000000000000000000000000000000000000000000"
}
}
]
}
*/

contract Callee {
function echo(bytes memory payload) public pure returns (bytes memory) {
return payload;
}
}

contract Caller {
function value_transfer(address payable destination) public payable {
destination.transfer(msg.value);
}

function call(
address callee,
bytes memory payload
) public pure returns (bytes memory) {
return Call(callee).echo(payload);
function call(bytes memory payload) public returns (bytes memory) {
Callee callee = new Callee();
return callee.echo(payload);
}
}
63 changes: 57 additions & 6 deletions crates/integration/contracts/Create.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,64 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.24;
pragma solidity ^0.8;

contract CreateA {
address creator;
/* runner.json
{
"differential": true,
"actions": [
{
"Upload": {
"code": {
"Solidity": {
"contract": "CreateA"
}
}
}
},
{
"Instantiate": {
"code": {
"Solidity": {
"contract": "CreateB"
}
}
}
},
{
"Call": {
"dest": {
"Instantiated": 0
},
"value": 10000
}
},
{
"Call": {
"dest": {
"Instantiated": 0
}
}
},
{
"Call": {
"dest": {
"Instantiated": 0
}
}
},
{
"Call": {
"dest": {
"Instantiated": 0
}
}
}
]
}
*/

constructor() payable {
creator = msg.sender;
}
contract CreateA {
constructor() payable {}
}

contract CreateB {
Expand Down
24 changes: 13 additions & 11 deletions crates/integration/contracts/Crypto.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,32 @@ pragma solidity ^0.8.24;

/* runner.json
{
"actions": [
"differential": true,
"actions": [
{
"Instantiate": {}
"Instantiate": {
"code": {
"Solidity": {
"contract": "TestSha3"
}
}
}
},
{
"Call": {
"dest": {
"Instantiated": 0
"Instantiated": 0
},
"data": "f9fbd5540000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000c68656c6c6f20776f726c64210000000000000000000000000000000000000000"
}
},
{
"VerifyCall": {
"success": true,
"output": "57caa176af1ac0433c5df30e8dabcd2ec1af1e92a26eced5f719b88458777cd6"
}
}
]
}
*/

contract TestSha3 {
function test(string memory _pre) external payable returns (bytes32 hash) {
hash = keccak256(bytes(_pre));
function test(string memory _pre) external payable returns (bytes32) {
bytes32 hash = keccak256(bytes(_pre));
return bytes32(uint(hash) + 1);
}
}
53 changes: 53 additions & 0 deletions crates/integration/contracts/ReturnDataOob.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8;

/* runner.json
{
"differential": true,
"actions": [
{
"Upload": {
"code": {
"Solidity": {
"contract": "Callee"
}
}
}
},
{
"Instantiate": {
"code": {
"Solidity": {
"contract": "ReturnDataOob"
}
}
}
},
{
"Call": {
"dest": {
"Instantiated": 0
}
}
}
]
}
*/

contract Callee {
function echo(bytes memory payload) public pure returns (bytes memory) {
return payload;
}
}

contract ReturnDataOob {
fallback() external {
new Callee().echo(hex"1234");
assembly {
let pos := mload(64)
let size := add(returndatasize(), 1)
returndatacopy(pos, 0, size)
}
}
}
54 changes: 54 additions & 0 deletions crates/integration/contracts/Transfer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8;

/* runner.json
{
"differential": true,
"actions": [
{
"Instantiate": {
"code": {
"Solidity": {
"contract": "Transfer"
}
},
"value": 11
}
},
{
"Call": {
"dest": {
"Instantiated": 0
},
"data": "1c8d16b30000000000000000000000000303030303030303030303030303030303030303000000000000000000000000000000000000000000000000000000000000000a"
}
},
{
"Call": {
"dest": {
"Instantiated": 0
},
"data": "fb9e8d0500000000000000000000000003030303030303030303030303030303030303030000000000000000000000000000000000000000000000000000000000000001"
}
}
]
}
*/

contract Transfer {
constructor() payable {
transfer_self(msg.value);
}

function address_self() internal view returns (address payable) {
return payable(address(this));
}

function transfer_self(uint _amount) public payable {
transfer_to(address_self(), _amount);
}

function transfer_to(address payable _dest, uint _amount) public payable {
_dest.transfer(_amount);
}
}
Loading

0 comments on commit 6585973

Please sign in to comment.