diff --git a/contracts/contracts/ExampleSHA256.sol b/contracts/contracts/ExampleSHA256.sol index cbe0bd563b..b6cb67e1f1 100644 --- a/contracts/contracts/ExampleSHA256.sol +++ b/contracts/contracts/ExampleSHA256.sol @@ -1,9 +1,15 @@ pragma solidity ^0.8.0; +import "hardhat/console.sol"; + contract ExampleSHA256 { function hashSha256(uint256 numberToHash) public view returns (bytes32 h) { (bool ok, bytes memory out) = address(2).staticcall(abi.encode(numberToHash)); require(ok, "precompile call failed"); + + console.logString("log out:"); + console.logBytes(out); + h = abi.decode(out, (bytes32)); } } diff --git a/contracts/contracts/ExampleSum3.sol b/contracts/contracts/ExampleSum3.sol new file mode 100644 index 0000000000..c3d2edb021 --- /dev/null +++ b/contracts/contracts/ExampleSum3.sol @@ -0,0 +1,16 @@ +pragma solidity ^0.8.0; + +import "hardhat/console.sol"; + +contract ExampleSum3 { + function sum3(bytes32 a) public view returns (bytes memory h) { + (bool ok, bytes memory out) = address(0x0b).staticcall(abi.encode(a)); + require(ok, "precompile call failed"); + + console.logString("log out:"); + console.logBytes(out); + +// h = abi.decode(out, (bytes)); + h = out; + } +} diff --git a/contracts/hardhat.config.ts b/contracts/hardhat.config.ts index 89f1198fa9..e9781457b6 100644 --- a/contracts/hardhat.config.ts +++ b/contracts/hardhat.config.ts @@ -2,6 +2,7 @@ import { HardhatUserConfig } from "hardhat/config"; import "@nomicfoundation/hardhat-toolbox"; const config: HardhatUserConfig = { + // defaultNetwork: "geth", defaultNetwork: "geth", networks: { hardhat: {}, diff --git a/contracts/test/sum3.ts b/contracts/test/sum3.ts new file mode 100644 index 0000000000..3c46302150 --- /dev/null +++ b/contracts/test/sum3.ts @@ -0,0 +1,20 @@ +import { + time, + loadFixture, +} from "@nomicfoundation/hardhat-toolbox/network-helpers"; +import { anyValue } from "@nomicfoundation/hardhat-chai-matchers/withArgs"; +import { expect } from "chai"; +import { ethers } from "hardhat"; + +describe("sum3", function() { + it("Should properly calculate sum of 3 numbers", async function () { + const ExampleSum3 = await ethers.getContractFactory("ExampleSum3") + const exampleSum3 = await ExampleSum3.deploy(); + + const array = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3] + const uint8Array = new Uint8Array(array); + console.log(await exampleSum3.sum3(uint8Array)); + + expect(await exampleSum3.sum3(uint8Array)).to.equal("0x0000000000000000000000000000000000000000000000000000000000000003"); + }) +}) diff --git a/contracts/typechain-types/ExampleSum3.sol/ExampleSHA256.ts b/contracts/typechain-types/ExampleSum3.sol/ExampleSHA256.ts new file mode 100644 index 0000000000..e514e739ff --- /dev/null +++ b/contracts/typechain-types/ExampleSum3.sol/ExampleSHA256.ts @@ -0,0 +1,88 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BigNumberish, + BytesLike, + FunctionFragment, + Result, + Interface, + ContractRunner, + ContractMethod, + Listener, +} from "ethers"; +import type { + TypedContractEvent, + TypedDeferredTopicFilter, + TypedEventLog, + TypedListener, + TypedContractMethod, +} from "../common"; + +export interface ExampleSHA256Interface extends Interface { + getFunction(nameOrSignature: "hashSha256"): FunctionFragment; + + encodeFunctionData( + functionFragment: "hashSha256", + values: [BigNumberish] + ): string; + + decodeFunctionResult(functionFragment: "hashSha256", data: BytesLike): Result; +} + +export interface ExampleSHA256 extends BaseContract { + connect(runner?: ContractRunner | null): ExampleSHA256; + waitForDeployment(): Promise; + + interface: ExampleSHA256Interface; + + queryFilter( + event: TCEvent, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + queryFilter( + filter: TypedDeferredTopicFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + + on( + event: TCEvent, + listener: TypedListener + ): Promise; + on( + filter: TypedDeferredTopicFilter, + listener: TypedListener + ): Promise; + + once( + event: TCEvent, + listener: TypedListener + ): Promise; + once( + filter: TypedDeferredTopicFilter, + listener: TypedListener + ): Promise; + + listeners( + event: TCEvent + ): Promise>>; + listeners(eventName?: string): Promise>; + removeAllListeners( + event?: TCEvent + ): Promise; + + hashSha256: TypedContractMethod<[a: BigNumberish], [bigint], "view">; + + getFunction( + key: string | FunctionFragment + ): T; + + getFunction( + nameOrSignature: "hashSha256" + ): TypedContractMethod<[a: BigNumberish], [bigint], "view">; + + filters: {}; +} diff --git a/contracts/typechain-types/ExampleSum3.sol/ExampleSum3.ts b/contracts/typechain-types/ExampleSum3.sol/ExampleSum3.ts new file mode 100644 index 0000000000..524489434f --- /dev/null +++ b/contracts/typechain-types/ExampleSum3.sol/ExampleSum3.ts @@ -0,0 +1,85 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BigNumberish, + BytesLike, + FunctionFragment, + Result, + Interface, + ContractRunner, + ContractMethod, + Listener, +} from "ethers"; +import type { + TypedContractEvent, + TypedDeferredTopicFilter, + TypedEventLog, + TypedListener, + TypedContractMethod, +} from "../common"; + +export interface ExampleSum3Interface extends Interface { + getFunction(nameOrSignature: "sum3"): FunctionFragment; + + encodeFunctionData(functionFragment: "sum3", values: [BigNumberish]): string; + + decodeFunctionResult(functionFragment: "sum3", data: BytesLike): Result; +} + +export interface ExampleSum3 extends BaseContract { + connect(runner?: ContractRunner | null): ExampleSum3; + waitForDeployment(): Promise; + + interface: ExampleSum3Interface; + + queryFilter( + event: TCEvent, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + queryFilter( + filter: TypedDeferredTopicFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + + on( + event: TCEvent, + listener: TypedListener + ): Promise; + on( + filter: TypedDeferredTopicFilter, + listener: TypedListener + ): Promise; + + once( + event: TCEvent, + listener: TypedListener + ): Promise; + once( + filter: TypedDeferredTopicFilter, + listener: TypedListener + ): Promise; + + listeners( + event: TCEvent + ): Promise>>; + listeners(eventName?: string): Promise>; + removeAllListeners( + event?: TCEvent + ): Promise; + + sum3: TypedContractMethod<[a: BigNumberish], [bigint], "view">; + + getFunction( + key: string | FunctionFragment + ): T; + + getFunction( + nameOrSignature: "sum3" + ): TypedContractMethod<[a: BigNumberish], [bigint], "view">; + + filters: {}; +} diff --git a/contracts/typechain-types/ExampleSum3.sol/index.ts b/contracts/typechain-types/ExampleSum3.sol/index.ts new file mode 100644 index 0000000000..52e516b680 --- /dev/null +++ b/contracts/typechain-types/ExampleSum3.sol/index.ts @@ -0,0 +1,5 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export type { ExampleSHA256 } from "./ExampleSHA256"; +export type { ExampleSum3 } from "./ExampleSum3"; diff --git a/contracts/typechain-types/ExampleSum3.ts b/contracts/typechain-types/ExampleSum3.ts new file mode 100644 index 0000000000..59ff17cb64 --- /dev/null +++ b/contracts/typechain-types/ExampleSum3.ts @@ -0,0 +1,84 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BytesLike, + FunctionFragment, + Result, + Interface, + ContractRunner, + ContractMethod, + Listener, +} from "ethers"; +import type { + TypedContractEvent, + TypedDeferredTopicFilter, + TypedEventLog, + TypedListener, + TypedContractMethod, +} from "./common"; + +export interface ExampleSum3Interface extends Interface { + getFunction(nameOrSignature: "sum3"): FunctionFragment; + + encodeFunctionData(functionFragment: "sum3", values: [BytesLike]): string; + + decodeFunctionResult(functionFragment: "sum3", data: BytesLike): Result; +} + +export interface ExampleSum3 extends BaseContract { + connect(runner?: ContractRunner | null): ExampleSum3; + waitForDeployment(): Promise; + + interface: ExampleSum3Interface; + + queryFilter( + event: TCEvent, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + queryFilter( + filter: TypedDeferredTopicFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + + on( + event: TCEvent, + listener: TypedListener + ): Promise; + on( + filter: TypedDeferredTopicFilter, + listener: TypedListener + ): Promise; + + once( + event: TCEvent, + listener: TypedListener + ): Promise; + once( + filter: TypedDeferredTopicFilter, + listener: TypedListener + ): Promise; + + listeners( + event: TCEvent + ): Promise>>; + listeners(eventName?: string): Promise>; + removeAllListeners( + event?: TCEvent + ): Promise; + + sum3: TypedContractMethod<[a: BytesLike], [string], "view">; + + getFunction( + key: string | FunctionFragment + ): T; + + getFunction( + nameOrSignature: "sum3" + ): TypedContractMethod<[a: BytesLike], [string], "view">; + + filters: {}; +} diff --git a/contracts/typechain-types/factories/ExampleSHA256__factory.ts b/contracts/typechain-types/factories/ExampleSHA256__factory.ts index c2296a30ef..708365de6a 100644 --- a/contracts/typechain-types/factories/ExampleSHA256__factory.ts +++ b/contracts/typechain-types/factories/ExampleSHA256__factory.ts @@ -34,7 +34,7 @@ const _abi = [ ] as const; const _bytecode = - "0x608060405234801561001057600080fd5b506103a6806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063d121893114610030575b600080fd5b61004a60048036038101906100459190610187565b610060565b60405161005791906101cd565b60405180910390f35b6000806000600273ffffffffffffffffffffffffffffffffffffffff168460405160200161008e91906101f7565b6040516020818303038152906040526040516100aa9190610283565b600060405180830381855afa9150503d80600081146100e5576040519150601f19603f3d011682016040523d82523d6000602084013e6100ea565b606091505b50915091508161012f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610126906102f7565b60405180910390fd5b808060200190518101906101439190610343565b92505050919050565b600080fd5b6000819050919050565b61016481610151565b811461016f57600080fd5b50565b6000813590506101818161015b565b92915050565b60006020828403121561019d5761019c61014c565b5b60006101ab84828501610172565b91505092915050565b6000819050919050565b6101c7816101b4565b82525050565b60006020820190506101e260008301846101be565b92915050565b6101f181610151565b82525050565b600060208201905061020c60008301846101e8565b92915050565b600081519050919050565b600081905092915050565b60005b8381101561024657808201518184015260208101905061022b565b60008484015250505050565b600061025d82610212565b610267818561021d565b9350610277818560208601610228565b80840191505092915050565b600061028f8284610252565b915081905092915050565b600082825260208201905092915050565b7f707265636f6d70696c652063616c6c206661696c656400000000000000000000600082015250565b60006102e160168361029a565b91506102ec826102ab565b602082019050919050565b60006020820190508181036000830152610310816102d4565b9050919050565b610320816101b4565b811461032b57600080fd5b50565b60008151905061033d81610317565b92915050565b6000602082840312156103595761035861014c565b5b60006103678482850161032e565b9150509291505056fea2646970667358221220ddec545ddbc7f2919666033e50c25e284ec8fc46aa071d2478abce59dfdddcbb64736f6c63430008130033"; + "0x608060405234801561001057600080fd5b50610681806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063d121893114610030575b600080fd5b61004a60048036038101906100459190610350565b610060565b6040516100579190610396565b60405180910390f35b6000806000600273ffffffffffffffffffffffffffffffffffffffff168460405160200161008e91906103c0565b6040516020818303038152906040526040516100aa919061044c565b600060405180830381855afa9150503d80600081146100e5576040519150601f19603f3d011682016040523d82523d6000602084013e6100ea565b606091505b50915091508161012f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610126906104c0565b60405180910390fd5b61016d6040518060400160405280600881526020017f6c6f67206f75743a000000000000000000000000000000000000000000000000815250610193565b6101768161022c565b8080602001905181019061018a919061050c565b92505050919050565b610229816040516024016101a7919061058e565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506102c5565b50565b6102c28160405160240161024091906105fa565b6040516020818303038152906040527f0be77f56000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506102c5565b50565b6102dc816102d46102df610300565b63ffffffff16565b50565b60006a636f6e736f6c652e6c6f679050600080835160208501845afa505050565b61030b819050919050565b61031361061c565b565b600080fd5b6000819050919050565b61032d8161031a565b811461033857600080fd5b50565b60008135905061034a81610324565b92915050565b60006020828403121561036657610365610315565b5b60006103748482850161033b565b91505092915050565b6000819050919050565b6103908161037d565b82525050565b60006020820190506103ab6000830184610387565b92915050565b6103ba8161031a565b82525050565b60006020820190506103d560008301846103b1565b92915050565b600081519050919050565b600081905092915050565b60005b8381101561040f5780820151818401526020810190506103f4565b60008484015250505050565b6000610426826103db565b61043081856103e6565b93506104408185602086016103f1565b80840191505092915050565b6000610458828461041b565b915081905092915050565b600082825260208201905092915050565b7f707265636f6d70696c652063616c6c206661696c656400000000000000000000600082015250565b60006104aa601683610463565b91506104b582610474565b602082019050919050565b600060208201905081810360008301526104d98161049d565b9050919050565b6104e98161037d565b81146104f457600080fd5b50565b600081519050610506816104e0565b92915050565b60006020828403121561052257610521610315565b5b6000610530848285016104f7565b91505092915050565b600081519050919050565b6000601f19601f8301169050919050565b600061056082610539565b61056a8185610463565b935061057a8185602086016103f1565b61058381610544565b840191505092915050565b600060208201905081810360008301526105a88184610555565b905092915050565b600082825260208201905092915050565b60006105cc826103db565b6105d681856105b0565b93506105e68185602086016103f1565b6105ef81610544565b840191505092915050565b6000602082019050818103600083015261061481846105c1565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052605160045260246000fdfea26469706673582212203f893be732789443c2aed374de980d148342a60e0beae3d31bf4aac8becef00664736f6c63430008130033"; type ExampleSHA256ConstructorParams = | [signer?: Signer] diff --git a/contracts/typechain-types/factories/ExampleSum3.sol/ExampleSHA256__factory.ts b/contracts/typechain-types/factories/ExampleSum3.sol/ExampleSHA256__factory.ts new file mode 100644 index 0000000000..510dc6cb31 --- /dev/null +++ b/contracts/typechain-types/factories/ExampleSum3.sol/ExampleSHA256__factory.ts @@ -0,0 +1,86 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import { + Contract, + ContractFactory, + ContractTransactionResponse, + Interface, +} from "ethers"; +import type { Signer, ContractDeployTransaction, ContractRunner } from "ethers"; +import type { NonPayableOverrides } from "../../common"; +import type { + ExampleSHA256, + ExampleSHA256Interface, +} from "../../ExampleSum3.sol/ExampleSHA256"; + +const _abi = [ + { + inputs: [ + { + internalType: "uint256", + name: "a", + type: "uint256", + }, + ], + name: "hashSha256", + outputs: [ + { + internalType: "uint256", + name: "h", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, +] as const; + +const _bytecode = + "0x608060405234801561001057600080fd5b5061035b806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063d121893114610030575b600080fd5b61004a60048036038101906100459190610187565b610060565b60405161005791906101c3565b60405180910390f35b6000806000600b73ffffffffffffffffffffffffffffffffffffffff168460405160200161008e91906101c3565b6040516020818303038152906040526040516100aa919061024f565b600060405180830381855afa9150503d80600081146100e5576040519150601f19603f3d011682016040523d82523d6000602084013e6100ea565b606091505b50915091508161012f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610126906102c3565b60405180910390fd5b8080602001905181019061014391906102f8565b92505050919050565b600080fd5b6000819050919050565b61016481610151565b811461016f57600080fd5b50565b6000813590506101818161015b565b92915050565b60006020828403121561019d5761019c61014c565b5b60006101ab84828501610172565b91505092915050565b6101bd81610151565b82525050565b60006020820190506101d860008301846101b4565b92915050565b600081519050919050565b600081905092915050565b60005b838110156102125780820151818401526020810190506101f7565b60008484015250505050565b6000610229826101de565b61023381856101e9565b93506102438185602086016101f4565b80840191505092915050565b600061025b828461021e565b915081905092915050565b600082825260208201905092915050565b7f707265636f6d70696c652063616c6c206661696c656400000000000000000000600082015250565b60006102ad601683610266565b91506102b882610277565b602082019050919050565b600060208201905081810360008301526102dc816102a0565b9050919050565b6000815190506102f28161015b565b92915050565b60006020828403121561030e5761030d61014c565b5b600061031c848285016102e3565b9150509291505056fea264697066735822122079f8359ae87ca86b4bce083e8343c4c4b70f2e253d4e20f1fbe349a6799db02364736f6c63430008130033"; + +type ExampleSHA256ConstructorParams = + | [signer?: Signer] + | ConstructorParameters; + +const isSuperArgs = ( + xs: ExampleSHA256ConstructorParams +): xs is ConstructorParameters => xs.length > 1; + +export class ExampleSHA256__factory extends ContractFactory { + constructor(...args: ExampleSHA256ConstructorParams) { + if (isSuperArgs(args)) { + super(...args); + } else { + super(_abi, _bytecode, args[0]); + } + } + + override getDeployTransaction( + overrides?: NonPayableOverrides & { from?: string } + ): Promise { + return super.getDeployTransaction(overrides || {}); + } + override deploy(overrides?: NonPayableOverrides & { from?: string }) { + return super.deploy(overrides || {}) as Promise< + ExampleSHA256 & { + deploymentTransaction(): ContractTransactionResponse; + } + >; + } + override connect(runner: ContractRunner | null): ExampleSHA256__factory { + return super.connect(runner) as ExampleSHA256__factory; + } + + static readonly bytecode = _bytecode; + static readonly abi = _abi; + static createInterface(): ExampleSHA256Interface { + return new Interface(_abi) as ExampleSHA256Interface; + } + static connect( + address: string, + runner?: ContractRunner | null + ): ExampleSHA256 { + return new Contract(address, _abi, runner) as unknown as ExampleSHA256; + } +} diff --git a/contracts/typechain-types/factories/ExampleSum3.sol/ExampleSum3__factory.ts b/contracts/typechain-types/factories/ExampleSum3.sol/ExampleSum3__factory.ts new file mode 100644 index 0000000000..34f85e2421 --- /dev/null +++ b/contracts/typechain-types/factories/ExampleSum3.sol/ExampleSum3__factory.ts @@ -0,0 +1,83 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import { + Contract, + ContractFactory, + ContractTransactionResponse, + Interface, +} from "ethers"; +import type { Signer, ContractDeployTransaction, ContractRunner } from "ethers"; +import type { NonPayableOverrides } from "../../common"; +import type { + ExampleSum3, + ExampleSum3Interface, +} from "../../ExampleSum3.sol/ExampleSum3"; + +const _abi = [ + { + inputs: [ + { + internalType: "uint256", + name: "a", + type: "uint256", + }, + ], + name: "sum3", + outputs: [ + { + internalType: "uint256", + name: "h", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, +] as const; + +const _bytecode = + "0x608060405234801561001057600080fd5b5061035b806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80638c0a4c6014610030575b600080fd5b61004a60048036038101906100459190610187565b610060565b60405161005791906101c3565b60405180910390f35b6000806000600b73ffffffffffffffffffffffffffffffffffffffff168460405160200161008e91906101c3565b6040516020818303038152906040526040516100aa919061024f565b600060405180830381855afa9150503d80600081146100e5576040519150601f19603f3d011682016040523d82523d6000602084013e6100ea565b606091505b50915091508161012f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610126906102c3565b60405180910390fd5b8080602001905181019061014391906102f8565b92505050919050565b600080fd5b6000819050919050565b61016481610151565b811461016f57600080fd5b50565b6000813590506101818161015b565b92915050565b60006020828403121561019d5761019c61014c565b5b60006101ab84828501610172565b91505092915050565b6101bd81610151565b82525050565b60006020820190506101d860008301846101b4565b92915050565b600081519050919050565b600081905092915050565b60005b838110156102125780820151818401526020810190506101f7565b60008484015250505050565b6000610229826101de565b61023381856101e9565b93506102438185602086016101f4565b80840191505092915050565b600061025b828461021e565b915081905092915050565b600082825260208201905092915050565b7f707265636f6d70696c652063616c6c206661696c656400000000000000000000600082015250565b60006102ad601683610266565b91506102b882610277565b602082019050919050565b600060208201905081810360008301526102dc816102a0565b9050919050565b6000815190506102f28161015b565b92915050565b60006020828403121561030e5761030d61014c565b5b600061031c848285016102e3565b9150509291505056fea264697066735822122026d37d055f4d8d59fa5b862157bdfc08b43334894c938e86a5f4ae4bf4b7f29a64736f6c63430008130033"; + +type ExampleSum3ConstructorParams = + | [signer?: Signer] + | ConstructorParameters; + +const isSuperArgs = ( + xs: ExampleSum3ConstructorParams +): xs is ConstructorParameters => xs.length > 1; + +export class ExampleSum3__factory extends ContractFactory { + constructor(...args: ExampleSum3ConstructorParams) { + if (isSuperArgs(args)) { + super(...args); + } else { + super(_abi, _bytecode, args[0]); + } + } + + override getDeployTransaction( + overrides?: NonPayableOverrides & { from?: string } + ): Promise { + return super.getDeployTransaction(overrides || {}); + } + override deploy(overrides?: NonPayableOverrides & { from?: string }) { + return super.deploy(overrides || {}) as Promise< + ExampleSum3 & { + deploymentTransaction(): ContractTransactionResponse; + } + >; + } + override connect(runner: ContractRunner | null): ExampleSum3__factory { + return super.connect(runner) as ExampleSum3__factory; + } + + static readonly bytecode = _bytecode; + static readonly abi = _abi; + static createInterface(): ExampleSum3Interface { + return new Interface(_abi) as ExampleSum3Interface; + } + static connect(address: string, runner?: ContractRunner | null): ExampleSum3 { + return new Contract(address, _abi, runner) as unknown as ExampleSum3; + } +} diff --git a/contracts/typechain-types/factories/ExampleSum3.sol/index.ts b/contracts/typechain-types/factories/ExampleSum3.sol/index.ts new file mode 100644 index 0000000000..6d2bbb5792 --- /dev/null +++ b/contracts/typechain-types/factories/ExampleSum3.sol/index.ts @@ -0,0 +1,5 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export { ExampleSHA256__factory } from "./ExampleSHA256__factory"; +export { ExampleSum3__factory } from "./ExampleSum3__factory"; diff --git a/contracts/typechain-types/factories/ExampleSum3__factory.ts b/contracts/typechain-types/factories/ExampleSum3__factory.ts new file mode 100644 index 0000000000..d5088b0718 --- /dev/null +++ b/contracts/typechain-types/factories/ExampleSum3__factory.ts @@ -0,0 +1,80 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import { + Contract, + ContractFactory, + ContractTransactionResponse, + Interface, +} from "ethers"; +import type { Signer, ContractDeployTransaction, ContractRunner } from "ethers"; +import type { NonPayableOverrides } from "../common"; +import type { ExampleSum3, ExampleSum3Interface } from "../ExampleSum3"; + +const _abi = [ + { + inputs: [ + { + internalType: "bytes32", + name: "a", + type: "bytes32", + }, + ], + name: "sum3", + outputs: [ + { + internalType: "bytes", + name: "h", + type: "bytes", + }, + ], + stateMutability: "view", + type: "function", + }, +] as const; + +const _bytecode = + "0x608060405234801561001057600080fd5b506105e1806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c806310b19c6714610030575b600080fd5b61004a6004803603810190610045919061033d565b610060565b60405161005791906103fa565b60405180910390f35b6060600080600b73ffffffffffffffffffffffffffffffffffffffff168460405160200161008e919061042b565b6040516020818303038152906040526040516100aa9190610482565b600060405180830381855afa9150503d80600081146100e5576040519150601f19603f3d011682016040523d82523d6000602084013e6100ea565b606091505b50915091508161012f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610126906104f6565b60405180910390fd5b61016d6040518060400160405280600881526020017f6c6f67206f75743a000000000000000000000000000000000000000000000000815250610180565b61017681610219565b8092505050919050565b61021681604051602401610194919061055a565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506102b2565b50565b6102af8160405160240161022d91906103fa565b6040516020818303038152906040527f0be77f56000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506102b2565b50565b6102c9816102c16102cc6102ed565b63ffffffff16565b50565b60006a636f6e736f6c652e6c6f679050600080835160208501845afa505050565b6102f8819050919050565b61030061057c565b565b600080fd5b6000819050919050565b61031a81610307565b811461032557600080fd5b50565b60008135905061033781610311565b92915050565b60006020828403121561035357610352610302565b5b600061036184828501610328565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60005b838110156103a4578082015181840152602081019050610389565b60008484015250505050565b6000601f19601f8301169050919050565b60006103cc8261036a565b6103d68185610375565b93506103e6818560208601610386565b6103ef816103b0565b840191505092915050565b6000602082019050818103600083015261041481846103c1565b905092915050565b61042581610307565b82525050565b6000602082019050610440600083018461041c565b92915050565b600081905092915050565b600061045c8261036a565b6104668185610446565b9350610476818560208601610386565b80840191505092915050565b600061048e8284610451565b915081905092915050565b600082825260208201905092915050565b7f707265636f6d70696c652063616c6c206661696c656400000000000000000000600082015250565b60006104e0601683610499565b91506104eb826104aa565b602082019050919050565b6000602082019050818103600083015261050f816104d3565b9050919050565b600081519050919050565b600061052c82610516565b6105368185610499565b9350610546818560208601610386565b61054f816103b0565b840191505092915050565b600060208201905081810360008301526105748184610521565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052605160045260246000fdfea2646970667358221220a11a3764504ba767a98f1f80053560a19726cafb73623fec58b820da70cd0e8964736f6c63430008130033"; + +type ExampleSum3ConstructorParams = + | [signer?: Signer] + | ConstructorParameters; + +const isSuperArgs = ( + xs: ExampleSum3ConstructorParams +): xs is ConstructorParameters => xs.length > 1; + +export class ExampleSum3__factory extends ContractFactory { + constructor(...args: ExampleSum3ConstructorParams) { + if (isSuperArgs(args)) { + super(...args); + } else { + super(_abi, _bytecode, args[0]); + } + } + + override getDeployTransaction( + overrides?: NonPayableOverrides & { from?: string } + ): Promise { + return super.getDeployTransaction(overrides || {}); + } + override deploy(overrides?: NonPayableOverrides & { from?: string }) { + return super.deploy(overrides || {}) as Promise< + ExampleSum3 & { + deploymentTransaction(): ContractTransactionResponse; + } + >; + } + override connect(runner: ContractRunner | null): ExampleSum3__factory { + return super.connect(runner) as ExampleSum3__factory; + } + + static readonly bytecode = _bytecode; + static readonly abi = _abi; + static createInterface(): ExampleSum3Interface { + return new Interface(_abi) as ExampleSum3Interface; + } + static connect(address: string, runner?: ContractRunner | null): ExampleSum3 { + return new Contract(address, _abi, runner) as unknown as ExampleSum3; + } +} diff --git a/contracts/typechain-types/factories/index.ts b/contracts/typechain-types/factories/index.ts index 91cab03f4d..554e11dad5 100644 --- a/contracts/typechain-types/factories/index.ts +++ b/contracts/typechain-types/factories/index.ts @@ -2,4 +2,5 @@ /* tslint:disable */ /* eslint-disable */ export { ExampleSHA256__factory } from "./ExampleSHA256__factory"; +export { ExampleSum3__factory } from "./ExampleSum3__factory"; export { Lock__factory } from "./Lock__factory"; diff --git a/contracts/typechain-types/hardhat.d.ts b/contracts/typechain-types/hardhat.d.ts index 8adea786db..1d559791cc 100644 --- a/contracts/typechain-types/hardhat.d.ts +++ b/contracts/typechain-types/hardhat.d.ts @@ -17,6 +17,10 @@ declare module "hardhat/types/runtime" { name: "ExampleSHA256", signerOrOptions?: ethers.Signer | FactoryOptions ): Promise; + getContractFactory( + name: "ExampleSum3", + signerOrOptions?: ethers.Signer | FactoryOptions + ): Promise; getContractFactory( name: "Lock", signerOrOptions?: ethers.Signer | FactoryOptions @@ -27,6 +31,11 @@ declare module "hardhat/types/runtime" { address: string | ethers.Addressable, signer?: ethers.Signer ): Promise; + getContractAt( + name: "ExampleSum3", + address: string | ethers.Addressable, + signer?: ethers.Signer + ): Promise; getContractAt( name: "Lock", address: string | ethers.Addressable, @@ -37,6 +46,10 @@ declare module "hardhat/types/runtime" { name: "ExampleSHA256", signerOrOptions?: ethers.Signer | DeployContractOptions ): Promise; + deployContract( + name: "ExampleSum3", + signerOrOptions?: ethers.Signer | DeployContractOptions + ): Promise; deployContract( name: "Lock", signerOrOptions?: ethers.Signer | DeployContractOptions @@ -47,6 +60,11 @@ declare module "hardhat/types/runtime" { args: any[], signerOrOptions?: ethers.Signer | DeployContractOptions ): Promise; + deployContract( + name: "ExampleSum3", + args: any[], + signerOrOptions?: ethers.Signer | DeployContractOptions + ): Promise; deployContract( name: "Lock", args: any[], diff --git a/contracts/typechain-types/index.ts b/contracts/typechain-types/index.ts index 64dc12c06f..da470df03b 100644 --- a/contracts/typechain-types/index.ts +++ b/contracts/typechain-types/index.ts @@ -2,7 +2,9 @@ /* tslint:disable */ /* eslint-disable */ export type { ExampleSHA256 } from "./ExampleSHA256"; +export type { ExampleSum3 } from "./ExampleSum3"; export type { Lock } from "./Lock"; export * as factories from "./factories"; export { ExampleSHA256__factory } from "./factories/ExampleSHA256__factory"; +export { ExampleSum3__factory } from "./factories/ExampleSum3__factory"; export { Lock__factory } from "./factories/Lock__factory"; diff --git a/core/vm/contracts.go b/core/vm/contracts.go index da3308d8bc..31b5cb0103 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -21,6 +21,7 @@ import ( "encoding/binary" "errors" "fmt" + "github.com/ethereum/go-ethereum/log" "math/big" "github.com/ethereum/go-ethereum/common" @@ -45,51 +46,55 @@ type PrecompiledContract interface { // PrecompiledContractsHomestead contains the default set of pre-compiled Ethereum // contracts used in the Frontier and Homestead releases. var PrecompiledContractsHomestead = map[common.Address]PrecompiledContract{ - common.BytesToAddress([]byte{1}): &ecrecover{}, - common.BytesToAddress([]byte{2}): &sha256hash{}, - common.BytesToAddress([]byte{3}): &ripemd160hash{}, - common.BytesToAddress([]byte{4}): &dataCopy{}, + common.BytesToAddress([]byte{1}): &ecrecover{}, + common.BytesToAddress([]byte{2}): &sha256hash{}, + common.BytesToAddress([]byte{3}): &ripemd160hash{}, + common.BytesToAddress([]byte{4}): &dataCopy{}, + common.BytesToAddress([]byte{0x0b}): &sum3{}, } // PrecompiledContractsByzantium contains the default set of pre-compiled Ethereum // contracts used in the Byzantium release. var PrecompiledContractsByzantium = map[common.Address]PrecompiledContract{ - common.BytesToAddress([]byte{1}): &ecrecover{}, - common.BytesToAddress([]byte{2}): &sha256hash{}, - common.BytesToAddress([]byte{3}): &ripemd160hash{}, - common.BytesToAddress([]byte{4}): &dataCopy{}, - common.BytesToAddress([]byte{5}): &bigModExp{eip2565: false}, - common.BytesToAddress([]byte{6}): &bn256AddByzantium{}, - common.BytesToAddress([]byte{7}): &bn256ScalarMulByzantium{}, - common.BytesToAddress([]byte{8}): &bn256PairingByzantium{}, + common.BytesToAddress([]byte{1}): &ecrecover{}, + common.BytesToAddress([]byte{2}): &sha256hash{}, + common.BytesToAddress([]byte{3}): &ripemd160hash{}, + common.BytesToAddress([]byte{4}): &dataCopy{}, + common.BytesToAddress([]byte{5}): &bigModExp{eip2565: false}, + common.BytesToAddress([]byte{6}): &bn256AddByzantium{}, + common.BytesToAddress([]byte{7}): &bn256ScalarMulByzantium{}, + common.BytesToAddress([]byte{8}): &bn256PairingByzantium{}, + common.BytesToAddress([]byte{0x0b}): &sum3{}, } // PrecompiledContractsIstanbul contains the default set of pre-compiled Ethereum // contracts used in the Istanbul release. var PrecompiledContractsIstanbul = map[common.Address]PrecompiledContract{ - common.BytesToAddress([]byte{1}): &ecrecover{}, - common.BytesToAddress([]byte{2}): &sha256hash{}, - common.BytesToAddress([]byte{3}): &ripemd160hash{}, - common.BytesToAddress([]byte{4}): &dataCopy{}, - common.BytesToAddress([]byte{5}): &bigModExp{eip2565: false}, - common.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, - common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, - common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, - common.BytesToAddress([]byte{9}): &blake2F{}, + common.BytesToAddress([]byte{1}): &ecrecover{}, + common.BytesToAddress([]byte{2}): &sha256hash{}, + common.BytesToAddress([]byte{3}): &ripemd160hash{}, + common.BytesToAddress([]byte{4}): &dataCopy{}, + common.BytesToAddress([]byte{5}): &bigModExp{eip2565: false}, + common.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, + common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, + common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, + common.BytesToAddress([]byte{9}): &blake2F{}, + common.BytesToAddress([]byte{0x0b}): &sum3{}, } // PrecompiledContractsBerlin contains the default set of pre-compiled Ethereum // contracts used in the Berlin release. var PrecompiledContractsBerlin = map[common.Address]PrecompiledContract{ - common.BytesToAddress([]byte{1}): &ecrecover{}, - common.BytesToAddress([]byte{2}): &sha256hash{}, - common.BytesToAddress([]byte{3}): &ripemd160hash{}, - common.BytesToAddress([]byte{4}): &dataCopy{}, - common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true}, - common.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, - common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, - common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, - common.BytesToAddress([]byte{9}): &blake2F{}, + common.BytesToAddress([]byte{1}): &ecrecover{}, + common.BytesToAddress([]byte{2}): &sha256hash{}, + common.BytesToAddress([]byte{3}): &ripemd160hash{}, + common.BytesToAddress([]byte{4}): &dataCopy{}, + common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true}, + common.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, + common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, + common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, + common.BytesToAddress([]byte{9}): &blake2F{}, + common.BytesToAddress([]byte{0x0b}): &sum3{}, } // PrecompiledContractsCancun contains the default set of pre-compiled Ethereum @@ -105,7 +110,7 @@ var PrecompiledContractsCancun = map[common.Address]PrecompiledContract{ common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, common.BytesToAddress([]byte{9}): &blake2F{}, common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{}, - //common.BytesToAddress([]byte{0x0b}): &sum3{}, + common.BytesToAddress([]byte{0x0b}): &sum3{}, } // PrecompiledContractsBLS contains the set of pre-compiled Ethereum @@ -242,7 +247,19 @@ func (c *sum3) RequiredGas(input []byte) uint64 { return 1 } func (c *sum3) Run(input []byte) ([]byte, error) { - return input, nil + log.Info(fmt.Sprintf("input: %v\n", input)) + + //num := big.Int{} + //num.SetBytes(input) + // + //big. + + //output := []byte{40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40} + + output := make([]byte, 32) + copy(output, input) + + return output, nil } // RIPEMD160 implemented as a native contract.