Skip to content

Instantly share code, notes, and snippets.

View a2468834's full-sized avatar
🤗
Search for opportunities

Chuan-Chun Wang a2468834

🤗
Search for opportunities
View GitHub Profile
async function method1(payload) {
return Buffer.from(payload, 'base64').toString('utf-8');
}
async function method2(payload) {
const uint8_array = await ethers.utils.base64.decode(payload);
const char_array = Array.from(uint8_array).map((element) => {
return String.fromCharCode(element)
});
@a2468834
a2468834 / Example2.sol
Last active May 16, 2022 02:09
2022-05-16 HSNL Paper Meeting
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.13;
contract Victim {
mapping(address => uint256) public balances;
function deposit() public payable {
balances[msg.sender] += msg.value;
}
@a2468834
a2468834 / Example1.sol
Last active May 16, 2022 02:03
2022-05-16 HSNL Paper Meeting
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.13;
contract A {
uint256 public x;
function foo() public payable {
x++;
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.1;
contract A {
function method() public pure virtual returns (string memory) {
return "A";
}
}
contract B is A {
// Main function
async function main() {
// Declare Signer object
const HRE_EOAs = await hre.ethers.getSigners();
// Deploy contracts
const factory_seq = await hre.ethers.getContractFactory("SortedSequence", HRE_EOAs[0]);
const contract_seq = await factory_seq.deploy();
await contract_seq.deployed();
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.1;
contract SortedSequence {
uint256[100] public _array;
mapping(uint256 => bool) public _mapping;
function setValue(uint256[100] calldata init_seq) public {
for(uint8 i = 0; i < 100; i++) {
_array[i] = init_seq[i];
// Constants
const EXIT_SUCCESS = 0;
const EXIT_FAILURE = 1;
// Method1: Query getCanvasSlice() 36 times, sequential
async function method1(contract) {
for(let i = 0; i < 36; i++) {
var args = [(i).toString(), (i+1).toString()];
await contract.getCanvasSlice(...args);
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.1;
// The compiler does not reserve a storage slot for these variables.
uint256 constant dim1 = 36;
uint256 constant dim2 = 36;
uint256 constant dim = dim1 * dim2;
// Use the original "struct Cell"
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.1 <0.9.0;
/**
* @dev
* The original contract:
* https://etherscan.io/address/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2#code
*/
interface IWeth9 {
function allowance(address, address) external returns (uint256);
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0 <0.9.0;
contract D1 {
function A() public pure { // 21437, MAX
uint256 x;
x+=1;
}
function B() public pure { // 21333, min
uint256 x;