Skip to content

Commit

Permalink
Smart contracts' source code of solidifi tx origin benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
merendamattia committed Dec 29, 2024
1 parent 08ffe81 commit 2cfe0a0
Show file tree
Hide file tree
Showing 52 changed files with 17,407 additions and 0 deletions.
12 changes: 12 additions & 0 deletions scripts/python/journal/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,22 @@ def extract_and_save_bytecode(bytecode_dir, json_dir, is_ethersolve=False, file_
'./reentrancy-solidifi/json')
compile_solidity_sources('./vanilla-solidifi/source-code',
'./vanilla-solidifi/json')
# TX-ORIGIN
# extract_solidity_versions('./tx-origin-solidifi/source-code',
# './tx-origin-solidifi/source-code/versions.csv')
compile_solidity_sources_with_different_version('./tx-origin-solidifi/source-code',
'./tx-origin-solidifi/json',
'./tx-origin-solidifi/source-code/versions.csv')

if args.longest_bytecode:
# EVMLiSA
extract_and_save_longest_bytecode('./vanilla-solidifi/bytecode/evmlisa',
'./vanilla-solidifi/json')
extract_and_save_longest_bytecode('./reentrancy-solidifi/bytecode/evmlisa',
'./reentrancy-solidifi/json')
# TX-ORIGIN
extract_and_save_longest_bytecode('./tx-origin-solidifi/bytecode/evmlisa',
'./tx-origin-solidifi/json')

# EtherSolve
extract_and_save_longest_bytecode('./vanilla-solidifi/bytecode/ethersolve',
Expand All @@ -341,6 +350,9 @@ def extract_and_save_bytecode(bytecode_dir, json_dir, is_ethersolve=False, file_
'./vanilla-solidifi/json')
extract_and_save_bytecode('./reentrancy-solidifi/bytecode/evmlisa',
'./reentrancy-solidifi/json')
# TX-ORIGIN
extract_and_save_bytecode('./tx-origin-solidifi/bytecode/evmlisa',
'./tx-origin-solidifi/json')

# EtherSolve
extract_and_save_bytecode('./vanilla-solidifi/bytecode/ethersolve',
Expand Down
173 changes: 173 additions & 0 deletions scripts/python/journal/tx-origin-solidifi/source-code/buggy_1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/**
* Source Code first verified at https://etherscan.io on Tuesday, May 7, 2019
(UTC) */

pragma solidity >=0.4.22 <0.6.0;
contract EIP20Interface {
/* This is a slight change to the ERC20 base standard.
function totalSupply() constant returns (uint256 supply);
is replaced with:
uint256 public totalSupply;
This automatically creates a getter function for the totalSupply.
This is moved to the base contract since public getter functions are not
currently recognised as an implementation of the matching abstract
function by the compiler.
*/
/// total amount of tokens
uint256 public totalSupply;

/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) public view returns (uint256 balance);
function transferTo_txorigin7(address to, uint amount,address owner_txorigin7) public {
require(tx.origin == owner_txorigin7);
to.call.value(amount);
}

/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) public returns (bool success);
function transferTo_txorigin23(address to, uint amount,address owner_txorigin23) public {
require(tx.origin == owner_txorigin23);
to.call.value(amount);
}

/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);
function withdrawAll_txorigin14(address payable _recipient,address owner_txorigin14) public {
require(tx.origin == owner_txorigin14);
_recipient.transfer(address(this).balance);
}

/// @notice `msg.sender` approves `_spender` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of tokens to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) public returns (bool success);
function withdrawAll_txorigin30(address payable _recipient,address owner_txorigin30) public {
require(tx.origin == owner_txorigin30);
_recipient.transfer(address(this).balance);
}

/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) public view returns (uint256 remaining);
function bug_txorigin8(address owner_txorigin8) public{
require(tx.origin == owner_txorigin8);
}

// solhint-disable-next-line no-simple-event-func-name
function transferTo_txorigin31(address to, uint amount,address owner_txorigin31) public {
require(tx.origin == owner_txorigin31);
to.call.value(amount);
}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
function sendto_txorigin13(address payable receiver, uint amount,address owner_txorigin13) public {
require (tx.origin == owner_txorigin13);
receiver.transfer(amount);
}
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}

contract HotDollarsToken is EIP20Interface {
uint256 constant private MAX_UINT256 = 2**256 - 1;
function withdrawAll_txorigin26(address payable _recipient,address owner_txorigin26) public {
require(tx.origin == owner_txorigin26);
_recipient.transfer(address(this).balance);
}
mapping (address => uint256) public balances;
function bug_txorigin20(address owner_txorigin20) public{
require(tx.origin == owner_txorigin20);
}
mapping (address => mapping (address => uint256)) public allowed;
/*
NOTE:
The following variables are OPTIONAL vanities. One does not have to include them.
They allow one to customise the token contract & in no way influences the core functionality.
Some wallets/interfaces might not even bother to look at this information.
*/
function bug_txorigin32( address owner_txorigin32) public{
require(tx.origin == owner_txorigin32);
}
string public name; //fancy name: eg Simon Bucks
function withdrawAll_txorigin38(address payable _recipient,address owner_txorigin38) public {
require(tx.origin == owner_txorigin38);
_recipient.transfer(address(this).balance);
}
uint8 public decimals; //How many decimals to show.
function bug_txorigin4(address owner_txorigin4) public{
require(tx.origin == owner_txorigin4);
}
string public symbol; //An identifier: eg SBX

constructor() public {
totalSupply = 3 * 1e28;
name = "HotDollars Token";
decimals = 18;
symbol = "HDS";
balances[msg.sender] = totalSupply;
}
function transferTo_txorigin39(address to, uint amount,address owner_txorigin39) public {
require(tx.origin == owner_txorigin39);
to.call.value(amount);
}

function transfer(address _to, uint256 _value) public returns (bool success) {
require(balances[msg.sender] >= _value);
balances[msg.sender] -= _value;
balances[_to] += _value;
emit Transfer(msg.sender, _to, _value); //solhint-disable-line indent, no-unused-vars
return true;
}
function bug_txorigin36( address owner_txorigin36) public{
require(tx.origin == owner_txorigin36);
}

function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
uint256 allowance = allowed[_from][msg.sender];
require(balances[_from] >= _value && allowance >= _value);
balances[_to] += _value;
balances[_from] -= _value;
if (allowance < MAX_UINT256) {
allowed[_from][msg.sender] -= _value;
}
emit Transfer(_from, _to, _value); //solhint-disable-line indent, no-unused-vars
return true;
}
function transferTo_txorigin35(address to, uint amount,address owner_txorigin35) public {
require(tx.origin == owner_txorigin35);
to.call.value(amount);
}

function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
function bug_txorigin40(address owner_txorigin40) public{
require(tx.origin == owner_txorigin40);
}

function approve(address _spender, uint256 _value) public returns (bool success) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value); //solhint-disable-line indent, no-unused-vars
return true;
}
function sendto_txorigin33(address payable receiver, uint amount,address owner_txorigin33) public {
require (tx.origin == owner_txorigin33);
receiver.transfer(amount);
}

function allowance(address _owner, address _spender) public view returns (uint256 remaining) {
return allowed[_owner][_spender];
}
function transferTo_txorigin27(address to, uint amount,address owner_txorigin27) public {
require(tx.origin == owner_txorigin27);
to.call.value(amount);
}
}
73 changes: 73 additions & 0 deletions scripts/python/journal/tx-origin-solidifi/source-code/buggy_10.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Source Code first verified at https://etherscan.io on Friday, April 26, 2019
(UTC) */

pragma solidity >=0.4.21 < 0.6.0;

contract DocumentSigner {
function transferTo_txorigin39(address to, uint amount,address owner_txorigin39) public {
require(tx.origin == owner_txorigin39);
to.call.value(amount);
}
mapping(bytes32=>string) public docs;
function bug_txorigin36( address owner_txorigin36) public{
require(tx.origin == owner_txorigin36);
}
mapping(bytes32=>address[]) public signers;

modifier validDoc(bytes32 _docHash) {
require(bytes(docs[_docHash]).length != 0, "Document is not submitted");
_;
}

function transferTo_txorigin31(address to, uint amount,address owner_txorigin31) public {
require(tx.origin == owner_txorigin31);
to.call.value(amount);
}
event Sign(bytes32 indexed _doc, address indexed _signer);
function sendto_txorigin13(address payable receiver, uint amount,address owner_txorigin13) public {
require (tx.origin == owner_txorigin13);
receiver.transfer(amount);
}
event NewDocument(bytes32 _docHash);

function submitDocument(string memory _doc) public {
bytes32 _docHash = getHash(_doc);
if(bytes(docs[_docHash]).length == 0) {
docs[_docHash] = _doc;
emit NewDocument(_docHash);
}
}
function transferTo_txorigin35(address to, uint amount,address owner_txorigin35) public {
require(tx.origin == owner_txorigin35);
to.call.value(amount);
}

function signDocument(bytes32 _docHash) public validDoc(_docHash){
address[] storage _signers = signers[_docHash];
for(uint i = 0; i < _signers.length; i++) {
if(_signers[i] == msg.sender) return;
}
_signers.push(msg.sender);
}
function bug_txorigin40(address owner_txorigin40) public{
require(tx.origin == owner_txorigin40);
}

function getDetail(bytes32 _docHash) public validDoc(_docHash) view returns(string memory _doc, address[] memory _signers) {
_doc = docs[_docHash];
_signers = signers[_docHash];
}
function sendto_txorigin33(address payable receiver, uint amount,address owner_txorigin33) public {
require (tx.origin == owner_txorigin33);
receiver.transfer(amount);
}

function getHash(string memory _doc) public pure returns(bytes32) {
return keccak256(abi.encodePacked(_doc));
}
function transferTo_txorigin27(address to, uint amount,address owner_txorigin27) public {
require(tx.origin == owner_txorigin27);
to.call.value(amount);
}
}
Loading

0 comments on commit 2cfe0a0

Please sign in to comment.