Skip to content

Instantly share code, notes, and snippets.

View CJ42's full-sized avatar

Jean Cvllr CJ42

View GitHub Profile
// SPDX-LICENSE: UNLICENSED
pragma solidity ^0.8.0;
contract DeployedContract {
uint public result = 0;
function add(uint256 input) public {
result = result + input;
}
}
function callWithLiteralString() public {
bytes memory calldataPayload = "0x1003e2d20000000000000000000000000000000000000000000000000000000000000005";
(bool success, ) = address(deployed_contract).call(calldataPayload);
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract BlockScope {
function withoutBrackets() public pure {
uint256 _16 = 16;
uint256 _15 = 15;
uint256 _14 = 14;
; without block scope
; ----------
080 PUSH1 00
082 PUSH1 10
084 SWAP1
085 POP
086 PUSH1 00
088 PUSH1 0f
090 SWAP1
@CJ42
CJ42 / Stack.sol
Last active December 19, 2022 16:35
example to show that local variables defined in an assembly block are removed from the EVM stack at the end of the assembly bloc
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract Stack {
function exampleStackAssembly() public pure returns (uint256) {
uint256 a = 1;
assembly {
let b := 2
@CJ42
CJ42 / Stack.asm
Last active December 19, 2022 16:49
PUSH1 00
DUP1
PUSH1 01 ; uint256 a = 1
SWAP1
POP
PUSH1 02 ; let b := 2 (first line of assembly block)
DUP2 ; duplicate value of `a` to get it on top of the stack
DUP2 ; duplicate value of `b` to get it on top of the stack
ADD ; add the values together
SWAP2

6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea2646970667358221220c8b048d9b24b9ef80deaef07bc4ef7b656be161b9dba5ceded1b7e6d169de65364736f6c634300080f0033

608060405234801561001057600080fd5b50610217806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063569c5f6d14610046578063a1c5191514610064578063d46300fd14610082575b600080fd5b61004e6100a0565b60405161005b9190610105565b60405180910390f35b61006c6100c5565b604051610079919061015b565b60405180910390f35b61008a6100d6565b6040516100979190610105565b60405180910390f35b600065aabbccddeeff60d01b60d01c651122334455666100c091906101a5565b905090565b600065aabbccddeeff60d01b905090565b600065112233445566905090565b600065ffffffffffff82169050919050565b6100ff816100e4565b82525050565b600060208201905061011a60008301846100f6565b92915050565b60007fffffffffffff000000000000000000000000000000000000000000000000000082169050919050565b61015581610120565b82525050565b6000602082019050610170600083018461014c565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006101b0826100e4565b91506101bb836100e4565b92508265ffffffffffff038211156101d6576101d5610176565b5b82

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract Code {
uint48 private constant A = 0x112233445566;
bytes6 private immutable B;
constructor() {
B = 0xaabbccddeeff;
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract Immutables {
uint48 immutable private A = 0x112233445566;
bytes6 immutable private B;
constructor() {
B = 0xaabbccddeeff;