feat: Rebrand Polkadot/Substrate references to PezkuwiChain
This commit systematically rebrands various references from Parity Technologies' Polkadot/Substrate ecosystem to PezkuwiChain within the kurdistan-sdk. Key changes include: - Updated external repository URLs (zombienet-sdk, parity-db, parity-scale-codec, wasm-instrument) to point to pezkuwichain forks. - Modified internal documentation and code comments to reflect PezkuwiChain naming and structure. - Replaced direct references to with or specific paths within the for XCM, Pezkuwi, and other modules. - Cleaned up deprecated issue and PR references in various and files, particularly in and modules. - Adjusted image and logo URLs in documentation to point to PezkuwiChain assets. - Removed or rephrased comments related to external Polkadot/Substrate PRs and issues. This is a significant step towards fully customizing the SDK for the PezkuwiChain ecosystem.
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
contract Arithmetic {
|
||||
// We don't run the optimizer to avoid constant folding
|
||||
function testArithmetic() public {
|
||||
// ADD tests
|
||||
uint256 addResult;
|
||||
assembly {
|
||||
addResult := add(20, 22)
|
||||
}
|
||||
require(addResult == 42, "ADD basic");
|
||||
|
||||
// SUB tests
|
||||
uint256 subResult;
|
||||
assembly {
|
||||
subResult := sub(42, 20)
|
||||
}
|
||||
require(subResult == 22, "SUB basic");
|
||||
|
||||
// MUL tests
|
||||
uint256 mulResult;
|
||||
assembly {
|
||||
mulResult := mul(20, 22)
|
||||
}
|
||||
require(mulResult == 440, "MUL basic");
|
||||
|
||||
// DIV tests
|
||||
uint256 divResult;
|
||||
assembly {
|
||||
divResult := div(100, 5)
|
||||
}
|
||||
require(divResult == 20, "DIV basic");
|
||||
|
||||
// SDIV tests
|
||||
int256 sdivResult1;
|
||||
assembly {
|
||||
sdivResult1 := sdiv(sub(0, 100), 5)
|
||||
}
|
||||
require(sdivResult1 == -20, "SDIV neg/pos");
|
||||
|
||||
int256 sdivResult2;
|
||||
assembly {
|
||||
sdivResult2 := sdiv(100, sub(0, 5))
|
||||
}
|
||||
require(sdivResult2 == -20, "SDIV pos/neg");
|
||||
|
||||
int256 sdivResult3;
|
||||
assembly {
|
||||
sdivResult3 := sdiv(sub(0, 100), sub(0, 5))
|
||||
}
|
||||
require(sdivResult3 == 20, "SDIV neg/neg");
|
||||
|
||||
// REM/MOD tests
|
||||
uint256 modResult;
|
||||
assembly {
|
||||
modResult := mod(100, 7)
|
||||
}
|
||||
require(modResult == 2, "REM basic");
|
||||
|
||||
// SMOD tests
|
||||
int256 smodResult1;
|
||||
assembly {
|
||||
smodResult1 := smod(sub(0, 100), 7)
|
||||
}
|
||||
require(smodResult1 == -2, "SMOD neg dividend");
|
||||
|
||||
int256 smodResult2;
|
||||
assembly {
|
||||
smodResult2 := smod(100, sub(0, 7))
|
||||
}
|
||||
require(smodResult2 == 2, "SMOD neg divisor");
|
||||
|
||||
// ADDMOD tests
|
||||
uint256 addmodResult;
|
||||
assembly {
|
||||
addmodResult := addmod(10, 15, 7)
|
||||
}
|
||||
require(addmodResult == 4, "ADDMOD basic");
|
||||
|
||||
// MULMOD tests
|
||||
uint256 mulmodResult;
|
||||
assembly {
|
||||
mulmodResult := mulmod(10, 15, 7)
|
||||
}
|
||||
require(mulmodResult == 3, "MULMOD basic");
|
||||
|
||||
// EXP tests
|
||||
uint256 expResult1;
|
||||
assembly {
|
||||
expResult1 := exp(2, 3)
|
||||
}
|
||||
require(expResult1 == 8, "EXP basic");
|
||||
|
||||
uint256 expResult2;
|
||||
assembly {
|
||||
expResult2 := exp(10, 0)
|
||||
}
|
||||
require(expResult2 == 1, "EXP zero exponent");
|
||||
|
||||
uint256 expResult3;
|
||||
assembly {
|
||||
expResult3 := exp(0, 5)
|
||||
}
|
||||
require(expResult3 == 0, "EXP zero base");
|
||||
|
||||
// EXP overflow test: 2^256 mod 2^256 = 0
|
||||
uint256 expResult;
|
||||
assembly {
|
||||
expResult := exp(2, 256)
|
||||
}
|
||||
require(expResult == 0, "EXP overflow");
|
||||
|
||||
// EXP test: 2^255 should not overflow
|
||||
assembly {
|
||||
expResult := exp(2, 255)
|
||||
}
|
||||
require(expResult == (1 << 255), "EXP 2^255");
|
||||
|
||||
// SIGNEXTEND tests
|
||||
uint256 result1;
|
||||
assembly {
|
||||
result1 := signextend(0, 0xff)
|
||||
}
|
||||
require(result1 == type(uint256).max, "SIGNEXTEND negative byte");
|
||||
uint256 result2;
|
||||
assembly {
|
||||
result2 := signextend(0, 0x7f)
|
||||
}
|
||||
require(result2 == 0x7f, "SIGNEXTEND positive byte");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
contract Bitwise {
|
||||
function testBitwise() public pure {
|
||||
require(5 < 10, "LT basic");
|
||||
require(type(uint256).max - 1 < type(uint256).max, "LT max");
|
||||
|
||||
require(10 > 5, "GT basic");
|
||||
require(type(uint256).max > type(uint256).max - 1, "GT max");
|
||||
|
||||
require(5 != 10, "NEQ basic");
|
||||
require(10 == 10, "EQ basic");
|
||||
require(type(uint256).max == type(uint256).max, "EQ max");
|
||||
|
||||
require(int256(-5) < int256(10), "SLT basic");
|
||||
require(type(int256).min < 0, "SLT min");
|
||||
|
||||
require(int256(5) > int256(-10), "SGT basic");
|
||||
require(0 > type(int256).min, "SGT min");
|
||||
|
||||
require((5 & 3) == 1, "AND basic");
|
||||
require((5 | 3) == 7, "OR basic");
|
||||
require((5 ^ 3) == 6, "XOR basic");
|
||||
require(~uint256(0) == type(uint256).max, "NOT basic");
|
||||
|
||||
require((1 << 3) == 8, "SHL basic");
|
||||
require((8 >> 3) == 1, "SHR basic");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
contract BlockInfo {
|
||||
function blockNumber() public view returns (uint64) {
|
||||
return uint64(block.number);
|
||||
}
|
||||
|
||||
function coinbase() public view returns (address) {
|
||||
return block.coinbase;
|
||||
}
|
||||
|
||||
function timestamp() public view returns (uint64) {
|
||||
return uint64(block.timestamp);
|
||||
}
|
||||
|
||||
function difficulty() public view returns (uint64) {
|
||||
return uint64(block.difficulty);
|
||||
}
|
||||
|
||||
function gaslimit() public view returns (uint64) {
|
||||
return uint64(block.gaslimit);
|
||||
}
|
||||
|
||||
function chainid() public view returns (uint64) {
|
||||
return uint64(block.chainid);
|
||||
}
|
||||
|
||||
function basefee() public view returns (uint64) {
|
||||
return uint64(block.basefee);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
pragma solidity >=0.8.0;
|
||||
|
||||
contract Callee {
|
||||
uint64 public stored;
|
||||
|
||||
function echo(uint64 _data) external pure returns (uint64 data) {
|
||||
data = _data;
|
||||
}
|
||||
|
||||
function whoSender() external view returns (address) {
|
||||
return msg.sender;
|
||||
}
|
||||
|
||||
function store(uint64 _data) external {
|
||||
stored = _data;
|
||||
}
|
||||
|
||||
function revert() public pure returns (uint64) {
|
||||
require(false, "This is a revert");
|
||||
return 42; // never reached
|
||||
}
|
||||
|
||||
function invalid() public pure {
|
||||
assembly {
|
||||
invalid()
|
||||
}
|
||||
}
|
||||
|
||||
function stop() public pure {
|
||||
assembly {
|
||||
stop()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
pragma solidity >=0.8.0;
|
||||
|
||||
// Contract that always reverts in constructor
|
||||
contract ChildRevert {
|
||||
constructor() {
|
||||
revert("ChildRevert: revert in constructor");
|
||||
}
|
||||
}
|
||||
|
||||
contract Caller {
|
||||
function normal(address _callee, uint64 _value, bytes memory _data, uint64 _gas)
|
||||
external
|
||||
returns (bool success, bytes memory output)
|
||||
{
|
||||
(success, output) = _callee.call{value: _value, gas: _gas}(_data);
|
||||
}
|
||||
|
||||
function delegate(address _callee, bytes memory _data, uint64 _gas)
|
||||
external
|
||||
returns (bool success, bytes memory output)
|
||||
{
|
||||
(success, output) = _callee.delegatecall{gas: _gas}(_data);
|
||||
}
|
||||
|
||||
function staticCall(
|
||||
// Don't rename to `static` (it's a Rust keyword).
|
||||
address _callee,
|
||||
bytes memory _data,
|
||||
uint64 _gas
|
||||
) external view returns (bool success, bytes memory output) {
|
||||
(success, output) = _callee.staticcall{gas: _gas}(_data);
|
||||
}
|
||||
|
||||
function create(bytes memory initcode) external payable returns (address addr) {
|
||||
assembly {
|
||||
// CREATE with no value
|
||||
addr := create(0, add(initcode, 0x20), mload(initcode))
|
||||
if iszero(addr) {
|
||||
// bubble failure
|
||||
let returnDataSize := returndatasize()
|
||||
returndatacopy(0, 0, returnDataSize)
|
||||
revert(0, returnDataSize)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createRevert() external returns (address addr) {
|
||||
try new ChildRevert() returns (ChildRevert c) {
|
||||
addr = address(c);
|
||||
} catch (bytes memory reason) {
|
||||
revert(string(reason));
|
||||
}
|
||||
}
|
||||
|
||||
function create2(bytes memory initcode, bytes32 salt) external payable returns (address addr) {
|
||||
assembly {
|
||||
// CREATE2 with no value
|
||||
addr := create2(0, add(initcode, 0x20), mload(initcode), salt)
|
||||
if iszero(addr) {
|
||||
// bubble failure
|
||||
let returnDataSize := returndatasize()
|
||||
returndatacopy(0, 0, returnDataSize)
|
||||
revert(0, returnDataSize)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity >=0.8.0;
|
||||
|
||||
contract CallerWithConstructor {
|
||||
CallerWithConstructorCallee callee;
|
||||
|
||||
constructor() {
|
||||
callee = new CallerWithConstructorCallee();
|
||||
}
|
||||
|
||||
function callBar() public view returns (uint64) {
|
||||
return callee.bar();
|
||||
}
|
||||
}
|
||||
|
||||
contract CallerWithConstructorCallee {
|
||||
function bar() public pure returns (uint64) {
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.4;
|
||||
contract Counter {
|
||||
uint256 public number;
|
||||
|
||||
constructor() {
|
||||
number = 3;
|
||||
}
|
||||
|
||||
function setNumber(uint256 newNumber) public returns (uint256) {
|
||||
number = newNumber;
|
||||
}
|
||||
|
||||
function increment() public {
|
||||
number++;
|
||||
}
|
||||
}
|
||||
|
||||
contract NestedCounter {
|
||||
Counter public counter;
|
||||
uint256 public number;
|
||||
|
||||
|
||||
constructor() {
|
||||
counter = new Counter();
|
||||
counter.setNumber(10);
|
||||
number = 7;
|
||||
}
|
||||
|
||||
function nestedNumber() public returns (uint256) {
|
||||
uint256 currentNumber = counter.setNumber(number);
|
||||
number++;
|
||||
return currentNumber;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8;
|
||||
|
||||
contract Dummy {}
|
||||
@@ -0,0 +1,11 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
contract Fibonacci {
|
||||
function fib(uint64 n) public pure returns (uint64) {
|
||||
if (n <= 1) {
|
||||
return n;
|
||||
}
|
||||
return fib(n - 1) + fib(n - 2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.24;
|
||||
|
||||
contract Host {
|
||||
function balance(address account) public view returns (uint64) {
|
||||
return uint64(account.balance);
|
||||
}
|
||||
|
||||
function extcodesizeOp(address account) public view returns (uint64) {
|
||||
uint256 size;
|
||||
assembly {
|
||||
size := extcodesize(account)
|
||||
}
|
||||
return uint64(size);
|
||||
}
|
||||
|
||||
function extcodehashOp(address account) public view returns (bytes32) {
|
||||
bytes32 hash;
|
||||
assembly {
|
||||
hash := extcodehash(account)
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
function blockhashOp(uint64 blockNumber) public view returns (bytes32) {
|
||||
bytes32 hash;
|
||||
assembly {
|
||||
hash := blockhash(blockNumber)
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
function sloadOp(uint64 slot) public view returns (uint64) {
|
||||
uint256 value;
|
||||
assembly {
|
||||
value := sload(slot)
|
||||
}
|
||||
return uint64(value);
|
||||
}
|
||||
|
||||
function sstoreOp(uint64 slot, uint64 value) public {
|
||||
assembly {
|
||||
sstore(slot, value)
|
||||
}
|
||||
}
|
||||
|
||||
function logOps() public {
|
||||
assembly {
|
||||
log0(0x01, 0x20)
|
||||
log1(0x02, 0x20, 0x11)
|
||||
log2(0x03, 0x20, 0x22, 0x33)
|
||||
log3(0x04, 0x20, 0x44, 0x55, 0x66)
|
||||
log4(0x05, 0x20, 0x77, 0x88, 0x99, 0xaa)
|
||||
}
|
||||
}
|
||||
|
||||
function selfbalance() public view returns (uint64) {
|
||||
return uint64(address(this).balance);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
contract HostEvmOnly {
|
||||
function selfdestructOp(address payable recipient) public {
|
||||
assembly {
|
||||
selfdestruct(recipient)
|
||||
}
|
||||
}
|
||||
function fallback(address payable recipient) public {
|
||||
assembly {
|
||||
selfdestruct(recipient)
|
||||
}
|
||||
}
|
||||
|
||||
function extcodecopyOp(address account, uint64 offset, uint64 size) public view returns (bytes memory code) {
|
||||
code = new bytes(size);
|
||||
assembly {
|
||||
extcodecopy(account, add(code, 32), offset, size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
contract HostEvmOnlyFactory {
|
||||
function createAndSelfdestruct(address payable recipient) public returns (address newContract) {
|
||||
// Deploy a new instance of HostEvmOnly
|
||||
HostEvmOnly newInstance = new HostEvmOnly();
|
||||
newContract = address(newInstance);
|
||||
|
||||
// Call selfdestruct on the newly created contract
|
||||
newInstance.selfdestructOp(recipient);
|
||||
|
||||
return newContract;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.24;
|
||||
|
||||
contract HostTransientMemory {
|
||||
function transientMemoryTest(uint64 slot, uint64 a) public returns (uint64) {
|
||||
uint256 value;
|
||||
assembly {
|
||||
tstore(slot, a)
|
||||
}
|
||||
value = 1;
|
||||
assembly {
|
||||
value := tload(slot)
|
||||
}
|
||||
return uint64(value - a);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.24;
|
||||
|
||||
contract Memory {
|
||||
/// @notice Expands memory to the specified size by writing a byte at that offset
|
||||
/// @param memorySize The memory size in bytes to expand to
|
||||
function expandMemory(uint64 memorySize) public pure returns (bool success) {
|
||||
// Allocate memory by accessing a byte at the specified offset
|
||||
// This will trigger memory expansion up to at least memorySize + 1
|
||||
assembly {
|
||||
// Store a single byte (0xFF) at the memory offset
|
||||
// This forces the EVM to expand memory to accommodate this write
|
||||
mstore8(memorySize, 0xFF)
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function testMemory() public {
|
||||
uint256 value = 0xfe;
|
||||
assembly {
|
||||
mstore(0, value)
|
||||
}
|
||||
uint256 result = 123;
|
||||
assembly {
|
||||
result := mload(0)
|
||||
}
|
||||
require(result == value, "Memory test failed");
|
||||
|
||||
for (uint256 i = 0; i < 32; i++) {
|
||||
assembly {
|
||||
mstore8(i, value)
|
||||
}
|
||||
}
|
||||
assembly {
|
||||
result := mload(0)
|
||||
}
|
||||
require(result == 0xfefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefe, "Memory test failed");
|
||||
|
||||
assembly {
|
||||
result := msize()
|
||||
}
|
||||
require(result == 96, "Memory size test failed");
|
||||
}
|
||||
|
||||
function testMsize(uint64 offset) public returns (uint64) {
|
||||
assembly {
|
||||
mstore(offset, 123)
|
||||
}
|
||||
uint256 value;
|
||||
assembly {
|
||||
value := msize()
|
||||
}
|
||||
return uint64(value);
|
||||
}
|
||||
|
||||
function testMcopy(uint64 dstOffset, uint64 offset, uint64 size, uint64 value) public returns (uint64) {
|
||||
assembly {
|
||||
mstore(dstOffset, 0)
|
||||
}
|
||||
for (uint256 i = 0; i < size; i += 32) {
|
||||
assembly {
|
||||
mstore(add(offset, i), value)
|
||||
}
|
||||
}
|
||||
assembly {
|
||||
mcopy(dstOffset, offset, size)
|
||||
}
|
||||
uint256 result = 123;
|
||||
assembly {
|
||||
result := mload(dstOffset)
|
||||
}
|
||||
return uint64(result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
contract System {
|
||||
constructor(bool panic) {
|
||||
if (panic) {
|
||||
revert("Reverted because revert=true was set as constructor argument");
|
||||
}
|
||||
}
|
||||
|
||||
function keccak256Func(bytes memory data) public pure returns (bytes32) {
|
||||
return keccak256(data);
|
||||
}
|
||||
|
||||
function addressFunc() public view returns (address) {
|
||||
return address(this);
|
||||
}
|
||||
|
||||
function caller() public view returns (address) {
|
||||
return msg.sender;
|
||||
}
|
||||
|
||||
function callvalue() public payable returns (uint64) {
|
||||
return uint64(msg.value);
|
||||
}
|
||||
|
||||
function calldataload(uint64 offset) public pure returns (bytes32) {
|
||||
bytes32 data;
|
||||
assembly {
|
||||
data := calldataload(offset)
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
function calldatasize() public pure returns (uint64) {
|
||||
return uint64(msg.data.length);
|
||||
}
|
||||
|
||||
function calldatacopy(uint64 destOffset, uint64 offset, uint64 size) public pure returns (bytes memory) {
|
||||
bytes memory data = new bytes(size);
|
||||
assembly {
|
||||
calldatacopy(add(data, 0x20), offset, size)
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
function codesize() public pure returns (uint64) {
|
||||
uint256 size;
|
||||
assembly {
|
||||
size := codesize()
|
||||
}
|
||||
return uint64(size);
|
||||
}
|
||||
|
||||
function codecopy(uint64, /* destOffset */ uint64, /* offset */ uint64 size) public pure returns (bytes memory) {
|
||||
bytes memory code = new bytes(size);
|
||||
return code;
|
||||
}
|
||||
|
||||
function returndatasize(address _callee, bytes memory _data, uint64 _gas) public returns (uint64) {
|
||||
uint256 size;
|
||||
_callee.staticcall{gas: _gas}(_data);
|
||||
assembly {
|
||||
size := returndatasize()
|
||||
}
|
||||
return uint64(size);
|
||||
}
|
||||
|
||||
function returndatacopy(
|
||||
address _callee,
|
||||
bytes memory _data,
|
||||
uint64 _gas,
|
||||
uint64 destOffset,
|
||||
uint64 offset,
|
||||
uint64 size
|
||||
) public returns (bytes memory) {
|
||||
bytes memory data = new bytes(size);
|
||||
_callee.staticcall{gas: _gas}(_data);
|
||||
assembly {
|
||||
returndatacopy(add(data, 0x20), offset, size)
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
function gas() public view returns (uint64) {
|
||||
return uint64(gasleft());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.30;
|
||||
|
||||
import "@revive/ISystem.sol";
|
||||
|
||||
contract Terminate {
|
||||
uint8 public constant METHOD_PRECOMPILE = 0;
|
||||
uint8 public constant METHOD_DELEGATE_CALL = 1;
|
||||
uint8 public constant METHOD_SYSCALL = 2;
|
||||
receive() external payable {}
|
||||
constructor(bool skip, uint8 method, address beneficiary) payable {
|
||||
if (skip) {
|
||||
return;
|
||||
}
|
||||
_terminate(method, beneficiary);
|
||||
}
|
||||
|
||||
function echo(uint value) external pure returns (uint) {
|
||||
return value;
|
||||
}
|
||||
|
||||
function terminate(uint8 method, address beneficiary) external {
|
||||
_terminate(method, beneficiary);
|
||||
}
|
||||
|
||||
function indirectDelegateTerminate(address beneficiary) external {
|
||||
bytes memory data = abi.encodeWithSelector(this.terminate.selector, METHOD_PRECOMPILE, beneficiary);
|
||||
(bool success, bytes memory returnData) = address(this).delegatecall(data);
|
||||
if (!success) {
|
||||
assembly {
|
||||
revert(add(returnData, 0x20), mload(returnData))
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Call terminate and forward any revert.
|
||||
/// Internal dispatcher: executes termination by
|
||||
/// - delegatecall (METHOD_DELEGATE_CALL) to system precompile
|
||||
/// - direct call (METHOD_PRECOMPILE) to system precompile
|
||||
/// - selfdestruct (METHOD_SYSCALL) sending balance to beneficiary
|
||||
function _terminate(uint8 method, address beneficiary) private {
|
||||
bytes memory data = abi.encodeWithSelector(ISystem.terminate.selector, beneficiary);
|
||||
(bool success, bytes memory returnData) = (false, "");
|
||||
|
||||
if (method == METHOD_DELEGATE_CALL) {
|
||||
(success, returnData) = SYSTEM_ADDR.delegatecall(data);
|
||||
} else if (method == METHOD_PRECOMPILE) {
|
||||
(success, returnData) = SYSTEM_ADDR.call(data);
|
||||
} else if (method == METHOD_SYSCALL) {
|
||||
assembly {
|
||||
selfdestruct(beneficiary)
|
||||
}
|
||||
// selfdestruct halts execution, so if we reach here, something went wrong.
|
||||
revert("selfdestruct opcode returned");
|
||||
} else {
|
||||
revert("Invalid TerminateMethod");
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
assembly {
|
||||
revert(add(returnData, 0x20), mload(returnData))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.30;
|
||||
|
||||
import { Terminate } from "./Terminate.sol";
|
||||
import { TerminateDelegator } from "./TerminateDelegator.sol";
|
||||
|
||||
contract TerminateCaller {
|
||||
Terminate inner;
|
||||
TerminateDelegator innerCaller;
|
||||
receive() external payable {}
|
||||
|
||||
constructor() payable {}
|
||||
|
||||
function createAndTerminateTwice(uint value, uint8 method1, uint8 method2, address beneficiary) external returns (address) {
|
||||
inner = new Terminate{value: value}(true, method1, beneficiary);
|
||||
inner.terminate(method1, beneficiary);
|
||||
inner.terminate(method2, beneficiary);
|
||||
return address(inner);
|
||||
}
|
||||
|
||||
function sendFundsAfterTerminateAndCreate(uint value, uint8 method, address beneficiary) external returns (address) {
|
||||
inner = new Terminate(true, method, beneficiary);
|
||||
inner.terminate(method, beneficiary);
|
||||
(bool success, ) = address(inner).call{value: value}("");
|
||||
require(success, "terminate reverted");
|
||||
return address(inner);
|
||||
}
|
||||
|
||||
function sendFundsAfterTerminate(address payable terminate_addr, uint value, uint8 method, address beneficiary) external {
|
||||
terminate_addr.call(abi.encodeWithSelector(Terminate.terminate.selector, method, beneficiary));
|
||||
(bool success, ) = terminate_addr.call{value: value}("");
|
||||
require(success, "terminate reverted");
|
||||
}
|
||||
|
||||
function revertAfterTerminate(address terminate_addr, uint8 method, address beneficiary) external {
|
||||
terminate_addr.call(abi.encodeWithSelector(Terminate.terminate.selector, method, beneficiary));
|
||||
revert("Deliberate revert");
|
||||
}
|
||||
|
||||
function delegateCallTerminate(uint value, uint8 method, address beneficiary) external returns (address, address) {
|
||||
inner = new Terminate(true, method, beneficiary);
|
||||
innerCaller = new TerminateDelegator{value: value}();
|
||||
bytes memory data = abi.encodeWithSelector(innerCaller.delegateCallTerminate.selector, address(inner), method, beneficiary);
|
||||
(bool success, ) = address(innerCaller).call(data);
|
||||
require(success, "delegatecall terminate reverted");
|
||||
return (address(innerCaller), address(inner));
|
||||
}
|
||||
|
||||
function callAfterTerminate(uint value, uint8 method) external returns (address, uint) {
|
||||
inner = new Terminate(true, method, payable(address(this)));
|
||||
inner.terminate(0, payable(address(this)));
|
||||
bytes memory data = abi.encodeWithSelector(inner.echo.selector, value);
|
||||
(bool success, bytes memory returnData) = address(inner).call(data);
|
||||
require(success, "call after terminate reverted");
|
||||
return (address(inner), returnData.length == 32 ? abi.decode(returnData, (uint)) : 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.30;
|
||||
|
||||
import { Terminate } from "./Terminate.sol";
|
||||
|
||||
contract TerminateDelegator {
|
||||
receive() external payable {}
|
||||
|
||||
constructor() payable {}
|
||||
|
||||
function delegateCallTerminate(address terminate_addr, uint8 method, address beneficiary) external {
|
||||
bytes memory data = abi.encodeWithSelector(Terminate.terminate.selector, method, beneficiary);
|
||||
(bool success, ) = terminate_addr.delegatecall(data);
|
||||
require(success, "delegatecall terminate reverted");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
contract TransactionInfo {
|
||||
function origin() public view returns (address) {
|
||||
return tx.origin;
|
||||
}
|
||||
|
||||
function gasprice() public view returns (uint64) {
|
||||
return uint64(tx.gasprice);
|
||||
}
|
||||
|
||||
function blobhash(uint64 index) public view returns (bytes32) {
|
||||
return blobhash(index);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{u64_output, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
let balance = u64_output!(api::balance,);
|
||||
assert_eq!(balance, 0);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, u64_output, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(address: &[u8; 20],);
|
||||
|
||||
let reported_free_balance = u64_output!(api::balance_of, address);
|
||||
|
||||
assert_ne!(reported_free_balance, 0);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Returns the base fee back to the caller.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api, ReturnFlags};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
let mut buf = [0; 32];
|
||||
api::base_fee(&mut buf);
|
||||
api::return_value(ReturnFlags::empty(), &buf);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Create a basic block that is larger than we allow.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use core::arch::asm;
|
||||
|
||||
// Export that is never called. We can put code here that should be in the binary
|
||||
// but is never supposed to be run.
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call_never() {
|
||||
// Stores cannot be optimized away because the optimizer cannot
|
||||
// know whether they have side effects.
|
||||
let value: u32 = 42;
|
||||
unsafe {
|
||||
// Repeat 1001 times to intentionally exceed the allowed basic block limit (1000)
|
||||
asm!(".rept 1001", "sw {x}, 0(sp)", ".endr", x = in(reg) value);
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {}
|
||||
@@ -0,0 +1,37 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(expected: &[u8; 20],);
|
||||
|
||||
let mut received = [0; 20];
|
||||
api::block_author(&mut received);
|
||||
|
||||
assert_eq!(expected, &received);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(block_number: &[u8; 32], block_hash: &[u8; 32],);
|
||||
|
||||
let mut buf = [0; 32];
|
||||
api::block_hash(block_number, &mut &mut buf);
|
||||
|
||||
assert_eq!(&buf[..], block_hash);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This calls another contract as passed as its account id.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
callee_input: [u8; 4],
|
||||
callee_addr: &[u8; 20],
|
||||
);
|
||||
|
||||
// Call the callee
|
||||
api::call(
|
||||
uapi::CallFlags::empty(),
|
||||
callee_addr,
|
||||
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
|
||||
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&[0u8; 32], // Value transferred to the contract.
|
||||
callee_input,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This calls another contract as passed as its account id.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, u256_bytes, HostFn, HostFnImpl as api, ReturnErrorCode, ReturnFlags};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
512,
|
||||
callee_addr: &[u8; 20],
|
||||
value: u64,
|
||||
callee_input: [u8],
|
||||
);
|
||||
|
||||
// Call the callee
|
||||
let mut output = [0u8; 512];
|
||||
let output = &mut &mut output[..];
|
||||
|
||||
match api::call(
|
||||
uapi::CallFlags::empty(),
|
||||
callee_addr,
|
||||
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
|
||||
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&u256_bytes(value), // Value transferred to the contract.
|
||||
callee_input,
|
||||
Some(output),
|
||||
) {
|
||||
Ok(_) => api::return_value(uapi::ReturnFlags::empty(), output),
|
||||
Err(ReturnErrorCode::CalleeReverted) => api::return_value(ReturnFlags::REVERT, output),
|
||||
Err(_) => panic!(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This calls another contract and returns the returncode and output.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
polkavm_derive::min_stack_size!(256 * 1024);
|
||||
|
||||
use uapi::{input, u256_bytes, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
512,
|
||||
callee_addr: &[u8; 20],
|
||||
value: u64,
|
||||
callee_input: [u8],
|
||||
);
|
||||
|
||||
// the first 4 bytes are reserved for the return code
|
||||
let mut output = [0u8; 128 * 1024];
|
||||
let output_ptr = &mut &mut output[4..];
|
||||
|
||||
let code = match api::call(
|
||||
uapi::CallFlags::empty(),
|
||||
callee_addr,
|
||||
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
|
||||
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&u256_bytes(value), // Value transferred to the contract.
|
||||
callee_input,
|
||||
Some(output_ptr),
|
||||
) {
|
||||
Ok(_) => 0,
|
||||
Err(code) => code as u32,
|
||||
};
|
||||
|
||||
let len = 4 + output_ptr.len();
|
||||
output[0..4].copy_from_slice(&code.to_le_bytes());
|
||||
api::return_value(uapi::ReturnFlags::empty(), &output[..len]);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This fixture calls the `callerIsOrigin` function on the
|
||||
//! `System` pre-compile.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
let mut output = [0u8; 32];
|
||||
let _ = api::call(
|
||||
uapi::CallFlags::READ_ONLY,
|
||||
&uapi::SYSTEM_PRECOMPILE_ADDR,
|
||||
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
|
||||
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&[0u8; 32], // Value transferred to the contract.
|
||||
&uapi::solidity_selector("callerIsOrigin()"),
|
||||
Some(&mut &mut output[..]),
|
||||
).unwrap();
|
||||
|
||||
api::return_value(uapi::ReturnFlags::empty(), &output);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This fixture calls the `callerIsRoot` function on the
|
||||
//! `System` pre-compile.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
let mut output = [0u8; 32];
|
||||
let _ = api::call(
|
||||
uapi::CallFlags::READ_ONLY,
|
||||
&uapi::SYSTEM_PRECOMPILE_ADDR,
|
||||
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
|
||||
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&[0u8; 32], // Value transferred to the contract.
|
||||
&uapi::solidity_selector("callerIsRoot()"),
|
||||
Some(&mut &mut output[..]),
|
||||
).unwrap();
|
||||
|
||||
api::return_value(uapi::ReturnFlags::empty(), &output);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Expects a call data of [0xFF; 32] and executes the test vectors from
|
||||
//! [https://www.evm.codes/?fork=cancun#37] and some additional tests.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
const TEST_DATA: [u8; 32] = [
|
||||
255, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
];
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
let mut buf = [0; 32];
|
||||
|
||||
api::call_data_copy(&mut &mut buf[..], 0);
|
||||
assert_eq!(buf, [255; 32]);
|
||||
|
||||
api::call_data_copy(&mut &mut buf[..8], 31);
|
||||
assert_eq!(buf, TEST_DATA);
|
||||
|
||||
api::call_data_copy(&mut &mut buf[..], 32);
|
||||
assert_eq!(buf, [0; 32]);
|
||||
|
||||
let mut buf = [255; 32];
|
||||
api::call_data_copy(&mut &mut buf[..], u32::MAX);
|
||||
assert_eq!(buf, [0; 32]);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This uses the call data load API to first the first input byte.
|
||||
//! This single input byte is used as the offset for a second call
|
||||
//! to the call data load API.
|
||||
//! The output of the second API call is returned.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api, ReturnFlags};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
let mut buf = [0; 32];
|
||||
api::call_data_load(&mut buf, 0);
|
||||
|
||||
let offset = buf[31] as u32;
|
||||
let mut buf = [0; 32];
|
||||
api::call_data_load(&mut buf, offset);
|
||||
|
||||
api::return_value(ReturnFlags::empty(), &buf);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Returns the call data size back to the caller.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api, ReturnFlags};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
api::return_value(ReturnFlags::empty(), &api::call_data_size().to_le_bytes());
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This tests that the correct output data is written when the provided
|
||||
//! output buffer length is smaller than what was actually returned during
|
||||
//! calls and instantiations.
|
||||
//!
|
||||
//! To not need an additional callee fixture, we call ourself recursively
|
||||
//! and also instantiate our own code hash (constructor and recursive calls
|
||||
//! always return `BUF_SIZE` bytes of data).
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api, u256_bytes};
|
||||
|
||||
const BUF_SIZE: usize = 8;
|
||||
static DATA: [u8; BUF_SIZE] = [1, 2, 3, 4, 5, 6, 7, 8];
|
||||
|
||||
/// Call `callee_address` with an output buf of size `N`
|
||||
/// and expect the call output to match `expected_output`.
|
||||
fn assert_call<const N: usize>(callee_address: &[u8; 20], expected_output: [u8; BUF_SIZE]) {
|
||||
let mut output_buf = [0u8; BUF_SIZE];
|
||||
let output_buf_capped = &mut &mut output_buf[..N];
|
||||
|
||||
api::call(
|
||||
uapi::CallFlags::ALLOW_REENTRY,
|
||||
callee_address,
|
||||
u64::MAX,
|
||||
u64::MAX,
|
||||
&[u8::MAX; 32],
|
||||
&[0u8; 32],
|
||||
&[],
|
||||
Some(output_buf_capped),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// The (capped) output buf should get properly resized
|
||||
assert_eq!(output_buf_capped.len(), N);
|
||||
assert_eq!(output_buf, expected_output);
|
||||
}
|
||||
|
||||
/// Instantiate this contract with an output buf of size `N`
|
||||
/// and expect the instantiate output to match `expected_output`.
|
||||
fn assert_instantiate<const N: usize>(expected_output: [u8; BUF_SIZE]) {
|
||||
let mut output_buf1 = [0u8; 32];
|
||||
let output1 = &mut &mut output_buf1[..];
|
||||
let _ = api::call(
|
||||
uapi::CallFlags::READ_ONLY,
|
||||
&uapi::SYSTEM_PRECOMPILE_ADDR,
|
||||
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
|
||||
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&[0u8; 32], // Value transferred to the contract.
|
||||
&uapi::solidity_selector("ownCodeHash()"),
|
||||
Some(output1),
|
||||
).unwrap();
|
||||
assert_ne!(output_buf1, [0u8; 32]);
|
||||
|
||||
let mut output_buf = [0u8; BUF_SIZE];
|
||||
let output_buf_capped = &mut &mut output_buf[..N];
|
||||
|
||||
api::instantiate(
|
||||
u64::MAX,
|
||||
u64::MAX,
|
||||
&[u8::MAX; 32],
|
||||
&u256_bytes(0),
|
||||
output_buf1.clone().as_slice(),
|
||||
None,
|
||||
Some(output_buf_capped),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// The (capped) output buf should get properly resized
|
||||
assert_eq!(output_buf_capped.len(), N);
|
||||
assert_eq!(output_buf, expected_output);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {
|
||||
api::return_value(uapi::ReturnFlags::empty(), &DATA);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
let mut caller_address = [0u8; 20];
|
||||
api::caller(&mut caller_address);
|
||||
|
||||
let mut callee_address = [0u8; 20];
|
||||
api::address(&mut callee_address);
|
||||
|
||||
// we already recurse; return data
|
||||
if caller_address == callee_address {
|
||||
api::return_value(uapi::ReturnFlags::empty(), &DATA);
|
||||
}
|
||||
|
||||
assert_call::<0>(&callee_address, [0; 8]);
|
||||
assert_call::<4>(&callee_address, [1, 2, 3, 4, 0, 0, 0, 0]);
|
||||
|
||||
assert_instantiate::<0>([0; 8]);
|
||||
assert_instantiate::<4>([1, 2, 3, 4, 0, 0, 0, 0]);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This fixture calls the `ownCodeHash` function on the
|
||||
//! `System` pre-compile.
|
||||
|
||||
#![allow(unused_imports)]
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use core::num::NonZero;
|
||||
use uapi::{HostFn, HostFnImpl as api, u256_bytes};
|
||||
use hex_literal::hex;
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() { }
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
let mut output_buf = [0u8; 32];
|
||||
let output = &mut &mut output_buf[..];
|
||||
let _ = api::call(
|
||||
uapi::CallFlags::READ_ONLY,
|
||||
&uapi::SYSTEM_PRECOMPILE_ADDR,
|
||||
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
|
||||
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&[0u8; 32], // Value transferred to the contract.
|
||||
&uapi::solidity_selector("ownCodeHash()"),
|
||||
Some(output),
|
||||
).unwrap();
|
||||
assert_ne!(output_buf, [0u8; 32]);
|
||||
api::return_value(uapi::ReturnFlags::empty(), &output_buf);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This calls the supplied dest and transfers 100 balance during this call and copies
|
||||
//! the return code of this call to the output buffer.
|
||||
//! It also forwards its input to the callee.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
100,
|
||||
callee_addr: &[u8; 20],
|
||||
value: &[u8; 32],
|
||||
input: [u8],
|
||||
);
|
||||
|
||||
// Call the callee
|
||||
let err_code = match api::call(
|
||||
uapi::CallFlags::empty(),
|
||||
callee_addr,
|
||||
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
|
||||
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
value, // Value transferred to the contract.
|
||||
input,
|
||||
None,
|
||||
) {
|
||||
Ok(_) => 0u32,
|
||||
Err(code) => code as u32,
|
||||
};
|
||||
|
||||
api::return_value(uapi::ReturnFlags::empty(), &err_code.to_le_bytes());
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
contract CallSelfWithDust {
|
||||
function f() external payable {}
|
||||
|
||||
function call() public payable {
|
||||
this.f{value: 10}();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This fixture calls the account_id with the flags and value.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, u256_bytes, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
256,
|
||||
callee_addr: &[u8; 20],
|
||||
flags: u32,
|
||||
value: u64,
|
||||
forwarded_input: [u8],
|
||||
);
|
||||
|
||||
api::call(
|
||||
uapi::CallFlags::from_bits(flags).unwrap(),
|
||||
callee_addr,
|
||||
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
|
||||
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&u256_bytes(value), // Value transferred to the contract.
|
||||
forwarded_input,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
polkavm_derive::min_stack_size!(512 * 1024);
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
input_size: u32,
|
||||
);
|
||||
|
||||
let input_buf = [0u8; 256 * 1024];
|
||||
let address = [1u8; 20];
|
||||
|
||||
// Call the callee
|
||||
api::call(
|
||||
uapi::CallFlags::empty(),
|
||||
&address,
|
||||
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
|
||||
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&[0; 32], // Value transferred to the contract.
|
||||
&input_buf[..input_size as usize],
|
||||
None,
|
||||
).unwrap();
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This fixture calls the account_id with the 2D Weight limit.
|
||||
//! It returns the result of the call as output data.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
256,
|
||||
callee_addr: &[u8; 20],
|
||||
ref_time: u64,
|
||||
proof_size: u64,
|
||||
forwarded_input: [u8],
|
||||
);
|
||||
|
||||
api::call(
|
||||
uapi::CallFlags::empty(),
|
||||
callee_addr,
|
||||
ref_time,
|
||||
proof_size,
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&[0u8; 32], // value transferred to the contract.
|
||||
forwarded_input,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This calls another contract as passed as its account id.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
value: &[u8; 32],
|
||||
callee_addr: &[u8; 20],
|
||||
);
|
||||
|
||||
// Call the callee
|
||||
api::call(
|
||||
uapi::CallFlags::empty(),
|
||||
callee_addr,
|
||||
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
|
||||
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
value, // Value transferred to the contract.
|
||||
&[0u8; 0], // input
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, u256_bytes, HostFn, HostFnImpl as api, ReturnErrorCode};
|
||||
|
||||
const INPUT: [u8; 8] = [0u8, 1, 34, 51, 68, 85, 102, 119];
|
||||
const REVERTED_INPUT: [u8; 7] = [1u8, 34, 51, 68, 85, 102, 119];
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(code_hash: &[u8; 32], load_code_ref_time: u64, load_code_proof_size: u64,);
|
||||
|
||||
// The value to transfer on instantiation and calls. Chosen to be greater than existential
|
||||
// deposit.
|
||||
let value = u256_bytes(32_768_000_000u64);
|
||||
let salt = [0u8; 32];
|
||||
|
||||
// Callee will use the first 4 bytes of the input to return an exit status.
|
||||
let mut input_deploy = [0; 32 + INPUT.len()];
|
||||
input_deploy[..32].copy_from_slice(code_hash);
|
||||
input_deploy[32..].copy_from_slice(&INPUT);
|
||||
|
||||
let mut reverted_input_deploy = [0; 32 + REVERTED_INPUT.len()];
|
||||
reverted_input_deploy[..32].copy_from_slice(code_hash);
|
||||
reverted_input_deploy[32..].copy_from_slice(&REVERTED_INPUT);
|
||||
|
||||
// Fail to deploy the contract since it returns a non-zero exit status.
|
||||
let res = api::instantiate(
|
||||
u64::MAX, /* How much ref_time weight to devote for the execution. u64::MAX = use
|
||||
* all. */
|
||||
u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&value,
|
||||
&reverted_input_deploy,
|
||||
None,
|
||||
None,
|
||||
Some(&salt),
|
||||
);
|
||||
assert!(matches!(res, Err(ReturnErrorCode::CalleeReverted)));
|
||||
|
||||
// Fail to deploy the contract due to insufficient ref_time weight.
|
||||
let res = api::instantiate(
|
||||
1u64, // too little ref_time weight
|
||||
u64::MAX, /* How much proof_size weight to devote for the execution. u64::MAX =
|
||||
* use all. */
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&value,
|
||||
&input_deploy,
|
||||
None,
|
||||
None,
|
||||
Some(&salt),
|
||||
);
|
||||
assert!(matches!(res, Err(ReturnErrorCode::OutOfResources)));
|
||||
|
||||
// Fail to deploy the contract due to insufficient proof_size weight.
|
||||
let res = api::instantiate(
|
||||
u64::MAX, /* How much ref_time weight to devote for the execution. u64::MAX = use
|
||||
* all. */
|
||||
1u64, // Too little proof_size weight
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&value,
|
||||
&input_deploy,
|
||||
None,
|
||||
None,
|
||||
Some(&salt),
|
||||
);
|
||||
assert!(matches!(res, Err(ReturnErrorCode::OutOfResources)));
|
||||
|
||||
// Deploy the contract successfully.
|
||||
let mut callee = [0u8; 20];
|
||||
|
||||
api::instantiate(
|
||||
u64::MAX, /* How much ref_time weight to devote for the execution. u64::MAX = use
|
||||
* all. */
|
||||
u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&value,
|
||||
&input_deploy,
|
||||
Some(&mut callee),
|
||||
None,
|
||||
Some(&salt),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Call the new contract and expect it to return failing exit code.
|
||||
let res = api::call(
|
||||
uapi::CallFlags::empty(),
|
||||
&callee,
|
||||
u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all.
|
||||
u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&value,
|
||||
&REVERTED_INPUT,
|
||||
None,
|
||||
);
|
||||
assert!(matches!(res, Err(ReturnErrorCode::CalleeReverted)));
|
||||
|
||||
// Fail to call the contract due to insufficient ref_time weight.
|
||||
let res = api::call(
|
||||
uapi::CallFlags::empty(),
|
||||
&callee,
|
||||
load_code_ref_time, // just enough to load the contract
|
||||
load_code_proof_size, // just enough to load the contract
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&value,
|
||||
&INPUT,
|
||||
None,
|
||||
);
|
||||
assert!(matches!(res, Err(ReturnErrorCode::OutOfResources)));
|
||||
|
||||
// Fail to call the contract due to insufficient proof_size weight.
|
||||
let mut output = [0u8; 4];
|
||||
let res = api::call(
|
||||
uapi::CallFlags::empty(),
|
||||
&callee,
|
||||
u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all.
|
||||
load_code_proof_size, // just enough to load the contract
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&value,
|
||||
&INPUT,
|
||||
Some(&mut &mut output[..]),
|
||||
);
|
||||
assert!(matches!(res, Err(ReturnErrorCode::CalleeReverted)));
|
||||
|
||||
let mut decode_buf = [0u8; 4];
|
||||
decode_buf[..4].copy_from_slice(&output[..4]);
|
||||
assert_eq!(u32::from_le_bytes(decode_buf), ReturnErrorCode::OutOfResources as u32);
|
||||
|
||||
// Call the contract successfully.
|
||||
let mut output = [0u8; 4];
|
||||
api::call(
|
||||
uapi::CallFlags::empty(),
|
||||
&callee,
|
||||
u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all.
|
||||
u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&value,
|
||||
&INPUT,
|
||||
Some(&mut &mut output[..]),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(&output, &INPUT[4..])
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This fixture calls caller_is_origin `n` times.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(n: u32, );
|
||||
|
||||
for _ in 0..n {
|
||||
let _ = api::call(
|
||||
uapi::CallFlags::READ_ONLY,
|
||||
&uapi::SYSTEM_PRECOMPILE_ADDR,
|
||||
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
|
||||
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&[0u8; 32], // Value transferred to the contract.
|
||||
&uapi::solidity_selector("callerIsOrigin()"),
|
||||
None,
|
||||
).unwrap();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api, ReturnFlags};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {
|
||||
call()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
let mut buf = [0; 32];
|
||||
api::chain_id(&mut buf);
|
||||
api::return_value(ReturnFlags::empty(), &buf);
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This contract tests the storage APIs. It sets and clears storage values using the different
|
||||
//! versions of the storage APIs.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
include!("../panic_handler.rs");
|
||||
include!("../sol_utils.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api, StorageFlags};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
fn test_storage_operations(flags: StorageFlags) {
|
||||
const KEY: [u8; 32] = [1u8; 32];
|
||||
const VALUE_A: [u8; 32] = [4u8; 32];
|
||||
const ZERO: [u8; 32] = [0u8; 32];
|
||||
let mut small_value_padded = [0u8; 32];
|
||||
small_value_padded[0] = 5;
|
||||
small_value_padded[1] = 6;
|
||||
small_value_padded[2] = 7;
|
||||
|
||||
clear_storage::<api>(flags, &KEY);
|
||||
|
||||
assert_eq!(contains_storage::<api>(flags, &KEY), None);
|
||||
|
||||
let existing = api::set_storage_or_clear(flags, &KEY, &VALUE_A);
|
||||
assert_eq!(existing, None);
|
||||
|
||||
let mut stored: [u8; 32] = [0u8; 32];
|
||||
api::get_storage_or_zero(flags, &KEY, &mut stored);
|
||||
assert_eq!(stored, VALUE_A);
|
||||
|
||||
let existing = api::set_storage_or_clear(flags, &KEY, &ZERO);
|
||||
assert_eq!(existing, Some(32));
|
||||
|
||||
let mut cleared: [u8; 32] = [1u8; 32];
|
||||
api::get_storage_or_zero(flags, &KEY, &mut cleared);
|
||||
assert_eq!(cleared, ZERO);
|
||||
|
||||
assert_eq!(contains_storage::<api>(flags, &KEY), None);
|
||||
|
||||
// Test retrieving a value smaller than 32 bytes
|
||||
api::set_storage_or_clear(flags, &KEY, &small_value_padded);
|
||||
let mut retrieved = [255u8; 32];
|
||||
api::get_storage_or_zero(flags, &KEY, &mut retrieved);
|
||||
|
||||
assert_eq!(retrieved[0], 5);
|
||||
assert_eq!(retrieved[1], 6);
|
||||
assert_eq!(retrieved[2], 7);
|
||||
for i in 3..32 {
|
||||
assert_eq!(retrieved[i], 0, "Byte at position {} should be zero", i);
|
||||
}
|
||||
|
||||
// Clean up
|
||||
clear_storage::<api>(flags, &KEY);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
// Test with regular storage
|
||||
test_storage_operations(StorageFlags::empty());
|
||||
|
||||
// Test with transient storage
|
||||
test_storage_operations(StorageFlags::TRANSIENT);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
address: &[u8; 20],
|
||||
expected_code_hash: &[u8; 32],
|
||||
);
|
||||
|
||||
let mut code_hash = [0u8; 32];
|
||||
api::code_hash(address, &mut code_hash);
|
||||
|
||||
assert!(&code_hash == expected_code_hash);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{u64_output, HostFn, HostFnImpl as api, ReturnFlags};
|
||||
|
||||
fn decide_my_fate() -> ! {
|
||||
match u64_output!(api::value_transferred,) {
|
||||
0 => api::consume_all_gas(),
|
||||
1 => api::return_value(ReturnFlags::REVERT, &[]),
|
||||
_ => api::return_value(ReturnFlags::empty(), &[]),
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {
|
||||
decide_my_fate();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
decide_my_fate();
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(code_hash: &[u8; 32],);
|
||||
|
||||
let mut value = [0; 32];
|
||||
api::value_transferred(&mut value);
|
||||
|
||||
// Deploy the contract with no salt (equivalent to create1).
|
||||
api::instantiate(u64::MAX, u64::MAX, &[u8::MAX; 32], &value, code_hash, None, None, None)
|
||||
.unwrap();
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(128, code_hash: [u8],);
|
||||
|
||||
let mut value = [0; 32];
|
||||
api::value_transferred(&mut value);
|
||||
|
||||
// Deploy the contract with salt (equivalent to create2).
|
||||
let salt = [1u8; 32];
|
||||
api::instantiate(
|
||||
u64::MAX,
|
||||
u64::MAX,
|
||||
&[u8::MAX; 32],
|
||||
&value,
|
||||
code_hash,
|
||||
None,
|
||||
None,
|
||||
Some(&salt),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This calls another contract as passed as its account id. It also creates some storage.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api, StorageFlags};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
buffer,
|
||||
input: [u8; 4],
|
||||
callee: &[u8; 20],
|
||||
deposit_limit: &[u8; 32],
|
||||
);
|
||||
|
||||
// create 4 byte of storage before calling
|
||||
api::set_storage(StorageFlags::empty(), buffer, &[1u8; 4]);
|
||||
|
||||
// Call the callee
|
||||
let ret = api::call(
|
||||
uapi::CallFlags::empty(),
|
||||
callee,
|
||||
u64::MAX, /* How much ref_time weight to devote for the execution. u64::MAX = use all
|
||||
* resources. */
|
||||
u64::MAX, /* How much proof_size weight to devote for the execution. u64::MAX = use all
|
||||
* resources. */
|
||||
deposit_limit,
|
||||
&[0u8; 32], // Value transferred to the contract.
|
||||
input,
|
||||
None,
|
||||
);
|
||||
if let Err(code) = ret {
|
||||
api::return_value(uapi::ReturnFlags::REVERT, &(code as u32).to_le_bytes());
|
||||
};
|
||||
|
||||
// create 8 byte of storage after calling
|
||||
// item of 12 bytes because we override 4 bytes
|
||||
api::set_storage(StorageFlags::empty(), buffer, &[1u8; 12]);
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This instantiates another contract and passes some input to its constructor.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, u256_bytes, HostFn, HostFnImpl as api, StorageFlags};
|
||||
|
||||
static BUFFER: [u8; 16 * 1024 + 1] = [0u8; 16 * 1024 + 1];
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
code_hash: &[u8; 32],
|
||||
input: [u8; 4],
|
||||
deposit_limit: &[u8; 32],
|
||||
);
|
||||
|
||||
let len = u32::from_le_bytes(input.try_into().unwrap());
|
||||
let data = &BUFFER[..len as usize];
|
||||
let mut key = [0u8; 32];
|
||||
key[0] = 1;
|
||||
api::set_storage(StorageFlags::empty(), &key, data);
|
||||
|
||||
let value = u256_bytes(10_000_000_000u64);
|
||||
let salt = [0u8; 32];
|
||||
let mut address = [0u8; 20];
|
||||
let mut deploy_input = [0; 32 + 4];
|
||||
deploy_input[..32].copy_from_slice(code_hash);
|
||||
deploy_input[32..].copy_from_slice(&input);
|
||||
|
||||
let ret = api::instantiate(
|
||||
u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all.
|
||||
u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all.
|
||||
deposit_limit,
|
||||
&value,
|
||||
&deploy_input,
|
||||
Some(&mut address),
|
||||
None,
|
||||
Some(&salt),
|
||||
);
|
||||
if let Err(code) = ret {
|
||||
api::return_value(uapi::ReturnFlags::REVERT, &(code as u32).to_le_bytes());
|
||||
};
|
||||
|
||||
// fail in the caller
|
||||
key[1] = 1;
|
||||
api::set_storage(StorageFlags::empty(), &key, data);
|
||||
|
||||
// Return the deployed contract address.
|
||||
api::return_value(uapi::ReturnFlags::empty(), &address);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This calls another contract as passed as its account id. It also creates some transient storage.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api, StorageFlags};
|
||||
|
||||
static BUFFER: [u8; 416] = [0u8; 416];
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
buffer,
|
||||
len: u32,
|
||||
input: [u8; 4],
|
||||
callee: &[u8; 20],
|
||||
);
|
||||
|
||||
let rounds = len as usize / BUFFER.len();
|
||||
let rest = len as usize / BUFFER.len();
|
||||
for i in 0..rounds {
|
||||
api::set_storage(StorageFlags::TRANSIENT, &i.to_le_bytes(), &BUFFER);
|
||||
}
|
||||
api::set_storage(StorageFlags::TRANSIENT, &u32::MAX.to_le_bytes(), &BUFFER[..rest]);
|
||||
|
||||
// Call the callee
|
||||
api::call(
|
||||
uapi::CallFlags::empty(),
|
||||
callee,
|
||||
u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = all.
|
||||
u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&[0u8; 32], // Value transferred to the contract.
|
||||
input,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
/// Called by the tests.
|
||||
///
|
||||
/// The input bytes encode the data that is directly fed into the Keccak-256 bit
|
||||
/// crypto hash function. The result is put into the output buffer.
|
||||
///
|
||||
/// After contract execution the test driver then asserts that the returned
|
||||
/// values are equal to the expected bytes for the input and hash function.
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
256,
|
||||
input: [u8],
|
||||
);
|
||||
|
||||
let mut output = [0u8; 32];
|
||||
api::hash_keccak_256(input, &mut output);
|
||||
api::return_value(uapi::ReturnFlags::empty(), &output);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api, StorageFlags};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
address: &[u8; 20],
|
||||
ref_time: u64,
|
||||
proof_size: u64,
|
||||
);
|
||||
|
||||
let mut key = [0u8; 32];
|
||||
key[0] = 1u8;
|
||||
|
||||
let mut value = [0u8; 32];
|
||||
let value = &mut &mut value[..];
|
||||
value[0] = 2u8;
|
||||
|
||||
api::set_storage(StorageFlags::empty(), &key, value);
|
||||
api::get_storage(StorageFlags::empty(), &key, value).unwrap();
|
||||
assert!(value[0] == 2u8);
|
||||
|
||||
let input = [0u8; 0];
|
||||
api::delegate_call(
|
||||
uapi::CallFlags::empty(),
|
||||
address,
|
||||
ref_time,
|
||||
proof_size,
|
||||
&[u8::MAX; 32],
|
||||
&input,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
api::get_storage(StorageFlags::empty(), &key, value).unwrap();
|
||||
assert!(value[0] == 1u8);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, u256_bytes, HostFn, HostFnImpl as api, StorageFlags};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
address: &[u8; 20],
|
||||
deposit_limit: u64,
|
||||
);
|
||||
|
||||
let input = [0u8; 0];
|
||||
let ret = api::delegate_call(
|
||||
uapi::CallFlags::empty(),
|
||||
address,
|
||||
u64::MAX,
|
||||
u64::MAX,
|
||||
&u256_bytes(deposit_limit),
|
||||
&input,
|
||||
None,
|
||||
);
|
||||
|
||||
if let Err(code) = ret {
|
||||
api::return_value(uapi::ReturnFlags::REVERT, &(code as u32).to_le_bytes());
|
||||
};
|
||||
|
||||
let mut key = [0u8; 32];
|
||||
key[0] = 1u8;
|
||||
|
||||
let mut value = [0u8; 32];
|
||||
|
||||
api::get_storage(StorageFlags::empty(), &key, &mut &mut value[..]).unwrap();
|
||||
assert!(value[0] == 1u8);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{u64_output, HostFn, HostFnImpl as api, StorageFlags};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
let mut key = [0u8; 32];
|
||||
key[0] = 1u8;
|
||||
|
||||
// Place a value in storage.
|
||||
let mut value = [0u8; 32];
|
||||
let value = &mut &mut value[..];
|
||||
value[0] = 1u8;
|
||||
api::set_storage(StorageFlags::empty(), &key, value);
|
||||
|
||||
// Assert that `value_transferred` is equal to the value
|
||||
// passed to the `caller` contract: 1337.
|
||||
let value = u64_output!(api::value_transferred,);
|
||||
assert_eq!(value, 1337_000_000);
|
||||
|
||||
// Assert that ALICE is the caller of the contract.
|
||||
let mut caller = [0u8; 20];
|
||||
api::caller(&mut caller);
|
||||
assert_eq!(caller, [1u8; 20]);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(address: &[u8; 20],);
|
||||
|
||||
let mut output = [0; 512];
|
||||
let ptr = &mut &mut output[..];
|
||||
|
||||
// Delegate call into passed address.
|
||||
let input = [0u8; 0];
|
||||
api::delegate_call(
|
||||
uapi::CallFlags::empty(),
|
||||
address,
|
||||
u64::MAX,
|
||||
u64::MAX,
|
||||
&[u8::MAX; 32],
|
||||
&input,
|
||||
Some(ptr),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(ptr.len(), 0);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{u256_bytes, u64_output, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
let balance = u64_output!(api::balance,);
|
||||
|
||||
let mut output_buf = [0u8; 32];
|
||||
let output = &mut &mut output_buf[..];
|
||||
let _ = api::call(
|
||||
uapi::CallFlags::READ_ONLY,
|
||||
&uapi::SYSTEM_PRECOMPILE_ADDR,
|
||||
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
|
||||
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&[0u8; 32], // Value transferred to the contract.
|
||||
&uapi::solidity_selector("minimumBalance()"),
|
||||
Some(output),
|
||||
).unwrap();
|
||||
assert_ne!(output_buf, [0u8; 32]);
|
||||
|
||||
let mut u64_buf = [0u8; 8];
|
||||
u64_buf[..8].copy_from_slice(&output_buf[24..32]);
|
||||
let minimum_balance = u64::from_be_bytes(u64_buf);
|
||||
|
||||
// Make the transferred value exceed the balance by adding the minimum balance.
|
||||
let balance = balance + minimum_balance;
|
||||
|
||||
// Try to self-destruct by sending more balance to the 0 address.
|
||||
// The call will fail because a contract transfer has a keep alive requirement.
|
||||
let res = api::call(
|
||||
uapi::CallFlags::empty(),
|
||||
&[0u8; 20],
|
||||
0,
|
||||
0,
|
||||
&[u8::MAX; 32],
|
||||
&u256_bytes(balance),
|
||||
&[],
|
||||
None,
|
||||
);
|
||||
assert!(matches!(res, Err(uapi::ReturnErrorCode::TransferFailed)));
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api, ReturnFlags};
|
||||
|
||||
// Export that is never called. We can put code here that should be in the binary
|
||||
// but is never supposed to be run.
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call_never() {
|
||||
// Make sure the 0xDEADBEEF pattern appears in the binary by
|
||||
// making it opaque to the optimizer. The benchmarking code will
|
||||
// just find and replace this pattern to make the code unique when
|
||||
// necessary.
|
||||
api::return_value(ReturnFlags::empty(), &[0xDE, 0xAD, 0xBE, 0xEF]);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {}
|
||||
@@ -0,0 +1,37 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {
|
||||
let buffer = [1u8, 2, 3, 4];
|
||||
let topics = [[42u8; 32]; 1];
|
||||
api::deposit_event(&topics, &buffer);
|
||||
api::return_value(uapi::ReturnFlags::empty(), &buffer);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
unreachable!()
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
static BUFFER: [u8; 64 * 1024 + 1] = [0u8; 64 * 1024 + 1];
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(len: u32,);
|
||||
|
||||
let data = &BUFFER[..len as usize];
|
||||
let topics = [[0u8; 32]; 0];
|
||||
|
||||
api::deposit_event(&topics, data);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(address: &[u8; 20], expected: u64,);
|
||||
|
||||
let received = api::code_size(address);
|
||||
|
||||
assert_eq!(expected, received);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn add(a: f32, b: f32) -> f32 {
|
||||
a + b
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api, ReturnFlags};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
api::return_value(ReturnFlags::empty(), &api::gas_left().to_le_bytes());
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Returns the block ref_time limit back to the caller.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api, ReturnFlags};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
api::return_value(ReturnFlags::empty(), &api::gas_limit().to_le_bytes());
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Returns the gas price back to the caller.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api, ReturnFlags};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
api::return_value(ReturnFlags::empty(), &api::gas_price().to_le_bytes());
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This fixture calls `gas_price` `n` times.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(n: u32, );
|
||||
|
||||
for _ in 0..n {
|
||||
let _ = api::gas_price();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Tests that the `get_immutable_data` and `set_immutable_data` APIs work.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {
|
||||
input!(data: &[u8; 8],);
|
||||
|
||||
api::set_immutable_data(data);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(data: &[u8; 8],);
|
||||
|
||||
let mut buf = [0; 8];
|
||||
api::get_immutable_data(&mut &mut buf[..]);
|
||||
|
||||
assert_eq!(data, &buf);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, u256_bytes, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(buffer: &[u8; 36],);
|
||||
|
||||
let err_code = match api::instantiate(
|
||||
u64::MAX, /* How much ref_time weight to devote for the execution. u64::MAX = use
|
||||
* all. */
|
||||
u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&u256_bytes(10_000_000_000u64), // Value to transfer.
|
||||
buffer,
|
||||
None,
|
||||
None,
|
||||
Some(&[0u8; 32]), // Salt.
|
||||
) {
|
||||
Ok(_) => 0u32,
|
||||
Err(code) => code as u32,
|
||||
};
|
||||
|
||||
// Exit with success and take transfer return code to the output buffer.
|
||||
api::return_value(uapi::ReturnFlags::empty(), &err_code.to_le_bytes());
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Does two stores to two separate storage items
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api, StorageFlags};
|
||||
|
||||
static BUFFER: [u8; 512] = [0u8; 512];
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
size1: u32,
|
||||
size2: u32,
|
||||
);
|
||||
|
||||
// Place a values in storage sizes are specified in the input buffer.
|
||||
// We don't care about the contents of the storage item.
|
||||
api::set_storage(StorageFlags::empty(), &[1u8; 32], &BUFFER[0..size1 as _]);
|
||||
api::set_storage(StorageFlags::empty(), &[2u8; 32], &BUFFER[0..size2 as _]);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
api::return_value(uapi::ReturnFlags::empty(), &2u32.to_le_bytes());
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn};
|
||||
|
||||
#[polkavm_derive::polkavm_import]
|
||||
extern "C" {
|
||||
pub fn noop();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(rounds: u32, );
|
||||
|
||||
for _ in 0..rounds {
|
||||
unsafe {
|
||||
noop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {
|
||||
ok_trap_revert();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
ok_trap_revert();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
fn ok_trap_revert() {
|
||||
input!(buffer, 4,);
|
||||
match buffer.first().unwrap_or(&0) {
|
||||
1 => api::return_value(uapi::ReturnFlags::REVERT, &[0u8; 0]),
|
||||
2 => panic!(),
|
||||
_ => {},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This creates a large ro section. Even though it is zero
|
||||
//! initialized we expect them to be included into the blob.
|
||||
//! This means it will fail at the blob size check.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api, ReturnFlags};
|
||||
|
||||
static BUFFER: [u8; 1024 * 1024] = [0; 1024 * 1024];
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call_never() {
|
||||
// make sure the buffer is not optimized away
|
||||
api::return_value(ReturnFlags::empty(), &BUFFER);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {}
|
||||
@@ -0,0 +1,48 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This creates a large rw section but with its contents
|
||||
//! included into the blob. It should be rejected for its
|
||||
//! blob size.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api, ReturnFlags};
|
||||
|
||||
static mut BUFFER: [u8; 1024 * 1024] = [42; 1024 * 1024];
|
||||
|
||||
unsafe fn buffer() -> &'static [u8; 1024 * 1024] {
|
||||
let ptr = core::ptr::addr_of!(BUFFER);
|
||||
&*ptr
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub unsafe extern "C" fn call_never() {
|
||||
// make sure the buffer is not optimized away
|
||||
api::return_value(ReturnFlags::empty(), buffer());
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {}
|
||||
@@ -0,0 +1,48 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This creates a large rw section but the trailing zeroes
|
||||
//! are removed by the linker. It should be rejected even
|
||||
//! though the blob is small enough.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api, ReturnFlags};
|
||||
|
||||
static mut BUFFER: [u8; 2 * 1024 * 1024] = [0; 2 * 1024 * 1024];
|
||||
|
||||
unsafe fn buffer() -> &'static [u8; 2 * 1024 * 1024] {
|
||||
let ptr = core::ptr::addr_of!(BUFFER);
|
||||
&*ptr
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub unsafe extern "C" fn call_never() {
|
||||
// make sure the buffer is not optimized away
|
||||
api::return_value(ReturnFlags::empty(), buffer());
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {}
|
||||
@@ -0,0 +1,62 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Tests that the `origin` syscall works.
|
||||
//! The fixture returns the observed origin if the caller is not the origin,
|
||||
//! otherwise call itself recursively and assert the returned origin to match.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
let mut caller = [0; 20];
|
||||
api::caller(&mut caller);
|
||||
|
||||
let mut origin = [0; 20];
|
||||
api::origin(&mut origin);
|
||||
|
||||
if caller != origin {
|
||||
api::return_value(Default::default(), &origin);
|
||||
}
|
||||
|
||||
let mut addr = [0u8; 20];
|
||||
api::address(&mut addr);
|
||||
|
||||
let mut buf = [0u8; 20];
|
||||
api::call(
|
||||
uapi::CallFlags::ALLOW_REENTRY,
|
||||
&addr,
|
||||
u64::MAX,
|
||||
u64::MAX,
|
||||
&[u8::MAX; 32],
|
||||
&[0; 32],
|
||||
&[],
|
||||
Some(&mut &mut buf[..]),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(buf, origin);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// This fixture tests if read-only call works as expected.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
256,
|
||||
callee_addr: &[u8; 20],
|
||||
callee_input: [u8],
|
||||
);
|
||||
|
||||
// Call the callee
|
||||
api::call(
|
||||
uapi::CallFlags::READ_ONLY,
|
||||
callee_addr,
|
||||
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = all.
|
||||
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&[0u8; 32], // Value transferred to the contract.
|
||||
callee_input,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This fixture calls itself as many times as passed as argument.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, ReturnFlags, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(calls_left: u32, );
|
||||
|
||||
// own address
|
||||
let mut addr = [0u8; 20];
|
||||
api::address(&mut addr);
|
||||
|
||||
let mut return_buffer = calls_left.to_le_bytes();
|
||||
|
||||
if calls_left > 0 {
|
||||
let _ = api::call(
|
||||
uapi::CallFlags::ALLOW_REENTRY,
|
||||
&addr,
|
||||
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all resources.
|
||||
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all resources.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&[0u8; 32], // Value transferred to the contract.
|
||||
&(calls_left - 1).to_le_bytes(),
|
||||
Some(&mut &mut return_buffer[..]),
|
||||
);
|
||||
}
|
||||
|
||||
api::return_value(ReturnFlags::empty(), &return_buffer);
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This tests that the `return_data_size` and `return_data_copy` APIs work.
|
||||
//!
|
||||
//! It does so by calling and instantiating the "return_with_data" fixture,
|
||||
//! which always echoes back the input[4..] regardless of the call outcome.
|
||||
//!
|
||||
//! We also check that the saved return data is properly reset after a trap
|
||||
//! and unaffected by plain transfers.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, u256_bytes, HostFn, HostFnImpl as api};
|
||||
|
||||
const INPUT_BUF_SIZE: usize = 128;
|
||||
static INPUT_DATA: [u8; INPUT_BUF_SIZE] = [0xFF; INPUT_BUF_SIZE];
|
||||
/// The "return_with_data" fixture echoes back 4 bytes less than the input
|
||||
const OUTPUT_BUF_SIZE: usize = INPUT_BUF_SIZE - 4;
|
||||
static OUTPUT_DATA: [u8; OUTPUT_BUF_SIZE] = [0xEE; OUTPUT_BUF_SIZE];
|
||||
|
||||
/// Assert correct return data after calls and finally reset the return data.
|
||||
fn assert_return_data_after_call(input: &[u8]) {
|
||||
assert_return_data_size_of(OUTPUT_BUF_SIZE as u64);
|
||||
assert_return_data_copy(&input[4..]);
|
||||
assert_balance_transfer_does_reset();
|
||||
}
|
||||
|
||||
/// Assert that what we get from [api::return_data_copy] matches `whole_return_data`,
|
||||
/// either fully or partially with an offset and limited size.
|
||||
fn assert_return_data_copy(whole_return_data: &[u8]) {
|
||||
// The full return data should match
|
||||
let mut buf = OUTPUT_DATA;
|
||||
let mut full = &mut buf[..whole_return_data.len()];
|
||||
api::return_data_copy(&mut full, 0);
|
||||
assert_eq!(whole_return_data, full);
|
||||
|
||||
// Partial return data should match
|
||||
let mut buf = OUTPUT_DATA;
|
||||
let offset = 5; // we just pick some offset
|
||||
let size = 32; // we just pick some size
|
||||
let mut partial = &mut buf[offset..offset + size];
|
||||
api::return_data_copy(&mut partial, offset as u32);
|
||||
assert_eq!(*partial, whole_return_data[offset..offset + size]);
|
||||
}
|
||||
|
||||
/// This function panics in a recursive contract call context.
|
||||
fn recursion_guard() -> [u8; 20] {
|
||||
let mut caller_address = [0u8; 20];
|
||||
api::caller(&mut caller_address);
|
||||
|
||||
let mut own_address = [0u8; 20];
|
||||
api::address(&mut own_address);
|
||||
|
||||
assert_ne!(caller_address, own_address);
|
||||
|
||||
own_address
|
||||
}
|
||||
|
||||
/// Assert [api::return_data_size] to match the `expected` value.
|
||||
fn assert_return_data_size_of(expected: u64) {
|
||||
assert_eq!(api::return_data_size(), expected);
|
||||
}
|
||||
|
||||
/// Assert the return data to be reset after a balance transfer.
|
||||
fn assert_balance_transfer_does_reset() {
|
||||
api::call(
|
||||
uapi::CallFlags::empty(),
|
||||
&[0u8; 20],
|
||||
u64::MAX,
|
||||
u64::MAX,
|
||||
&[u8::MAX; 32],
|
||||
&u256_bytes(128_000_000),
|
||||
&[],
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
assert_return_data_size_of(0);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(code_hash: &[u8; 32],);
|
||||
|
||||
// We didn't do anything yet; return data size should be 0
|
||||
assert_return_data_size_of(0);
|
||||
|
||||
recursion_guard();
|
||||
|
||||
let mut address_buf = [0; 20];
|
||||
let construct_input = |exit_flag| {
|
||||
let mut input = INPUT_DATA;
|
||||
input[0] = exit_flag;
|
||||
input[9] = 7;
|
||||
input[17 / 2] = 127;
|
||||
input[89 / 2] = 127;
|
||||
input
|
||||
};
|
||||
let mut instantiate = |exit_flag| {
|
||||
let input = construct_input(exit_flag);
|
||||
let mut deploy_input = [0; 32 + INPUT_BUF_SIZE];
|
||||
deploy_input[..32].copy_from_slice(code_hash);
|
||||
deploy_input[32..].copy_from_slice(&input);
|
||||
api::instantiate(
|
||||
u64::MAX,
|
||||
u64::MAX,
|
||||
&[u8::MAX; 32],
|
||||
&[0; 32],
|
||||
&deploy_input,
|
||||
Some(&mut address_buf),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
};
|
||||
let call = |exit_flag, address_buf| {
|
||||
api::call(
|
||||
uapi::CallFlags::empty(),
|
||||
address_buf,
|
||||
u64::MAX,
|
||||
u64::MAX,
|
||||
&[u8::MAX; 32],
|
||||
&[0; 32],
|
||||
&construct_input(exit_flag),
|
||||
None,
|
||||
)
|
||||
};
|
||||
|
||||
instantiate(0).unwrap();
|
||||
assert_return_data_after_call(&construct_input(0)[..]);
|
||||
|
||||
instantiate(1).unwrap_err();
|
||||
assert_return_data_after_call(&construct_input(1)[..]);
|
||||
|
||||
call(0, &address_buf).unwrap();
|
||||
assert_return_data_after_call(&construct_input(0)[..]);
|
||||
|
||||
call(1, &address_buf).unwrap_err();
|
||||
assert_return_data_after_call(&construct_input(1)[..]);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
polkavm_derive::min_stack_size!(512 * 1024);
|
||||
|
||||
use uapi::{ReturnFlags, input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
return_size: u32,
|
||||
);
|
||||
|
||||
let return_buf = [42u8; 256 * 1024];
|
||||
api::return_value(ReturnFlags::empty(), &return_buf[..return_size as usize])
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
include!("../panic_handler.rs");
|
||||
include!("../sol_utils.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api, StorageFlags};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {
|
||||
call();
|
||||
}
|
||||
|
||||
/// Reads the first byte as the exit status and copy all but the first 4 bytes of the input as
|
||||
/// output data.
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
input, 128,
|
||||
exit_status: [u8; 4],
|
||||
output: [u8],
|
||||
);
|
||||
|
||||
// Burn some PoV, clear_storage consumes some PoV as in order to clear the storage we need to we
|
||||
// need to read its size first.
|
||||
clear_storage::<api>(StorageFlags::empty(), b"");
|
||||
|
||||
let exit_status = uapi::ReturnFlags::from_bits(exit_status[0] as u32).unwrap();
|
||||
api::return_value(exit_status, output);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, u64_output, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {
|
||||
input!(128, data: [u8],);
|
||||
api::deposit_event(&[], data);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
// Not payable
|
||||
let value = u64_output!(api::value_transferred,);
|
||||
if value > 0 {
|
||||
panic!();
|
||||
}
|
||||
|
||||
input!(128, data: [u8],);
|
||||
api::deposit_event(&[], data);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
#[allow(clippy::empty_loop)]
|
||||
loop {}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Uses the sbrk instruction in order to test that it is rejected.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
// Export that is never called. We can put code here that should be in the binary
|
||||
// but is never supposed to be run.
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call_never() {
|
||||
polkavm_derive::sbrk(4);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {}
|
||||
@@ -0,0 +1,77 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
const DJANGO_FALLBACK: [u8; 20] = [4u8; 20];
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {
|
||||
// make sure that the deposit for the immutable data is refunded
|
||||
api::set_immutable_data(&[1, 2, 3, 4, 5])
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
// If the input data is not empty, then recursively call self with empty input data.
|
||||
// This should trap instead of self-destructing since a contract cannot be removed, while it's
|
||||
// in the execution stack. If the recursive call traps, then trap here as well.
|
||||
input!(input, 4,);
|
||||
|
||||
if !input.is_empty() {
|
||||
let mut addr = [0u8; 20];
|
||||
api::address(&mut addr);
|
||||
|
||||
api::call(
|
||||
uapi::CallFlags::ALLOW_REENTRY,
|
||||
&addr,
|
||||
u64::MAX, // How much ref_time to devote for the execution. u64 = all.
|
||||
u64::MAX, // How much proof_size to devote for the execution. u64 = all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&[0u8; 32], // Value to transfer.
|
||||
&[0u8; 0],
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
} else {
|
||||
// Try to terminate and give balance to django.
|
||||
|
||||
// Build the calldata: selector + ABI-encoded address
|
||||
let selector = uapi::solidity_selector("terminate(address)");
|
||||
let mut calldata = [0u8; 4 + 32];
|
||||
calldata[0..4].copy_from_slice(&selector);
|
||||
// ABI encode address: right-align into 32 bytes (pad with 12 leading zeros)
|
||||
calldata[4 + 12..4 + 32].copy_from_slice(&DJANGO_FALLBACK);
|
||||
|
||||
let _ = api::call(
|
||||
uapi::CallFlags::ALLOW_REENTRY,
|
||||
&uapi::SYSTEM_PRECOMPILE_ADDR,
|
||||
u64::MAX,
|
||||
u64::MAX,
|
||||
&[u8::MAX; 32],
|
||||
&[0u8; 32],
|
||||
&calldata,
|
||||
None,
|
||||
).unwrap();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
const DJANGO_FALLBACK: [u8; 20] = [4u8; 20];
|
||||
api::terminate(&DJANGO_FALLBACK);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, u256_bytes, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(36, code_hash: [u8],);
|
||||
|
||||
let mut addr = [0u8; 20];
|
||||
let salt = [1u8; 32];
|
||||
api::instantiate(
|
||||
u64::MAX,
|
||||
u64::MAX,
|
||||
&[u8::MAX; 32],
|
||||
&u256_bytes(100_000_000_000u64),
|
||||
code_hash,
|
||||
Some(&mut addr),
|
||||
None,
|
||||
Some(&salt),
|
||||
).unwrap();
|
||||
|
||||
api::call(
|
||||
uapi::CallFlags::empty(),
|
||||
&addr,
|
||||
u64::MAX,
|
||||
u64::MAX,
|
||||
&[u8::MAX; 32],
|
||||
&[0u8; 32],
|
||||
&[],
|
||||
None,
|
||||
).unwrap();
|
||||
|
||||
// Return the address of the created (and destroyed) contract
|
||||
api::return_value(uapi::ReturnFlags::empty(), &addr);
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
const DJANGO_FALLBACK: [u8; 20] = [4u8; 20];
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {
|
||||
// Build the calldata: selector + ABI-encoded address
|
||||
let selector = uapi::solidity_selector("terminate(address)");
|
||||
let mut calldata = [0u8; 4 + 32];
|
||||
calldata[0..4].copy_from_slice(&selector);
|
||||
// ABI encode address: right-align into 32 bytes (pad with 12 leading zeros)
|
||||
calldata[4 + 12..4 + 32].copy_from_slice(&DJANGO_FALLBACK);
|
||||
|
||||
let _ = api::call(
|
||||
uapi::CallFlags::ALLOW_REENTRY,
|
||||
&uapi::SYSTEM_PRECOMPILE_ADDR,
|
||||
u64::MAX,
|
||||
u64::MAX,
|
||||
&[u8::MAX; 32],
|
||||
&[0u8; 32],
|
||||
&calldata,
|
||||
None,
|
||||
).unwrap();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {
|
||||
api::terminate(&[0u8; 20]);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {}
|
||||
@@ -0,0 +1,37 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(addr: &[u8; 32],);
|
||||
api::set_code_hash(addr);
|
||||
|
||||
// we return 1 after setting new code_hash
|
||||
// next `call` will NOT return this value, because contract code has been changed
|
||||
api::return_value(uapi::ReturnFlags::empty(), &1u32.to_le_bytes());
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api, StorageFlags};
|
||||
|
||||
static BUFFER: [u8; 512] = [0u8; 512];
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(len: u32, );
|
||||
|
||||
let rounds = len as usize / BUFFER.len();
|
||||
let rest = len as usize / BUFFER.len();
|
||||
for i in 0..rounds {
|
||||
api::set_storage(StorageFlags::TRANSIENT, &i.to_le_bytes(), &BUFFER);
|
||||
}
|
||||
api::set_storage(StorageFlags::TRANSIENT, &u32::MAX.to_le_bytes(), &BUFFER[..rest]);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
signature: [u8; 64],
|
||||
pub_key: [u8; 32],
|
||||
msg: [u8; 11],
|
||||
);
|
||||
|
||||
let exit_status = match api::sr25519_verify(
|
||||
&signature.try_into().unwrap(),
|
||||
msg,
|
||||
&pub_key.try_into().unwrap(),
|
||||
) {
|
||||
Ok(_) => 0u32,
|
||||
Err(code) => code as u32,
|
||||
};
|
||||
|
||||
// Exit with success and take transfer return code to the output buffer.
|
||||
api::return_value(uapi::ReturnFlags::empty(), &exit_status.to_le_bytes());
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This contract tests the storage APIs. It sets and clears storage values using the different
|
||||
//! versions of the storage APIs.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
include!("../panic_handler.rs");
|
||||
include!("../sol_utils.rs");
|
||||
|
||||
use uapi::{unwrap_output, HostFn, HostFnImpl as api, StorageFlags};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
const KEY: [u8; 32] = [1u8; 32];
|
||||
const VALUE_1: [u8; 4] = [1u8; 4];
|
||||
const VALUE_2: [u8; 4] = [2u8; 4];
|
||||
const VALUE_3: [u8; 4] = [3u8; 4];
|
||||
|
||||
api::set_storage(StorageFlags::empty(), &KEY, &VALUE_1);
|
||||
assert_eq!(contains_storage::<api>(StorageFlags::empty(), &KEY), Some(VALUE_1.len() as _));
|
||||
unwrap_output!(val, [0u8; 4], api::get_storage, StorageFlags::empty(), &KEY);
|
||||
assert_eq!(**val, VALUE_1);
|
||||
|
||||
let existing = api::set_storage(StorageFlags::empty(), &KEY, &VALUE_2);
|
||||
assert_eq!(existing, Some(VALUE_1.len() as _));
|
||||
unwrap_output!(val, [0u8; 4], api::get_storage, StorageFlags::empty(), &KEY);
|
||||
assert_eq!(**val, VALUE_2);
|
||||
|
||||
clear_storage::<api>(StorageFlags::empty(), &KEY);
|
||||
assert_eq!(contains_storage::<api>(StorageFlags::empty(), &KEY), None);
|
||||
|
||||
let existing = api::set_storage(StorageFlags::empty(), &KEY, &VALUE_3);
|
||||
assert_eq!(existing, None);
|
||||
assert_eq!(contains_storage::<api>(StorageFlags::empty(), &KEY), Some(VALUE_1.len() as _));
|
||||
unwrap_output!(val, [0u8; 32], api::get_storage, StorageFlags::empty(), &KEY);
|
||||
assert_eq!(**val, VALUE_3);
|
||||
|
||||
clear_storage::<api>(StorageFlags::empty(), &KEY);
|
||||
assert_eq!(contains_storage::<api>(StorageFlags::empty(), &KEY), None);
|
||||
let existing = api::set_storage(StorageFlags::empty(), &KEY, &VALUE_3);
|
||||
assert_eq!(existing, None);
|
||||
let mut decoded_buf = [0u8; 4];
|
||||
assert_eq!(take_storage::<api>(StorageFlags::empty(), &KEY, &mut decoded_buf), Some(4));
|
||||
assert_eq!(decoded_buf, VALUE_3);
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This contract calls the Storage pre-compile _without a delegate call_.
|
||||
//! This must result in a trap, it must not be possible to call this contract
|
||||
//! succesfully!
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
include!("../panic_handler.rs");
|
||||
include!("../sol_utils.rs");
|
||||
|
||||
use uapi::{ReturnErrorCode, HostFn, HostFnImpl as api, StorageFlags};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
const KEY: [u8; 32] = [1u8; 32];
|
||||
const VALUE_1: [u8; 4] = [1u8; 4];
|
||||
|
||||
api::set_storage(StorageFlags::empty(), &KEY, &VALUE_1);
|
||||
|
||||
let mut buffer = [0u8; 512];
|
||||
let sel = solidity_selector("containsStorage(uint32,bool,bytes)");
|
||||
buffer[..4].copy_from_slice(&sel[..4]);
|
||||
|
||||
let flags = encode_u32(StorageFlags::empty().bits());
|
||||
buffer[4..36].copy_from_slice(&flags[..32]);
|
||||
|
||||
encode_bool(false, &mut buffer[36..68]); // `is_fixed_key`
|
||||
let n = encode_bytes(&KEY, &mut buffer[68..]);
|
||||
|
||||
let mut output = [0u8; 64]; /* function returns (bool, uint) */
|
||||
match api::call(
|
||||
CallFlags::empty(),
|
||||
&STORAGE_PRECOMPILE_ADDR,
|
||||
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
|
||||
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&[0u8; 32], // Value transferred to the contract.
|
||||
&buffer[..36 /* selector + `uint32` */ + 32 /* `bool` */ + n /* `bytes` */],
|
||||
Some(&mut &mut output[..]),
|
||||
) {
|
||||
Ok(_) => api::return_value(uapi::ReturnFlags::empty(), &output[..]),
|
||||
Err(ReturnErrorCode::CalleeReverted) => api::return_value(ReturnFlags::REVERT, &output[..]),
|
||||
Err(_) => panic!(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api, StorageFlags};
|
||||
|
||||
static mut BUFFER: [u8; 16 * 1024 + 1] = [0u8; 16 * 1024 + 1];
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(len: u32, );
|
||||
|
||||
let data = unsafe { &BUFFER[..len as usize] };
|
||||
|
||||
// Place a garbage value in storage, the size of which is specified by the call input.
|
||||
let mut key = [0u8; 32];
|
||||
key[0] = 1;
|
||||
|
||||
api::set_storage(StorageFlags::empty(), &key, data);
|
||||
|
||||
let data = unsafe { &mut &mut BUFFER[..] };
|
||||
api::get_storage(StorageFlags::empty(), &key, data).unwrap();
|
||||
assert_eq!(data.len(), len as usize);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api, StorageFlags};
|
||||
|
||||
static BUFFER: [u8; 512] = [0u8; 512];
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(len: u32, );
|
||||
|
||||
let data = &BUFFER[..len as usize];
|
||||
|
||||
// Place a garbage value in storage, the size of which is specified by the call input.
|
||||
let mut key = [0u8; 32];
|
||||
key[0] = 1;
|
||||
|
||||
api::set_storage(StorageFlags::empty(), &key, data);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api, StorageFlags};
|
||||
|
||||
static BUFFER: [u8; 16 * 1024 + 1] = [0u8; 16 * 1024 + 1];
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {
|
||||
input!(len: u32, );
|
||||
|
||||
let data = &BUFFER[..len as usize];
|
||||
|
||||
// place a garbage value in storage, the size of which is specified by the call input.
|
||||
let mut key = [0u8; 32];
|
||||
key[0] = 1;
|
||||
|
||||
api::set_storage(StorageFlags::empty(), &key, data);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {}
|
||||
@@ -0,0 +1,49 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(beneficiary: &[u8; 20],);
|
||||
// Build the calldata: selector + ABI-encoded address
|
||||
let selector = uapi::solidity_selector("terminate(address)");
|
||||
let mut calldata = [0u8; 4 + 32];
|
||||
calldata[0..4].copy_from_slice(&selector);
|
||||
// ABI encode address: right-align into 32 bytes (pad with 12 leading zeros)
|
||||
calldata[4 + 12..4 + 32].copy_from_slice(beneficiary);
|
||||
|
||||
let _ = api::call(
|
||||
uapi::CallFlags::ALLOW_REENTRY,
|
||||
&uapi::SYSTEM_PRECOMPILE_ADDR,
|
||||
u64::MAX,
|
||||
u64::MAX,
|
||||
&[u8::MAX; 32],
|
||||
&[0u8; 32],
|
||||
&calldata,
|
||||
None,
|
||||
).unwrap();
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! This fixture calls itself as many times as passed as argument.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, u256_bytes, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(calls_left: u32, callee_addr: &[u8; 20],);
|
||||
if calls_left == 0 {
|
||||
// transfer some value to BOB
|
||||
let _ = api::call(
|
||||
uapi::CallFlags::empty(),
|
||||
&[2u8; 20],
|
||||
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
|
||||
u64::MAX, /* How much proof_size to devote for the execution. u64::MAX = use
|
||||
* all. */
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&u256_bytes(100), // Value transferred
|
||||
&[],
|
||||
None,
|
||||
);
|
||||
return
|
||||
}
|
||||
|
||||
let next_input = (calls_left - 1).to_le_bytes();
|
||||
api::deposit_event(&[], b"before");
|
||||
|
||||
// Call the callee, ignore revert.
|
||||
let _ = api::call(
|
||||
uapi::CallFlags::empty(),
|
||||
callee_addr,
|
||||
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
|
||||
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&[0u8; 32], // Value transferred to the contract.
|
||||
&next_input,
|
||||
None,
|
||||
);
|
||||
|
||||
api::deposit_event(&[], b"after");
|
||||
|
||||
// own address
|
||||
let mut addr = [0u8; 20];
|
||||
api::address(&mut addr);
|
||||
let mut input = [0u8; 24];
|
||||
|
||||
input[..4].copy_from_slice(&next_input);
|
||||
input[4..24].copy_from_slice(&callee_addr[..20]);
|
||||
|
||||
// recurse
|
||||
api::call(
|
||||
uapi::CallFlags::ALLOW_REENTRY,
|
||||
&addr,
|
||||
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
|
||||
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
|
||||
&[u8::MAX; 32], // No deposit limit.
|
||||
&[0u8; 32], // Value transferred to the contract.
|
||||
&input,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
include!("../panic_handler.rs");
|
||||
|
||||
use uapi::{input, HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(id: u32, );
|
||||
|
||||
match id {
|
||||
// Revert with message "This function always fails"
|
||||
2 => {
|
||||
let data = hex_literal::hex!(
|
||||
"08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001a546869732066756e6374696f6e20616c77617973206661696c73000000000000"
|
||||
);
|
||||
api::return_value(uapi::ReturnFlags::REVERT, &data)
|
||||
},
|
||||
1 => {
|
||||
panic!("booum");
|
||||
},
|
||||
_ => api::return_value(uapi::ReturnFlags::empty(), &id.to_le_bytes()),
|
||||
};
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user