Skip to content

Commit

Permalink
upgrade default version to 0.8.26 (#849)
Browse files Browse the repository at this point in the history
  • Loading branch information
wenlinlee authored Jun 27, 2024
1 parent cd6ea4b commit 19f3cbd
Show file tree
Hide file tree
Showing 22 changed files with 400 additions and 21 deletions.
14 changes: 14 additions & 0 deletions src/main/resources/contract/solidity/0.8.26/BlobHashExample.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.10 <=0.8.26;

contract BlobHashExample {
bytes public largeData = "This is a very large data blob that needs to be hashed efficiently.";

function hashData() public view returns (bytes32) {
bytes32 result;
assembly {
result := blobhash(add(sload(largeData.slot), largeData.offset))
}
return result;
}
}
24 changes: 24 additions & 0 deletions src/main/resources/contract/solidity/0.8.26/ContractA.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.6.10 <=0.8.26;

import "./StorageSlot.sol";
import "./ContractB.sol";

contract ContractA {
using StorageSlot for *;

StorageSlot.Int256SlotType private intSlot;
constructor(int256 value){
StorageSlot.tstore(intSlot, value);
}

function getData() public view returns (int256) {
return StorageSlot.tload(intSlot);
}

function callContractB() public returns (int256){
ContractB b = new ContractB();
return b.callContractA(address(this));
}

}
16 changes: 16 additions & 0 deletions src/main/resources/contract/solidity/0.8.26/ContractB.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.6.10 <=0.8.26;

import "./StorageSlot.sol";
import "./ContractA.sol";


contract ContractB {

function callContractA(address a) public returns (int256){
ContractA a = ContractA(a);
int256 result = a.getData();
return result;
}

}
16 changes: 16 additions & 0 deletions src/main/resources/contract/solidity/0.8.26/MainContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.6.10 <=0.8.26;

import "./StorageSlot.sol";
import "./ContractA.sol";
import "./ContractB.sol";

contract MainContract {

function checkAndVerifyIntValue(int256 value) public returns (bool) {
ContractA a = new ContractA(value);
int256 result = a.callContractB();
require(result == value, "store value not equal tload result");
return true;
}
}
12 changes: 12 additions & 0 deletions src/main/resources/contract/solidity/0.8.26/Mcopy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.6.10 <=0.8.26;

contract Mcopy {
function memoryCopy() external pure returns (bytes32 x) {
assembly {
mstore(0x20, 0x50) // Store 0x50 at word 1 in memory
mcopy(0, 0x20, 0x20) // Copies 0x50 to word 0 in memory
x := mload(0) // Returns 32 bytes "0x50"
}
}
}
78 changes: 78 additions & 0 deletions src/main/resources/contract/solidity/0.8.26/StorageContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
pragma solidity >=0.6.10 <=0.8.26;

import "./StorageSlot.sol";

contract StorageContract {
using StorageSlot for *;

StorageSlot.AddressSlotType private addressSlot = StorageSlot.asAddress(keccak256("address_slot"));
StorageSlot.BooleanSlotType private booleanSlot = StorageSlot.asBoolean(keccak256("boolean_slot"));
StorageSlot.Bytes32SlotType private bytes32Slot = StorageSlot.asBytes32(keccak256("bytes32_slot"));
StorageSlot.Uint256SlotType private uint256Slot = StorageSlot.asUint256(keccak256("uint256_slot"));
StorageSlot.Int256SlotType private int256Slot = StorageSlot.asInt256(keccak256("int256_slot"));

function setAddress(address _value) public {
addressSlot.tstore(_value);
}

function getAddress() public view returns (address) {
return addressSlot.tload();
}

function setBoolean(bool _value) public {
booleanSlot.tstore(_value);
}

function getBoolean() public view returns (bool) {
return booleanSlot.tload();
}

function setBytes32(bytes32 _value) public {
bytes32Slot.tstore(_value);
}

function getBytes32() public view returns (bytes32) {
return bytes32Slot.tload();
}

function setUint256(uint256 _value) public {
uint256Slot.tstore(_value);
}

function getUint256() public view returns (uint256) {
return uint256Slot.tload();
}

function setInt256(int256 _value) public {
int256Slot.tstore(_value);
}

function getInt256() public view returns (int256) {
return int256Slot.tload();
}

function storeIntTest(int256 _value) public returns (int256) {
int256Slot.tstore(_value);
return int256Slot.tload();
}

function storeUintTest(uint256 _value) public returns (uint256) {
uint256Slot.tstore(_value);
return uint256Slot.tload();
}

function storeBytes32Test(bytes32 _value) public returns (bytes32) {
bytes32Slot.tstore(_value);
return bytes32Slot.tload();
}

function storeBooleanTest(bool _value) public returns (bool) {
booleanSlot.tstore(_value);
return booleanSlot.tload();
}

function storeAddressTest(address _value) public returns (address) {
addressSlot.tstore(_value);
return addressSlot.tload();
}
}
194 changes: 194 additions & 0 deletions src/main/resources/contract/solidity/0.8.26/StorageSlot.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.6.10 <=0.8.26;

library StorageSlot {
struct AddressSlot {
address value;
}

struct BooleanSlot {
bool value;
}

struct Bytes32Slot {
bytes32 value;
}

struct Uint256Slot {
uint256 value;
}

struct Int256Slot {
int256 value;
}

struct StringSlot {
string value;
}

struct BytesSlot {
bytes value;
}

function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly {
r.slot := slot
}
}

function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}

function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}

function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}

function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}

function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}

function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}

function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}

function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}

type AddressSlotType is bytes32;

function asAddress(bytes32 slot) internal pure returns (AddressSlotType) {
return AddressSlotType.wrap(slot);
}

type BooleanSlotType is bytes32;

function asBoolean(bytes32 slot) internal pure returns (BooleanSlotType) {
return BooleanSlotType.wrap(slot);
}

type Bytes32SlotType is bytes32;

function asBytes32(bytes32 slot) internal pure returns (Bytes32SlotType) {
return Bytes32SlotType.wrap(slot);
}

type Uint256SlotType is bytes32;

function asUint256(bytes32 slot) internal pure returns (Uint256SlotType) {
return Uint256SlotType.wrap(slot);
}

type Int256SlotType is bytes32;

function asInt256(bytes32 slot) internal pure returns (Int256SlotType) {
return Int256SlotType.wrap(slot);
}

function tload(AddressSlotType slot) internal view returns (address value) {
/// @solidity memory-safe-assembly
assembly {
value := tload(slot)
}
}

function tstore(AddressSlotType slot, address value) internal {
/// @solidity memory-safe-assembly
assembly {
tstore(slot, value)
}
}

function tload(BooleanSlotType slot) internal view returns (bool value) {
/// @solidity memory-safe-assembly
assembly {
value := tload(slot)
}
}

function tstore(BooleanSlotType slot, bool value) internal {
/// @solidity memory-safe-assembly
assembly {
tstore(slot, value)
}
}

function tload(Bytes32SlotType slot) internal view returns (bytes32 value) {
/// @solidity memory-safe-assembly
assembly {
value := tload(slot)
}
}

function tstore(Bytes32SlotType slot, bytes32 value) internal {
/// @solidity memory-safe-assembly
assembly {
tstore(slot, value)
}
}

function tload(Uint256SlotType slot) internal view returns (uint256 value) {
/// @solidity memory-safe-assembly
assembly {
value := tload(slot)
}
}

function tstore(Uint256SlotType slot, uint256 value) internal {
/// @solidity memory-safe-assembly
assembly {
tstore(slot, value)
}
}

function tload(Int256SlotType slot) internal view returns (int256 value) {
/// @solidity memory-safe-assembly
assembly {
value := tload(slot)
}
}

function tstore(Int256SlotType slot, int256 value) internal {
/// @solidity memory-safe-assembly
assembly {
tstore(slot, value)
}
}
}
14 changes: 14 additions & 0 deletions src/main/resources/contract/solidity/0.8.26/blobBaseFee.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.6.10 <=0.8.26;

contract blobBaseFee {
function getBlobBaseFeeYul() external view returns (uint256 blobBaseFee) {
assembly {
blobBaseFee := blobbasefee()
}
}

function getBlobBaseFeeSolidity() external view returns (uint256 blobBaseFee) {
blobBaseFee = block.blobbasefee;
}
}
3 changes: 2 additions & 1 deletion src/main/resources/contract/solidity/Asset.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.6.10 <0.8.20;
pragma solidity >=0.6.10 <=0.8.26;

pragma experimental ABIEncoderV2;

import "./Table.sol";
Expand Down
Loading

0 comments on commit 19f3cbd

Please sign in to comment.