Skip to content

Instantly share code, notes, and snippets.

@iamsajidjaved
Created May 2, 2021 19:50
Show Gist options
  • Save iamsajidjaved/80d27391d983f0b36c4b6b4db49b76d7 to your computer and use it in GitHub Desktop.
Save iamsajidjaved/80d27391d983f0b36c4b6b4db49b76d7 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.1+commit.df193b15.js&optimize=false&runs=200&gist=
REMIX EXAMPLE PROJECT
Remix example project is present when Remix loads very first time or there are no files existing in the File Explorer.
It contains 3 directories:
1. 'contracts': Holds three contracts with different complexity level, denoted with number prefix in file name.
2. 'scripts': Holds two scripts to deploy a contract. It is explained below.
3. 'tests': Contains one test file for 'Ballot' contract with unit tests in Solidity.
SCRIPTS
The 'scripts' folder contains example async/await scripts for deploying the 'Storage' contract.
For the deployment of any other contract, 'contractName' and 'constructorArgs' should be updated (along with other code if required).
Scripts have full access to the web3.js and ethers.js libraries.
To run a script, right click on file name in the file explorer and click 'Run'. Remember, Solidity file must already be compiled.
Output from script will appear in remix terminal.
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/**
* @title Storage
* @dev Store & retrieve value in a variable
*/
contract Storage {
uint256 number;
/**
* @dev Store value in variable
* @param num value to store
*/
function store(uint256 num) public {
number = num;
}
/**
* @dev Return value
* @return value of 'number'
*/
function retrieve() public view returns (uint256){
return number;
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/**
* @title Owner
* @dev Set & change owner
*/
contract Owner {
address private owner;
// event for EVM logging
event OwnerSet(address indexed oldOwner, address indexed newOwner);
// modifier to check if caller is owner
modifier isOwner() {
// If the first argument of 'require' evaluates to 'false', execution terminates and all
// changes to the state and to Ether balances are reverted.
// This used to consume all gas in old EVM versions, but not anymore.
// It is often a good idea to use 'require' to check if functions are called correctly.
// As a second argument, you can also provide an explanation about what went wrong.
require(msg.sender == owner, "Caller is not owner");
_;
}
/**
* @dev Set contract deployer as owner
*/
constructor() {
owner = msg.sender; // 'msg.sender' is sender of current call, contract deployer for a constructor
emit OwnerSet(address(0), owner);
}
/**
* @dev Change owner
* @param newOwner address of new owner
*/
function changeOwner(address newOwner) public isOwner {
emit OwnerSet(owner, newOwner);
owner = newOwner;
}
/**
* @dev Return owner address
* @return address of owner
*/
function getOwner() external view returns (address) {
return owner;
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/**
* @title Ballot
* @dev Implements voting process along with vote delegation
*/
contract Ballot {
struct Voter {
uint weight; // weight is accumulated by delegation
bool voted; // if true, that person already voted
address delegate; // person delegated to
uint vote; // index of the voted proposal
}
struct Proposal {
// If you can limit the length to a certain number of bytes,
// always use one of bytes1 to bytes32 because they are much cheaper
bytes32 name; // short name (up to 32 bytes)
uint voteCount; // number of accumulated votes
}
address public chairperson;
mapping(address => Voter) public voters;
Proposal[] public proposals;
/**
* @dev Create a new ballot to choose one of 'proposalNames'.
* @param proposalNames names of proposals
*/
constructor(bytes32[] memory proposalNames) {
chairperson = msg.sender;
voters[chairperson].weight = 1;
for (uint i = 0; i < proposalNames.length; i++) {
// 'Proposal({...})' creates a temporary
// Proposal object and 'proposals.push(...)'
// appends it to the end of 'proposals'.
proposals.push(Proposal({
name: proposalNames[i],
voteCount: 0
}));
}
}
/**
* @dev Give 'voter' the right to vote on this ballot. May only be called by 'chairperson'.
* @param voter address of voter
*/
function giveRightToVote(address voter) public {
require(
msg.sender == chairperson,
"Only chairperson can give right to vote."
);
require(
!voters[voter].voted,
"The voter already voted."
);
require(voters[voter].weight == 0);
voters[voter].weight = 1;
}
/**
* @dev Delegate your vote to the voter 'to'.
* @param to address to which vote is delegated
*/
function delegate(address to) public {
Voter storage sender = voters[msg.sender];
require(!sender.voted, "You already voted.");
require(to != msg.sender, "Self-delegation is disallowed.");
while (voters[to].delegate != address(0)) {
to = voters[to].delegate;
// We found a loop in the delegation, not allowed.
require(to != msg.sender, "Found loop in delegation.");
}
sender.voted = true;
sender.delegate = to;
Voter storage delegate_ = voters[to];
if (delegate_.voted) {
// If the delegate already voted,
// directly add to the number of votes
proposals[delegate_.vote].voteCount += sender.weight;
} else {
// If the delegate did not vote yet,
// add to her weight.
delegate_.weight += sender.weight;
}
}
/**
* @dev Give your vote (including votes delegated to you) to proposal 'proposals[proposal].name'.
* @param proposal index of proposal in the proposals array
*/
function vote(uint proposal) public {
Voter storage sender = voters[msg.sender];
require(sender.weight != 0, "Has no right to vote");
require(!sender.voted, "Already voted.");
sender.voted = true;
sender.vote = proposal;
// If 'proposal' is out of the range of the array,
// this will throw automatically and revert all
// changes.
proposals[proposal].voteCount += sender.weight;
}
/**
* @dev Computes the winning proposal taking all previous votes into account.
* @return winningProposal_ index of winning proposal in the proposals array
*/
function winningProposal() public view
returns (uint winningProposal_)
{
uint winningVoteCount = 0;
for (uint p = 0; p < proposals.length; p++) {
if (proposals[p].voteCount > winningVoteCount) {
winningVoteCount = proposals[p].voteCount;
winningProposal_ = p;
}
}
}
/**
* @dev Calls winningProposal() function to get the index of the winner contained in the proposals array and then
* @return winnerName_ the name of the winner
*/
function winnerName() public view
returns (bytes32 winnerName_)
{
winnerName_ = proposals[winningProposal()].name;
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract Bank{
int bal;
constructor(){
bal = 1;
}
function getBalance() view public returns(int){
return bal;
}
function withdraw(int amt) public{
bal = bal-amt;
}
function deposit(int amt) public{
bal = bal+amt;
}
}
{
"deploy": {
"VM:-": {
"linkReferences": {},
"autoDeployLib": true
},
"main:1": {
"linkReferences": {},
"autoDeployLib": true
},
"ropsten:3": {
"linkReferences": {},
"autoDeployLib": true
},
"rinkeby:4": {
"linkReferences": {},
"autoDeployLib": true
},
"kovan:42": {
"linkReferences": {},
"autoDeployLib": true
},
"görli:5": {
"linkReferences": {},
"autoDeployLib": true
},
"Custom": {
"linkReferences": {},
"autoDeployLib": true
}
},
"data": {
"bytecode": {
"generatedSources": [],
"linkReferences": {},
"object": "608060405234801561001057600080fd5b5060016000819055506102e9806100286000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806312065fe0146100465780637e62eab814610064578063f04991f014610080575b600080fd5b61004e61009c565b60405161005b9190610120565b60405180910390f35b61007e600480360381019061007991906100e8565b6100a5565b005b61009a600480360381019061009591906100e8565b6100bc565b005b60008054905090565b806000546100b391906101cf565b60008190555050565b806000546100ca919061013b565b60008190555050565b6000813590506100e28161029c565b92915050565b6000602082840312156100fa57600080fd5b6000610108848285016100d3565b91505092915050565b61011a81610263565b82525050565b60006020820190506101356000830184610111565b92915050565b600061014682610263565b915061015183610263565b9250817f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0383136000831215161561018c5761018b61026d565b5b817f80000000000000000000000000000000000000000000000000000000000000000383126000831216156101c4576101c361026d565b5b828201905092915050565b60006101da82610263565b91506101e583610263565b9250827f8000000000000000000000000000000000000000000000000000000000000000018212600084121516156102205761021f61026d565b5b827f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0182136000841216156102585761025761026d565b5b828203905092915050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6102a581610263565b81146102b057600080fd5b5056fea2646970667358221220d515ed45a8b4426f6a5a986954398bf55577eb07b43b8d089a7c25929bb2cec064736f6c63430008010033",
"opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x1 PUSH1 0x0 DUP2 SWAP1 SSTORE POP PUSH2 0x2E9 DUP1 PUSH2 0x28 PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN INVALID PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x4 CALLDATASIZE LT PUSH2 0x41 JUMPI PUSH1 0x0 CALLDATALOAD PUSH1 0xE0 SHR DUP1 PUSH4 0x12065FE0 EQ PUSH2 0x46 JUMPI DUP1 PUSH4 0x7E62EAB8 EQ PUSH2 0x64 JUMPI DUP1 PUSH4 0xF04991F0 EQ PUSH2 0x80 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH2 0x4E PUSH2 0x9C JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH2 0x5B SWAP2 SWAP1 PUSH2 0x120 JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST PUSH2 0x7E PUSH1 0x4 DUP1 CALLDATASIZE SUB DUP2 ADD SWAP1 PUSH2 0x79 SWAP2 SWAP1 PUSH2 0xE8 JUMP JUMPDEST PUSH2 0xA5 JUMP JUMPDEST STOP JUMPDEST PUSH2 0x9A PUSH1 0x4 DUP1 CALLDATASIZE SUB DUP2 ADD SWAP1 PUSH2 0x95 SWAP2 SWAP1 PUSH2 0xE8 JUMP JUMPDEST PUSH2 0xBC JUMP JUMPDEST STOP JUMPDEST PUSH1 0x0 DUP1 SLOAD SWAP1 POP SWAP1 JUMP JUMPDEST DUP1 PUSH1 0x0 SLOAD PUSH2 0xB3 SWAP2 SWAP1 PUSH2 0x1CF JUMP JUMPDEST PUSH1 0x0 DUP2 SWAP1 SSTORE POP POP JUMP JUMPDEST DUP1 PUSH1 0x0 SLOAD PUSH2 0xCA SWAP2 SWAP1 PUSH2 0x13B JUMP JUMPDEST PUSH1 0x0 DUP2 SWAP1 SSTORE POP POP JUMP JUMPDEST PUSH1 0x0 DUP2 CALLDATALOAD SWAP1 POP PUSH2 0xE2 DUP2 PUSH2 0x29C JUMP JUMPDEST SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 DUP5 SUB SLT ISZERO PUSH2 0xFA JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH1 0x0 PUSH2 0x108 DUP5 DUP3 DUP6 ADD PUSH2 0xD3 JUMP JUMPDEST SWAP2 POP POP SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH2 0x11A DUP2 PUSH2 0x263 JUMP JUMPDEST DUP3 MSTORE POP POP JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 ADD SWAP1 POP PUSH2 0x135 PUSH1 0x0 DUP4 ADD DUP5 PUSH2 0x111 JUMP JUMPDEST SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x0 PUSH2 0x146 DUP3 PUSH2 0x263 JUMP JUMPDEST SWAP2 POP PUSH2 0x151 DUP4 PUSH2 0x263 JUMP JUMPDEST SWAP3 POP DUP2 PUSH32 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF SUB DUP4 SGT PUSH1 0x0 DUP4 SLT ISZERO AND ISZERO PUSH2 0x18C JUMPI PUSH2 0x18B PUSH2 0x26D JUMP JUMPDEST JUMPDEST DUP2 PUSH32 0x8000000000000000000000000000000000000000000000000000000000000000 SUB DUP4 SLT PUSH1 0x0 DUP4 SLT AND ISZERO PUSH2 0x1C4 JUMPI PUSH2 0x1C3 PUSH2 0x26D JUMP JUMPDEST JUMPDEST DUP3 DUP3 ADD SWAP1 POP SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x0 PUSH2 0x1DA DUP3 PUSH2 0x263 JUMP JUMPDEST SWAP2 POP PUSH2 0x1E5 DUP4 PUSH2 0x263 JUMP JUMPDEST SWAP3 POP DUP3 PUSH32 0x8000000000000000000000000000000000000000000000000000000000000000 ADD DUP3 SLT PUSH1 0x0 DUP5 SLT ISZERO AND ISZERO PUSH2 0x220 JUMPI PUSH2 0x21F PUSH2 0x26D JUMP JUMPDEST JUMPDEST DUP3 PUSH32 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ADD DUP3 SGT PUSH1 0x0 DUP5 SLT AND ISZERO PUSH2 0x258 JUMPI PUSH2 0x257 PUSH2 0x26D JUMP JUMPDEST JUMPDEST DUP3 DUP3 SUB SWAP1 POP SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x0 DUP2 SWAP1 POP SWAP2 SWAP1 POP JUMP JUMPDEST PUSH32 0x4E487B7100000000000000000000000000000000000000000000000000000000 PUSH1 0x0 MSTORE PUSH1 0x11 PUSH1 0x4 MSTORE PUSH1 0x24 PUSH1 0x0 REVERT JUMPDEST PUSH2 0x2A5 DUP2 PUSH2 0x263 JUMP JUMPDEST DUP2 EQ PUSH2 0x2B0 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP JUMP INVALID LOG2 PUSH5 0x6970667358 0x22 SLT KECCAK256 0xD5 ISZERO 0xED GASLIMIT 0xA8 0xB4 TIMESTAMP PUSH16 0x6A5A986954398BF55577EB07B43B8D08 SWAP11 PUSH29 0x25929BB2CEC064736F6C63430008010033000000000000000000000000 ",
"sourceMap": "70:304:0:-:0;;;107:37;;;;;;;;;;136:1;130:3;:7;;;;70:304;;;;;;"
},
"deployedBytecode": {
"generatedSources": [
{
"ast": {
"nodeType": "YulBlock",
"src": "0:2216:1",
"statements": [
{
"body": {
"nodeType": "YulBlock",
"src": "58:86:1",
"statements": [
{
"nodeType": "YulAssignment",
"src": "68:29:1",
"value": {
"arguments": [
{
"name": "offset",
"nodeType": "YulIdentifier",
"src": "90:6:1"
}
],
"functionName": {
"name": "calldataload",
"nodeType": "YulIdentifier",
"src": "77:12:1"
},
"nodeType": "YulFunctionCall",
"src": "77:20:1"
},
"variableNames": [
{
"name": "value",
"nodeType": "YulIdentifier",
"src": "68:5:1"
}
]
},
{
"expression": {
"arguments": [
{
"name": "value",
"nodeType": "YulIdentifier",
"src": "132:5:1"
}
],
"functionName": {
"name": "validator_revert_t_int256",
"nodeType": "YulIdentifier",
"src": "106:25:1"
},
"nodeType": "YulFunctionCall",
"src": "106:32:1"
},
"nodeType": "YulExpressionStatement",
"src": "106:32:1"
}
]
},
"name": "abi_decode_t_int256",
"nodeType": "YulFunctionDefinition",
"parameters": [
{
"name": "offset",
"nodeType": "YulTypedName",
"src": "36:6:1",
"type": ""
},
{
"name": "end",
"nodeType": "YulTypedName",
"src": "44:3:1",
"type": ""
}
],
"returnVariables": [
{
"name": "value",
"nodeType": "YulTypedName",
"src": "52:5:1",
"type": ""
}
],
"src": "7:137:1"
},
{
"body": {
"nodeType": "YulBlock",
"src": "215:195:1",
"statements": [
{
"body": {
"nodeType": "YulBlock",
"src": "261:16:1",
"statements": [
{
"expression": {
"arguments": [
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "270:1:1",
"type": "",
"value": "0"
},
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "273:1:1",
"type": "",
"value": "0"
}
],
"functionName": {
"name": "revert",
"nodeType": "YulIdentifier",
"src": "263:6:1"
},
"nodeType": "YulFunctionCall",
"src": "263:12:1"
},
"nodeType": "YulExpressionStatement",
"src": "263:12:1"
}
]
},
"condition": {
"arguments": [
{
"arguments": [
{
"name": "dataEnd",
"nodeType": "YulIdentifier",
"src": "236:7:1"
},
{
"name": "headStart",
"nodeType": "YulIdentifier",
"src": "245:9:1"
}
],
"functionName": {
"name": "sub",
"nodeType": "YulIdentifier",
"src": "232:3:1"
},
"nodeType": "YulFunctionCall",
"src": "232:23:1"
},
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "257:2:1",
"type": "",
"value": "32"
}
],
"functionName": {
"name": "slt",
"nodeType": "YulIdentifier",
"src": "228:3:1"
},
"nodeType": "YulFunctionCall",
"src": "228:32:1"
},
"nodeType": "YulIf",
"src": "225:2:1"
},
{
"nodeType": "YulBlock",
"src": "287:116:1",
"statements": [
{
"nodeType": "YulVariableDeclaration",
"src": "302:15:1",
"value": {
"kind": "number",
"nodeType": "YulLiteral",
"src": "316:1:1",
"type": "",
"value": "0"
},
"variables": [
{
"name": "offset",
"nodeType": "YulTypedName",
"src": "306:6:1",
"type": ""
}
]
},
{
"nodeType": "YulAssignment",
"src": "331:62:1",
"value": {
"arguments": [
{
"arguments": [
{
"name": "headStart",
"nodeType": "YulIdentifier",
"src": "365:9:1"
},
{
"name": "offset",
"nodeType": "YulIdentifier",
"src": "376:6:1"
}
],
"functionName": {
"name": "add",
"nodeType": "YulIdentifier",
"src": "361:3:1"
},
"nodeType": "YulFunctionCall",
"src": "361:22:1"
},
{
"name": "dataEnd",
"nodeType": "YulIdentifier",
"src": "385:7:1"
}
],
"functionName": {
"name": "abi_decode_t_int256",
"nodeType": "YulIdentifier",
"src": "341:19:1"
},
"nodeType": "YulFunctionCall",
"src": "341:52:1"
},
"variableNames": [
{
"name": "value0",
"nodeType": "YulIdentifier",
"src": "331:6:1"
}
]
}
]
}
]
},
"name": "abi_decode_tuple_t_int256",
"nodeType": "YulFunctionDefinition",
"parameters": [
{
"name": "headStart",
"nodeType": "YulTypedName",
"src": "185:9:1",
"type": ""
},
{
"name": "dataEnd",
"nodeType": "YulTypedName",
"src": "196:7:1",
"type": ""
}
],
"returnVariables": [
{
"name": "value0",
"nodeType": "YulTypedName",
"src": "208:6:1",
"type": ""
}
],
"src": "150:260:1"
},
{
"body": {
"nodeType": "YulBlock",
"src": "479:52:1",
"statements": [
{
"expression": {
"arguments": [
{
"name": "pos",
"nodeType": "YulIdentifier",
"src": "496:3:1"
},
{
"arguments": [
{
"name": "value",
"nodeType": "YulIdentifier",
"src": "518:5:1"
}
],
"functionName": {
"name": "cleanup_t_int256",
"nodeType": "YulIdentifier",
"src": "501:16:1"
},
"nodeType": "YulFunctionCall",
"src": "501:23:1"
}
],
"functionName": {
"name": "mstore",
"nodeType": "YulIdentifier",
"src": "489:6:1"
},
"nodeType": "YulFunctionCall",
"src": "489:36:1"
},
"nodeType": "YulExpressionStatement",
"src": "489:36:1"
}
]
},
"name": "abi_encode_t_int256_to_t_int256_fromStack",
"nodeType": "YulFunctionDefinition",
"parameters": [
{
"name": "value",
"nodeType": "YulTypedName",
"src": "467:5:1",
"type": ""
},
{
"name": "pos",
"nodeType": "YulTypedName",
"src": "474:3:1",
"type": ""
}
],
"src": "416:115:1"
},
{
"body": {
"nodeType": "YulBlock",
"src": "633:122:1",
"statements": [
{
"nodeType": "YulAssignment",
"src": "643:26:1",
"value": {
"arguments": [
{
"name": "headStart",
"nodeType": "YulIdentifier",
"src": "655:9:1"
},
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "666:2:1",
"type": "",
"value": "32"
}
],
"functionName": {
"name": "add",
"nodeType": "YulIdentifier",
"src": "651:3:1"
},
"nodeType": "YulFunctionCall",
"src": "651:18:1"
},
"variableNames": [
{
"name": "tail",
"nodeType": "YulIdentifier",
"src": "643:4:1"
}
]
},
{
"expression": {
"arguments": [
{
"name": "value0",
"nodeType": "YulIdentifier",
"src": "721:6:1"
},
{
"arguments": [
{
"name": "headStart",
"nodeType": "YulIdentifier",
"src": "734:9:1"
},
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "745:1:1",
"type": "",
"value": "0"
}
],
"functionName": {
"name": "add",
"nodeType": "YulIdentifier",
"src": "730:3:1"
},
"nodeType": "YulFunctionCall",
"src": "730:17:1"
}
],
"functionName": {
"name": "abi_encode_t_int256_to_t_int256_fromStack",
"nodeType": "YulIdentifier",
"src": "679:41:1"
},
"nodeType": "YulFunctionCall",
"src": "679:69:1"
},
"nodeType": "YulExpressionStatement",
"src": "679:69:1"
}
]
},
"name": "abi_encode_tuple_t_int256__to_t_int256__fromStack_reversed",
"nodeType": "YulFunctionDefinition",
"parameters": [
{
"name": "headStart",
"nodeType": "YulTypedName",
"src": "605:9:1",
"type": ""
},
{
"name": "value0",
"nodeType": "YulTypedName",
"src": "617:6:1",
"type": ""
}
],
"returnVariables": [
{
"name": "tail",
"nodeType": "YulTypedName",
"src": "628:4:1",
"type": ""
}
],
"src": "537:218:1"
},
{
"body": {
"nodeType": "YulBlock",
"src": "804:482:1",
"statements": [
{
"nodeType": "YulAssignment",
"src": "814:24:1",
"value": {
"arguments": [
{
"name": "x",
"nodeType": "YulIdentifier",
"src": "836:1:1"
}
],
"functionName": {
"name": "cleanup_t_int256",
"nodeType": "YulIdentifier",
"src": "819:16:1"
},
"nodeType": "YulFunctionCall",
"src": "819:19:1"
},
"variableNames": [
{
"name": "x",
"nodeType": "YulIdentifier",
"src": "814:1:1"
}
]
},
{
"nodeType": "YulAssignment",
"src": "847:24:1",
"value": {
"arguments": [
{
"name": "y",
"nodeType": "YulIdentifier",
"src": "869:1:1"
}
],
"functionName": {
"name": "cleanup_t_int256",
"nodeType": "YulIdentifier",
"src": "852:16:1"
},
"nodeType": "YulFunctionCall",
"src": "852:19:1"
},
"variableNames": [
{
"name": "y",
"nodeType": "YulIdentifier",
"src": "847:1:1"
}
]
},
{
"body": {
"nodeType": "YulBlock",
"src": "1045:22:1",
"statements": [
{
"expression": {
"arguments": [],
"functionName": {
"name": "panic_error_0x11",
"nodeType": "YulIdentifier",
"src": "1047:16:1"
},
"nodeType": "YulFunctionCall",
"src": "1047:18:1"
},
"nodeType": "YulExpressionStatement",
"src": "1047:18:1"
}
]
},
"condition": {
"arguments": [
{
"arguments": [
{
"arguments": [
{
"name": "x",
"nodeType": "YulIdentifier",
"src": "953:1:1"
},
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "956:1:1",
"type": "",
"value": "0"
}
],
"functionName": {
"name": "slt",
"nodeType": "YulIdentifier",
"src": "949:3:1"
},
"nodeType": "YulFunctionCall",
"src": "949:9:1"
}
],
"functionName": {
"name": "iszero",
"nodeType": "YulIdentifier",
"src": "942:6:1"
},
"nodeType": "YulFunctionCall",
"src": "942:17:1"
},
{
"arguments": [
{
"name": "y",
"nodeType": "YulIdentifier",
"src": "965:1:1"
},
{
"arguments": [
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "972:66:1",
"type": "",
"value": "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
},
{
"name": "x",
"nodeType": "YulIdentifier",
"src": "1040:1:1"
}
],
"functionName": {
"name": "sub",
"nodeType": "YulIdentifier",
"src": "968:3:1"
},
"nodeType": "YulFunctionCall",
"src": "968:74:1"
}
],
"functionName": {
"name": "sgt",
"nodeType": "YulIdentifier",
"src": "961:3:1"
},
"nodeType": "YulFunctionCall",
"src": "961:82:1"
}
],
"functionName": {
"name": "and",
"nodeType": "YulIdentifier",
"src": "938:3:1"
},
"nodeType": "YulFunctionCall",
"src": "938:106:1"
},
"nodeType": "YulIf",
"src": "935:2:1"
},
{
"body": {
"nodeType": "YulBlock",
"src": "1232:22:1",
"statements": [
{
"expression": {
"arguments": [],
"functionName": {
"name": "panic_error_0x11",
"nodeType": "YulIdentifier",
"src": "1234:16:1"
},
"nodeType": "YulFunctionCall",
"src": "1234:18:1"
},
"nodeType": "YulExpressionStatement",
"src": "1234:18:1"
}
]
},
"condition": {
"arguments": [
{
"arguments": [
{
"name": "x",
"nodeType": "YulIdentifier",
"src": "1141:1:1"
},
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "1144:1:1",
"type": "",
"value": "0"
}
],
"functionName": {
"name": "slt",
"nodeType": "YulIdentifier",
"src": "1137:3:1"
},
"nodeType": "YulFunctionCall",
"src": "1137:9:1"
},
{
"arguments": [
{
"name": "y",
"nodeType": "YulIdentifier",
"src": "1152:1:1"
},
{
"arguments": [
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "1159:66:1",
"type": "",
"value": "0x8000000000000000000000000000000000000000000000000000000000000000"
},
{
"name": "x",
"nodeType": "YulIdentifier",
"src": "1227:1:1"
}
],
"functionName": {
"name": "sub",
"nodeType": "YulIdentifier",
"src": "1155:3:1"
},
"nodeType": "YulFunctionCall",
"src": "1155:74:1"
}
],
"functionName": {
"name": "slt",
"nodeType": "YulIdentifier",
"src": "1148:3:1"
},
"nodeType": "YulFunctionCall",
"src": "1148:82:1"
}
],
"functionName": {
"name": "and",
"nodeType": "YulIdentifier",
"src": "1133:3:1"
},
"nodeType": "YulFunctionCall",
"src": "1133:98:1"
},
"nodeType": "YulIf",
"src": "1130:2:1"
},
{
"nodeType": "YulAssignment",
"src": "1264:16:1",
"value": {
"arguments": [
{
"name": "x",
"nodeType": "YulIdentifier",
"src": "1275:1:1"
},
{
"name": "y",
"nodeType": "YulIdentifier",
"src": "1278:1:1"
}
],
"functionName": {
"name": "add",
"nodeType": "YulIdentifier",
"src": "1271:3:1"
},
"nodeType": "YulFunctionCall",
"src": "1271:9:1"
},
"variableNames": [
{
"name": "sum",
"nodeType": "YulIdentifier",
"src": "1264:3:1"
}
]
}
]
},
"name": "checked_add_t_int256",
"nodeType": "YulFunctionDefinition",
"parameters": [
{
"name": "x",
"nodeType": "YulTypedName",
"src": "791:1:1",
"type": ""
},
{
"name": "y",
"nodeType": "YulTypedName",
"src": "794:1:1",
"type": ""
}
],
"returnVariables": [
{
"name": "sum",
"nodeType": "YulTypedName",
"src": "800:3:1",
"type": ""
}
],
"src": "761:525:1"
},
{
"body": {
"nodeType": "YulBlock",
"src": "1336:483:1",
"statements": [
{
"nodeType": "YulAssignment",
"src": "1346:24:1",
"value": {
"arguments": [
{
"name": "x",
"nodeType": "YulIdentifier",
"src": "1368:1:1"
}
],
"functionName": {
"name": "cleanup_t_int256",
"nodeType": "YulIdentifier",
"src": "1351:16:1"
},
"nodeType": "YulFunctionCall",
"src": "1351:19:1"
},
"variableNames": [
{
"name": "x",
"nodeType": "YulIdentifier",
"src": "1346:1:1"
}
]
},
{
"nodeType": "YulAssignment",
"src": "1379:24:1",
"value": {
"arguments": [
{
"name": "y",
"nodeType": "YulIdentifier",
"src": "1401:1:1"
}
],
"functionName": {
"name": "cleanup_t_int256",
"nodeType": "YulIdentifier",
"src": "1384:16:1"
},
"nodeType": "YulFunctionCall",
"src": "1384:19:1"
},
"variableNames": [
{
"name": "y",
"nodeType": "YulIdentifier",
"src": "1379:1:1"
}
]
},
{
"body": {
"nodeType": "YulBlock",
"src": "1578:22:1",
"statements": [
{
"expression": {
"arguments": [],
"functionName": {
"name": "panic_error_0x11",
"nodeType": "YulIdentifier",
"src": "1580:16:1"
},
"nodeType": "YulFunctionCall",
"src": "1580:18:1"
},
"nodeType": "YulExpressionStatement",
"src": "1580:18:1"
}
]
},
"condition": {
"arguments": [
{
"arguments": [
{
"arguments": [
{
"name": "y",
"nodeType": "YulIdentifier",
"src": "1486:1:1"
},
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "1489:1:1",
"type": "",
"value": "0"
}
],
"functionName": {
"name": "slt",
"nodeType": "YulIdentifier",
"src": "1482:3:1"
},
"nodeType": "YulFunctionCall",
"src": "1482:9:1"
}
],
"functionName": {
"name": "iszero",
"nodeType": "YulIdentifier",
"src": "1475:6:1"
},
"nodeType": "YulFunctionCall",
"src": "1475:17:1"
},
{
"arguments": [
{
"name": "x",
"nodeType": "YulIdentifier",
"src": "1498:1:1"
},
{
"arguments": [
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "1505:66:1",
"type": "",
"value": "0x8000000000000000000000000000000000000000000000000000000000000000"
},
{
"name": "y",
"nodeType": "YulIdentifier",
"src": "1573:1:1"
}
],
"functionName": {
"name": "add",
"nodeType": "YulIdentifier",
"src": "1501:3:1"
},
"nodeType": "YulFunctionCall",
"src": "1501:74:1"
}
],
"functionName": {
"name": "slt",
"nodeType": "YulIdentifier",
"src": "1494:3:1"
},
"nodeType": "YulFunctionCall",
"src": "1494:82:1"
}
],
"functionName": {
"name": "and",
"nodeType": "YulIdentifier",
"src": "1471:3:1"
},
"nodeType": "YulFunctionCall",
"src": "1471:106:1"
},
"nodeType": "YulIf",
"src": "1468:2:1"
},
{
"body": {
"nodeType": "YulBlock",
"src": "1764:22:1",
"statements": [
{
"expression": {
"arguments": [],
"functionName": {
"name": "panic_error_0x11",
"nodeType": "YulIdentifier",
"src": "1766:16:1"
},
"nodeType": "YulFunctionCall",
"src": "1766:18:1"
},
"nodeType": "YulExpressionStatement",
"src": "1766:18:1"
}
]
},
"condition": {
"arguments": [
{
"arguments": [
{
"name": "y",
"nodeType": "YulIdentifier",
"src": "1673:1:1"
},
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "1676:1:1",
"type": "",
"value": "0"
}
],
"functionName": {
"name": "slt",
"nodeType": "YulIdentifier",
"src": "1669:3:1"
},
"nodeType": "YulFunctionCall",
"src": "1669:9:1"
},
{
"arguments": [
{
"name": "x",
"nodeType": "YulIdentifier",
"src": "1684:1:1"
},
{
"arguments": [
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "1691:66:1",
"type": "",
"value": "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
},
{
"name": "y",
"nodeType": "YulIdentifier",
"src": "1759:1:1"
}
],
"functionName": {
"name": "add",
"nodeType": "YulIdentifier",
"src": "1687:3:1"
},
"nodeType": "YulFunctionCall",
"src": "1687:74:1"
}
],
"functionName": {
"name": "sgt",
"nodeType": "YulIdentifier",
"src": "1680:3:1"
},
"nodeType": "YulFunctionCall",
"src": "1680:82:1"
}
],
"functionName": {
"name": "and",
"nodeType": "YulIdentifier",
"src": "1665:3:1"
},
"nodeType": "YulFunctionCall",
"src": "1665:98:1"
},
"nodeType": "YulIf",
"src": "1662:2:1"
},
{
"nodeType": "YulAssignment",
"src": "1796:17:1",
"value": {
"arguments": [
{
"name": "x",
"nodeType": "YulIdentifier",
"src": "1808:1:1"
},
{
"name": "y",
"nodeType": "YulIdentifier",
"src": "1811:1:1"
}
],
"functionName": {
"name": "sub",
"nodeType": "YulIdentifier",
"src": "1804:3:1"
},
"nodeType": "YulFunctionCall",
"src": "1804:9:1"
},
"variableNames": [
{
"name": "diff",
"nodeType": "YulIdentifier",
"src": "1796:4:1"
}
]
}
]
},
"name": "checked_sub_t_int256",
"nodeType": "YulFunctionDefinition",
"parameters": [
{
"name": "x",
"nodeType": "YulTypedName",
"src": "1322:1:1",
"type": ""
},
{
"name": "y",
"nodeType": "YulTypedName",
"src": "1325:1:1",
"type": ""
}
],
"returnVariables": [
{
"name": "diff",
"nodeType": "YulTypedName",
"src": "1331:4:1",
"type": ""
}
],
"src": "1292:527:1"
},
{
"body": {
"nodeType": "YulBlock",
"src": "1869:32:1",
"statements": [
{
"nodeType": "YulAssignment",
"src": "1879:16:1",
"value": {
"name": "value",
"nodeType": "YulIdentifier",
"src": "1890:5:1"
},
"variableNames": [
{
"name": "cleaned",
"nodeType": "YulIdentifier",
"src": "1879:7:1"
}
]
}
]
},
"name": "cleanup_t_int256",
"nodeType": "YulFunctionDefinition",
"parameters": [
{
"name": "value",
"nodeType": "YulTypedName",
"src": "1851:5:1",
"type": ""
}
],
"returnVariables": [
{
"name": "cleaned",
"nodeType": "YulTypedName",
"src": "1861:7:1",
"type": ""
}
],
"src": "1825:76:1"
},
{
"body": {
"nodeType": "YulBlock",
"src": "1935:152:1",
"statements": [
{
"expression": {
"arguments": [
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "1952:1:1",
"type": "",
"value": "0"
},
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "1955:77:1",
"type": "",
"value": "35408467139433450592217433187231851964531694900788300625387963629091585785856"
}
],
"functionName": {
"name": "mstore",
"nodeType": "YulIdentifier",
"src": "1945:6:1"
},
"nodeType": "YulFunctionCall",
"src": "1945:88:1"
},
"nodeType": "YulExpressionStatement",
"src": "1945:88:1"
},
{
"expression": {
"arguments": [
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "2049:1:1",
"type": "",
"value": "4"
},
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "2052:4:1",
"type": "",
"value": "0x11"
}
],
"functionName": {
"name": "mstore",
"nodeType": "YulIdentifier",
"src": "2042:6:1"
},
"nodeType": "YulFunctionCall",
"src": "2042:15:1"
},
"nodeType": "YulExpressionStatement",
"src": "2042:15:1"
},
{
"expression": {
"arguments": [
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "2073:1:1",
"type": "",
"value": "0"
},
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "2076:4:1",
"type": "",
"value": "0x24"
}
],
"functionName": {
"name": "revert",
"nodeType": "YulIdentifier",
"src": "2066:6:1"
},
"nodeType": "YulFunctionCall",
"src": "2066:15:1"
},
"nodeType": "YulExpressionStatement",
"src": "2066:15:1"
}
]
},
"name": "panic_error_0x11",
"nodeType": "YulFunctionDefinition",
"src": "1907:180:1"
},
{
"body": {
"nodeType": "YulBlock",
"src": "2135:78:1",
"statements": [
{
"body": {
"nodeType": "YulBlock",
"src": "2191:16:1",
"statements": [
{
"expression": {
"arguments": [
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "2200:1:1",
"type": "",
"value": "0"
},
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "2203:1:1",
"type": "",
"value": "0"
}
],
"functionName": {
"name": "revert",
"nodeType": "YulIdentifier",
"src": "2193:6:1"
},
"nodeType": "YulFunctionCall",
"src": "2193:12:1"
},
"nodeType": "YulExpressionStatement",
"src": "2193:12:1"
}
]
},
"condition": {
"arguments": [
{
"arguments": [
{
"name": "value",
"nodeType": "YulIdentifier",
"src": "2158:5:1"
},
{
"arguments": [
{
"name": "value",
"nodeType": "YulIdentifier",
"src": "2182:5:1"
}
],
"functionName": {
"name": "cleanup_t_int256",
"nodeType": "YulIdentifier",
"src": "2165:16:1"
},
"nodeType": "YulFunctionCall",
"src": "2165:23:1"
}
],
"functionName": {
"name": "eq",
"nodeType": "YulIdentifier",
"src": "2155:2:1"
},
"nodeType": "YulFunctionCall",
"src": "2155:34:1"
}
],
"functionName": {
"name": "iszero",
"nodeType": "YulIdentifier",
"src": "2148:6:1"
},
"nodeType": "YulFunctionCall",
"src": "2148:42:1"
},
"nodeType": "YulIf",
"src": "2145:2:1"
}
]
},
"name": "validator_revert_t_int256",
"nodeType": "YulFunctionDefinition",
"parameters": [
{
"name": "value",
"nodeType": "YulTypedName",
"src": "2128:5:1",
"type": ""
}
],
"src": "2093:120:1"
}
]
},
"contents": "{\n\n function abi_decode_t_int256(offset, end) -> value {\n value := calldataload(offset)\n validator_revert_t_int256(value)\n }\n\n function abi_decode_tuple_t_int256(headStart, dataEnd) -> value0 {\n if slt(sub(dataEnd, headStart), 32) { revert(0, 0) }\n\n {\n\n let offset := 0\n\n value0 := abi_decode_t_int256(add(headStart, offset), dataEnd)\n }\n\n }\n\n function abi_encode_t_int256_to_t_int256_fromStack(value, pos) {\n mstore(pos, cleanup_t_int256(value))\n }\n\n function abi_encode_tuple_t_int256__to_t_int256__fromStack_reversed(headStart , value0) -> tail {\n tail := add(headStart, 32)\n\n abi_encode_t_int256_to_t_int256_fromStack(value0, add(headStart, 0))\n\n }\n\n function checked_add_t_int256(x, y) -> sum {\n x := cleanup_t_int256(x)\n y := cleanup_t_int256(y)\n\n // overflow, if x >= 0 and y > (maxValue - x)\n if and(iszero(slt(x, 0)), sgt(y, sub(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, x))) { panic_error_0x11() }\n // underflow, if x < 0 and y < (minValue - x)\n if and(slt(x, 0), slt(y, sub(0x8000000000000000000000000000000000000000000000000000000000000000, x))) { panic_error_0x11() }\n\n sum := add(x, y)\n }\n\n function checked_sub_t_int256(x, y) -> diff {\n x := cleanup_t_int256(x)\n y := cleanup_t_int256(y)\n\n // underflow, if y >= 0 and x < (minValue + y)\n if and(iszero(slt(y, 0)), slt(x, add(0x8000000000000000000000000000000000000000000000000000000000000000, y))) { panic_error_0x11() }\n // overflow, if y < 0 and x > (maxValue + y)\n if and(slt(y, 0), sgt(x, add(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, y))) { panic_error_0x11() }\n\n diff := sub(x, y)\n }\n\n function cleanup_t_int256(value) -> cleaned {\n cleaned := value\n }\n\n function panic_error_0x11() {\n mstore(0, 35408467139433450592217433187231851964531694900788300625387963629091585785856)\n mstore(4, 0x11)\n revert(0, 0x24)\n }\n\n function validator_revert_t_int256(value) {\n if iszero(eq(value, cleanup_t_int256(value))) { revert(0, 0) }\n }\n\n}\n",
"id": 1,
"language": "Yul",
"name": "#utility.yul"
}
],
"immutableReferences": {},
"linkReferences": {},
"object": "608060405234801561001057600080fd5b50600436106100415760003560e01c806312065fe0146100465780637e62eab814610064578063f04991f014610080575b600080fd5b61004e61009c565b60405161005b9190610120565b60405180910390f35b61007e600480360381019061007991906100e8565b6100a5565b005b61009a600480360381019061009591906100e8565b6100bc565b005b60008054905090565b806000546100b391906101cf565b60008190555050565b806000546100ca919061013b565b60008190555050565b6000813590506100e28161029c565b92915050565b6000602082840312156100fa57600080fd5b6000610108848285016100d3565b91505092915050565b61011a81610263565b82525050565b60006020820190506101356000830184610111565b92915050565b600061014682610263565b915061015183610263565b9250817f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0383136000831215161561018c5761018b61026d565b5b817f80000000000000000000000000000000000000000000000000000000000000000383126000831216156101c4576101c361026d565b5b828201905092915050565b60006101da82610263565b91506101e583610263565b9250827f8000000000000000000000000000000000000000000000000000000000000000018212600084121516156102205761021f61026d565b5b827f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0182136000841216156102585761025761026d565b5b828203905092915050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6102a581610263565b81146102b057600080fd5b5056fea2646970667358221220d515ed45a8b4426f6a5a986954398bf55577eb07b43b8d089a7c25929bb2cec064736f6c63430008010033",
"opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x4 CALLDATASIZE LT PUSH2 0x41 JUMPI PUSH1 0x0 CALLDATALOAD PUSH1 0xE0 SHR DUP1 PUSH4 0x12065FE0 EQ PUSH2 0x46 JUMPI DUP1 PUSH4 0x7E62EAB8 EQ PUSH2 0x64 JUMPI DUP1 PUSH4 0xF04991F0 EQ PUSH2 0x80 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH2 0x4E PUSH2 0x9C JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH2 0x5B SWAP2 SWAP1 PUSH2 0x120 JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST PUSH2 0x7E PUSH1 0x4 DUP1 CALLDATASIZE SUB DUP2 ADD SWAP1 PUSH2 0x79 SWAP2 SWAP1 PUSH2 0xE8 JUMP JUMPDEST PUSH2 0xA5 JUMP JUMPDEST STOP JUMPDEST PUSH2 0x9A PUSH1 0x4 DUP1 CALLDATASIZE SUB DUP2 ADD SWAP1 PUSH2 0x95 SWAP2 SWAP1 PUSH2 0xE8 JUMP JUMPDEST PUSH2 0xBC JUMP JUMPDEST STOP JUMPDEST PUSH1 0x0 DUP1 SLOAD SWAP1 POP SWAP1 JUMP JUMPDEST DUP1 PUSH1 0x0 SLOAD PUSH2 0xB3 SWAP2 SWAP1 PUSH2 0x1CF JUMP JUMPDEST PUSH1 0x0 DUP2 SWAP1 SSTORE POP POP JUMP JUMPDEST DUP1 PUSH1 0x0 SLOAD PUSH2 0xCA SWAP2 SWAP1 PUSH2 0x13B JUMP JUMPDEST PUSH1 0x0 DUP2 SWAP1 SSTORE POP POP JUMP JUMPDEST PUSH1 0x0 DUP2 CALLDATALOAD SWAP1 POP PUSH2 0xE2 DUP2 PUSH2 0x29C JUMP JUMPDEST SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 DUP5 SUB SLT ISZERO PUSH2 0xFA JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH1 0x0 PUSH2 0x108 DUP5 DUP3 DUP6 ADD PUSH2 0xD3 JUMP JUMPDEST SWAP2 POP POP SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH2 0x11A DUP2 PUSH2 0x263 JUMP JUMPDEST DUP3 MSTORE POP POP JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 ADD SWAP1 POP PUSH2 0x135 PUSH1 0x0 DUP4 ADD DUP5 PUSH2 0x111 JUMP JUMPDEST SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x0 PUSH2 0x146 DUP3 PUSH2 0x263 JUMP JUMPDEST SWAP2 POP PUSH2 0x151 DUP4 PUSH2 0x263 JUMP JUMPDEST SWAP3 POP DUP2 PUSH32 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF SUB DUP4 SGT PUSH1 0x0 DUP4 SLT ISZERO AND ISZERO PUSH2 0x18C JUMPI PUSH2 0x18B PUSH2 0x26D JUMP JUMPDEST JUMPDEST DUP2 PUSH32 0x8000000000000000000000000000000000000000000000000000000000000000 SUB DUP4 SLT PUSH1 0x0 DUP4 SLT AND ISZERO PUSH2 0x1C4 JUMPI PUSH2 0x1C3 PUSH2 0x26D JUMP JUMPDEST JUMPDEST DUP3 DUP3 ADD SWAP1 POP SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x0 PUSH2 0x1DA DUP3 PUSH2 0x263 JUMP JUMPDEST SWAP2 POP PUSH2 0x1E5 DUP4 PUSH2 0x263 JUMP JUMPDEST SWAP3 POP DUP3 PUSH32 0x8000000000000000000000000000000000000000000000000000000000000000 ADD DUP3 SLT PUSH1 0x0 DUP5 SLT ISZERO AND ISZERO PUSH2 0x220 JUMPI PUSH2 0x21F PUSH2 0x26D JUMP JUMPDEST JUMPDEST DUP3 PUSH32 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ADD DUP3 SGT PUSH1 0x0 DUP5 SLT AND ISZERO PUSH2 0x258 JUMPI PUSH2 0x257 PUSH2 0x26D JUMP JUMPDEST JUMPDEST DUP3 DUP3 SUB SWAP1 POP SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x0 DUP2 SWAP1 POP SWAP2 SWAP1 POP JUMP JUMPDEST PUSH32 0x4E487B7100000000000000000000000000000000000000000000000000000000 PUSH1 0x0 MSTORE PUSH1 0x11 PUSH1 0x4 MSTORE PUSH1 0x24 PUSH1 0x0 REVERT JUMPDEST PUSH2 0x2A5 DUP2 PUSH2 0x263 JUMP JUMPDEST DUP2 EQ PUSH2 0x2B0 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP JUMP INVALID LOG2 PUSH5 0x6970667358 0x22 SLT KECCAK256 0xD5 ISZERO 0xED GASLIMIT 0xA8 0xB4 TIMESTAMP PUSH16 0x6A5A986954398BF55577EB07B43B8D08 SWAP11 PUSH29 0x25929BB2CEC064736F6C63430008010033000000000000000000000000 ",
"sourceMap": "70:304:0:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;154:73;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;;237:63;;;;;;;;;;;;;:::i;:::-;;:::i;:::-;;310:62;;;;;;;;;;;;;:::i;:::-;;:::i;:::-;;154:73;196:3;217;;210:10;;154:73;:::o;237:63::-;290:3;286;;:7;;;;:::i;:::-;280:3;:13;;;;237:63;:::o;310:62::-;362:3;358;;:7;;;;:::i;:::-;352:3;:13;;;;310:62;:::o;7:137:1:-;;90:6;77:20;68:29;;106:32;132:5;106:32;:::i;:::-;58:86;;;;:::o;150:260::-;;257:2;245:9;236:7;232:23;228:32;225:2;;;273:1;270;263:12;225:2;316:1;341:52;385:7;376:6;365:9;361:22;341:52;:::i;:::-;331:62;;287:116;215:195;;;;:::o;416:115::-;501:23;518:5;501:23;:::i;:::-;496:3;489:36;479:52;;:::o;537:218::-;;666:2;655:9;651:18;643:26;;679:69;745:1;734:9;730:17;721:6;679:69;:::i;:::-;633:122;;;;:::o;761:525::-;;819:19;836:1;819:19;:::i;:::-;814:24;;852:19;869:1;852:19;:::i;:::-;847:24;;1040:1;972:66;968:74;965:1;961:82;956:1;953;949:9;942:17;938:106;935:2;;;1047:18;;:::i;:::-;935:2;1227:1;1159:66;1155:74;1152:1;1148:82;1144:1;1141;1137:9;1133:98;1130:2;;;1234:18;;:::i;:::-;1130:2;1278:1;1275;1271:9;1264:16;;804:482;;;;:::o;1292:527::-;;1351:19;1368:1;1351:19;:::i;:::-;1346:24;;1384:19;1401:1;1384:19;:::i;:::-;1379:24;;1573:1;1505:66;1501:74;1498:1;1494:82;1489:1;1486;1482:9;1475:17;1471:106;1468:2;;;1580:18;;:::i;:::-;1468:2;1759:1;1691:66;1687:74;1684:1;1680:82;1676:1;1673;1669:9;1665:98;1662:2;;;1766:18;;:::i;:::-;1662:2;1811:1;1808;1804:9;1796:17;;1336:483;;;;:::o;1825:76::-;;1890:5;1879:16;;1869:32;;;:::o;1907:180::-;1955:77;1952:1;1945:88;2052:4;2049:1;2042:15;2076:4;2073:1;2066:15;2093:120;2165:23;2182:5;2165:23;:::i;:::-;2158:5;2155:34;2145:2;;2203:1;2200;2193:12;2145:2;2135:78;:::o"
},
"gasEstimates": {
"creation": {
"codeDepositCost": "149000",
"executionCost": "20210",
"totalCost": "169210"
},
"external": {
"deposit(int256)": "infinite",
"getBalance()": "1115",
"withdraw(int256)": "infinite"
}
},
"methodIdentifiers": {
"deposit(int256)": "f04991f0",
"getBalance()": "12065fe0",
"withdraw(int256)": "7e62eab8"
}
},
"abi": [
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "int256",
"name": "amt",
"type": "int256"
}
],
"name": "deposit",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "getBalance",
"outputs": [
{
"internalType": "int256",
"name": "",
"type": "int256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "int256",
"name": "amt",
"type": "int256"
}
],
"name": "withdraw",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
}
{
"compiler": {
"version": "0.8.1+commit.df193b15"
},
"language": "Solidity",
"output": {
"abi": [
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "int256",
"name": "amt",
"type": "int256"
}
],
"name": "deposit",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "getBalance",
"outputs": [
{
"internalType": "int256",
"name": "",
"type": "int256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "int256",
"name": "amt",
"type": "int256"
}
],
"name": "withdraw",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"devdoc": {
"kind": "dev",
"methods": {},
"version": 1
},
"userdoc": {
"kind": "user",
"methods": {},
"version": 1
}
},
"settings": {
"compilationTarget": {
"contracts/4_Bank.sol": "Bank"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
},
"sources": {
"contracts/4_Bank.sol": {
"keccak256": "0x29317c12fa220eeebd40e9db7c5edd0f11ba13e247bd3cdd15aabbe764063ec2",
"license": "GPL-3.0",
"urls": [
"bzz-raw://e7c8d62a900a05df4c9223aa25ef5be11e3d7dad9357a0a567144b4b92787609",
"dweb:/ipfs/QmTLhrwFSrDbveWM7ZL6SsfKDCpWKGoEeQEhdLhZL6tQeR"
]
}
},
"version": 1
}
// Right click on the script name and hit "Run" to execute
(async () => {
try {
console.log('Running deployWithEthers script...')
const contractName = 'Storage' // Change this for other contract
const constructorArgs = [] // Put constructor args (if any) here for your contract
// Note that the script needs the ABI which is generated from the compilation artifact.
// Make sure contract is compiled and artifacts are generated
const artifactsPath = `browser/contracts/artifacts/${contractName}.json` // Change this for different path
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
// 'web3Provider' is a remix global variable object
const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner()
let factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer);
let contract = await factory.deploy(...constructorArgs);
console.log('Contract Address: ', contract.address);
// The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed()
console.log('Deployment successful.')
} catch (e) {
console.log(e.message)
}
})()
// Right click on the script name and hit "Run" to execute
(async () => {
try {
console.log('Running deployWithWeb3 script...')
const contractName = 'Storage' // Change this for other contract
const constructorArgs = [] // Put constructor args (if any) here for your contract
// Note that the script needs the ABI which is generated from the compilation artifact.
// Make sure contract is compiled and artifacts are generated
const artifactsPath = `browser/contracts/artifacts/${contractName}.json` // Change this for different path
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
const accounts = await web3.eth.getAccounts()
let contract = new web3.eth.Contract(metadata.abi)
contract = contract.deploy({
data: metadata.data.bytecode.object,
arguments: constructorArgs
})
const newContractInstance = await contract.send({
from: accounts[0],
gas: 1500000,
gasPrice: '30000000000'
})
console.log('Contract deployed at address: ', newContractInstance.options.address)
} catch (e) {
console.log(e.message)
}
})()
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "remix_tests.sol"; // this import is automatically injected by Remix.
import "../contracts/3_Ballot.sol";
contract BallotTest {
bytes32[] proposalNames;
Ballot ballotToTest;
function beforeAll () public {
proposalNames.push(bytes32("candidate1"));
ballotToTest = new Ballot(proposalNames);
}
function checkWinningProposal () public {
ballotToTest.vote(0);
Assert.equal(ballotToTest.winningProposal(), uint(0), "proposal at index 0 should be the winning proposal");
Assert.equal(ballotToTest.winnerName(), bytes32("candidate1"), "candidate1 should be the winner name");
}
function checkWinninProposalWithReturnValue () public view returns (bool) {
return ballotToTest.winningProposal() == 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment