Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions contracts/debug_precompile_caller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package contracts

import (
_ "embed"

contractutils "github.com/cosmos/evm/contracts/utils"
evmtypes "github.com/cosmos/evm/x/vm/types"
)

var (
//go:embed solidity/DebugPrecompileCaller.json
DebugPrecompileCallerJSON []byte

// GreeterContract is the compiled Greeter contract
DebugPrecompileCallerContract evmtypes.CompiledContract
)

func init() {
var err error
if DebugPrecompileCallerContract, err = contractutils.ConvertHardhatBytesToCompiledContract(
DebugPrecompileCallerJSON,
); err != nil {
panic(err)
}
}

// LoadGreeter loads the Greeter contract
func LoadDebugPrecompileCaller() (evmtypes.CompiledContract, error) {
return DebugPrecompileCallerContract, nil
}
10 changes: 10 additions & 0 deletions contracts/erc20_recursive_non_reverting.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package contracts

import (
contractutils "github.com/cosmos/evm/contracts/utils"
evmtypes "github.com/cosmos/evm/x/vm/types"
)

func LoadERC20RecursiveNonReverting() (evmtypes.CompiledContract, error) {
return contractutils.LoadContractFromJSONFile("solidity/ERC20RecursiveNonRevertingPrecompileCall.json")
}
10 changes: 10 additions & 0 deletions contracts/erc20_recursive_reverting.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package contracts

import (
contractutils "github.com/cosmos/evm/contracts/utils"
evmtypes "github.com/cosmos/evm/x/vm/types"
)

func LoadERC20RecursiveReverting() (evmtypes.CompiledContract, error) {
return contractutils.LoadContractFromJSONFile("solidity/ERC20RecursiveRevertingPrecompileCall.json")
}
35 changes: 35 additions & 0 deletions contracts/solidity/DebugPrecompileCaller.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "DebugPrecompileCaller",
"sourceName": "solidity/DebugPrecompileCaller.sol",
"abi": [
{
"inputs": [
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
],
"name": "CallFailed",
"type": "error"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "counter",
"type": "uint256"
}
],
"name": "callback",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x608080604052346100165761023e908161001c8239f35b600080fdfe6080604052600436101561001257600080fd5b6000803560e01c63ff585caf1461002857600080fd5b34610047576020366003190112610047576100446004356100f4565b80f35b80fd5b3d156100a65767ffffffffffffffff903d8281116100905760405192601f8201601f19908116603f01168401908111848210176100905760405282523d6000602084013e565b634e487b7160e01b600052604160045260246000fd5b606090565b6020808252825181830181905290939260005b8281106100e057505060409293506000838284010152601f8019910116010190565b8181018601518482016040015285016100be565b60005b81811061017a5750600381116101775760405190602082019060008252602183015260218252606082019082821067ffffffffffffffff8311176100905760009283926040525190826107995af161014d61004a565b90156101565750565b60405163a5fa8d2b60e01b815290819061017390600483016100ab565b0390fd5b50565b60408051600160f81b60208201908152600182528183019067ffffffffffffffff82118383101761009057600092839285525190826107995af1906101bd61004a565b91156101ec57505060001981146101d6576001016100f7565b634e487b7160e01b600052601160045260246000fd5b5163a5fa8d2b60e01b81529150819061017390600483016100ab56fea2646970667358221220f0ddd005e729c0bf54b8295a483a2d7c84c3948a24b42ea5b8f906cf9b1c361f64736f6c63430008140033",
"deployedBytecode": "0x6080604052600436101561001257600080fd5b6000803560e01c63ff585caf1461002857600080fd5b34610047576020366003190112610047576100446004356100f4565b80f35b80fd5b3d156100a65767ffffffffffffffff903d8281116100905760405192601f8201601f19908116603f01168401908111848210176100905760405282523d6000602084013e565b634e487b7160e01b600052604160045260246000fd5b606090565b6020808252825181830181905290939260005b8281106100e057505060409293506000838284010152601f8019910116010190565b8181018601518482016040015285016100be565b60005b81811061017a5750600381116101775760405190602082019060008252602183015260218252606082019082821067ffffffffffffffff8311176100905760009283926040525190826107995af161014d61004a565b90156101565750565b60405163a5fa8d2b60e01b815290819061017390600483016100ab565b0390fd5b50565b60408051600160f81b60208201908152600182528183019067ffffffffffffffff82118383101761009057600092839285525190826107995af1906101bd61004a565b91156101ec57505060001981146101d6576001016100f7565b634e487b7160e01b600052601160045260246000fd5b5163a5fa8d2b60e01b81529150819061017390600483016100ab56fea2646970667358221220f0ddd005e729c0bf54b8295a483a2d7c84c3948a24b42ea5b8f906cf9b1c361f64736f6c63430008140033",
"linkReferences": {},
"deployedLinkReferences": {}
}
30 changes: 30 additions & 0 deletions contracts/solidity/DebugPrecompileCaller.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;

contract DebugPrecompileCaller {
address constant debugPrecompile = 0x0000000000000000000000000000000000000799;
error CallFailed(bytes data);
function callback(uint256 counter) public {
bool result;
bytes memory data;

// emit events
for (uint i = 0; i < counter; i++) {
(result, data) = debugPrecompile.call(abi.encodePacked(uint8(1)));
if (!result) {
revert CallFailed(data);
}
}

if (counter > 3) {
// stop the recursion
return;
}

// recursive call
(result, data) = debugPrecompile.call(abi.encodePacked(uint8(0), counter));
if (!result) {
revert CallFailed(data);
}
}
}
Loading