Identity Contract Works

This commit is contained in:
evgeniy-scherbina 2024-01-03 19:08:53 -05:00
parent bbd08b4716
commit 01d4a40325
17 changed files with 630 additions and 33 deletions

View file

@ -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));
}
}

View file

@ -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;
}
}

View file

@ -2,6 +2,7 @@ import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
const config: HardhatUserConfig = {
// defaultNetwork: "geth",
defaultNetwork: "geth",
networks: {
hardhat: {},

20
contracts/test/sum3.ts Normal file
View file

@ -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");
})
})

View file

@ -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<this>;
interface: ExampleSHA256Interface;
queryFilter<TCEvent extends TypedContractEvent>(
event: TCEvent,
fromBlockOrBlockhash?: string | number | undefined,
toBlock?: string | number | undefined
): Promise<Array<TypedEventLog<TCEvent>>>;
queryFilter<TCEvent extends TypedContractEvent>(
filter: TypedDeferredTopicFilter<TCEvent>,
fromBlockOrBlockhash?: string | number | undefined,
toBlock?: string | number | undefined
): Promise<Array<TypedEventLog<TCEvent>>>;
on<TCEvent extends TypedContractEvent>(
event: TCEvent,
listener: TypedListener<TCEvent>
): Promise<this>;
on<TCEvent extends TypedContractEvent>(
filter: TypedDeferredTopicFilter<TCEvent>,
listener: TypedListener<TCEvent>
): Promise<this>;
once<TCEvent extends TypedContractEvent>(
event: TCEvent,
listener: TypedListener<TCEvent>
): Promise<this>;
once<TCEvent extends TypedContractEvent>(
filter: TypedDeferredTopicFilter<TCEvent>,
listener: TypedListener<TCEvent>
): Promise<this>;
listeners<TCEvent extends TypedContractEvent>(
event: TCEvent
): Promise<Array<TypedListener<TCEvent>>>;
listeners(eventName?: string): Promise<Array<Listener>>;
removeAllListeners<TCEvent extends TypedContractEvent>(
event?: TCEvent
): Promise<this>;
hashSha256: TypedContractMethod<[a: BigNumberish], [bigint], "view">;
getFunction<T extends ContractMethod = ContractMethod>(
key: string | FunctionFragment
): T;
getFunction(
nameOrSignature: "hashSha256"
): TypedContractMethod<[a: BigNumberish], [bigint], "view">;
filters: {};
}

View file

@ -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<this>;
interface: ExampleSum3Interface;
queryFilter<TCEvent extends TypedContractEvent>(
event: TCEvent,
fromBlockOrBlockhash?: string | number | undefined,
toBlock?: string | number | undefined
): Promise<Array<TypedEventLog<TCEvent>>>;
queryFilter<TCEvent extends TypedContractEvent>(
filter: TypedDeferredTopicFilter<TCEvent>,
fromBlockOrBlockhash?: string | number | undefined,
toBlock?: string | number | undefined
): Promise<Array<TypedEventLog<TCEvent>>>;
on<TCEvent extends TypedContractEvent>(
event: TCEvent,
listener: TypedListener<TCEvent>
): Promise<this>;
on<TCEvent extends TypedContractEvent>(
filter: TypedDeferredTopicFilter<TCEvent>,
listener: TypedListener<TCEvent>
): Promise<this>;
once<TCEvent extends TypedContractEvent>(
event: TCEvent,
listener: TypedListener<TCEvent>
): Promise<this>;
once<TCEvent extends TypedContractEvent>(
filter: TypedDeferredTopicFilter<TCEvent>,
listener: TypedListener<TCEvent>
): Promise<this>;
listeners<TCEvent extends TypedContractEvent>(
event: TCEvent
): Promise<Array<TypedListener<TCEvent>>>;
listeners(eventName?: string): Promise<Array<Listener>>;
removeAllListeners<TCEvent extends TypedContractEvent>(
event?: TCEvent
): Promise<this>;
sum3: TypedContractMethod<[a: BigNumberish], [bigint], "view">;
getFunction<T extends ContractMethod = ContractMethod>(
key: string | FunctionFragment
): T;
getFunction(
nameOrSignature: "sum3"
): TypedContractMethod<[a: BigNumberish], [bigint], "view">;
filters: {};
}

View file

@ -0,0 +1,5 @@
/* Autogenerated file. Do not edit manually. */
/* tslint:disable */
/* eslint-disable */
export type { ExampleSHA256 } from "./ExampleSHA256";
export type { ExampleSum3 } from "./ExampleSum3";

View file

@ -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<this>;
interface: ExampleSum3Interface;
queryFilter<TCEvent extends TypedContractEvent>(
event: TCEvent,
fromBlockOrBlockhash?: string | number | undefined,
toBlock?: string | number | undefined
): Promise<Array<TypedEventLog<TCEvent>>>;
queryFilter<TCEvent extends TypedContractEvent>(
filter: TypedDeferredTopicFilter<TCEvent>,
fromBlockOrBlockhash?: string | number | undefined,
toBlock?: string | number | undefined
): Promise<Array<TypedEventLog<TCEvent>>>;
on<TCEvent extends TypedContractEvent>(
event: TCEvent,
listener: TypedListener<TCEvent>
): Promise<this>;
on<TCEvent extends TypedContractEvent>(
filter: TypedDeferredTopicFilter<TCEvent>,
listener: TypedListener<TCEvent>
): Promise<this>;
once<TCEvent extends TypedContractEvent>(
event: TCEvent,
listener: TypedListener<TCEvent>
): Promise<this>;
once<TCEvent extends TypedContractEvent>(
filter: TypedDeferredTopicFilter<TCEvent>,
listener: TypedListener<TCEvent>
): Promise<this>;
listeners<TCEvent extends TypedContractEvent>(
event: TCEvent
): Promise<Array<TypedListener<TCEvent>>>;
listeners(eventName?: string): Promise<Array<Listener>>;
removeAllListeners<TCEvent extends TypedContractEvent>(
event?: TCEvent
): Promise<this>;
sum3: TypedContractMethod<[a: BytesLike], [string], "view">;
getFunction<T extends ContractMethod = ContractMethod>(
key: string | FunctionFragment
): T;
getFunction(
nameOrSignature: "sum3"
): TypedContractMethod<[a: BytesLike], [string], "view">;
filters: {};
}

View file

@ -34,7 +34,7 @@ const _abi = [
] as const;
const _bytecode =
"0x608060405234801561001057600080fd5b506103a6806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063d121893114610030575b600080fd5b61004a60048036038101906100459190610187565b610060565b60405161005791906101cd565b60405180910390f35b6000806000600273ffffffffffffffffffffffffffffffffffffffff168460405160200161008e91906101f7565b6040516020818303038152906040526040516100aa9190610283565b600060405180830381855afa9150503d80600081146100e5576040519150601f19603f3d011682016040523d82523d6000602084013e6100ea565b606091505b50915091508161012f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610126906102f7565b60405180910390fd5b808060200190518101906101439190610343565b92505050919050565b600080fd5b6000819050919050565b61016481610151565b811461016f57600080fd5b50565b6000813590506101818161015b565b92915050565b60006020828403121561019d5761019c61014c565b5b60006101ab84828501610172565b91505092915050565b6000819050919050565b6101c7816101b4565b82525050565b60006020820190506101e260008301846101be565b92915050565b6101f181610151565b82525050565b600060208201905061020c60008301846101e8565b92915050565b600081519050919050565b600081905092915050565b60005b8381101561024657808201518184015260208101905061022b565b60008484015250505050565b600061025d82610212565b610267818561021d565b9350610277818560208601610228565b80840191505092915050565b600061028f8284610252565b915081905092915050565b600082825260208201905092915050565b7f707265636f6d70696c652063616c6c206661696c656400000000000000000000600082015250565b60006102e160168361029a565b91506102ec826102ab565b602082019050919050565b60006020820190508181036000830152610310816102d4565b9050919050565b610320816101b4565b811461032b57600080fd5b50565b60008151905061033d81610317565b92915050565b6000602082840312156103595761035861014c565b5b60006103678482850161032e565b9150509291505056fea2646970667358221220ddec545ddbc7f2919666033e50c25e284ec8fc46aa071d2478abce59dfdddcbb64736f6c63430008130033";
"0x608060405234801561001057600080fd5b50610681806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063d121893114610030575b600080fd5b61004a60048036038101906100459190610350565b610060565b6040516100579190610396565b60405180910390f35b6000806000600273ffffffffffffffffffffffffffffffffffffffff168460405160200161008e91906103c0565b6040516020818303038152906040526040516100aa919061044c565b600060405180830381855afa9150503d80600081146100e5576040519150601f19603f3d011682016040523d82523d6000602084013e6100ea565b606091505b50915091508161012f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610126906104c0565b60405180910390fd5b61016d6040518060400160405280600881526020017f6c6f67206f75743a000000000000000000000000000000000000000000000000815250610193565b6101768161022c565b8080602001905181019061018a919061050c565b92505050919050565b610229816040516024016101a7919061058e565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506102c5565b50565b6102c28160405160240161024091906105fa565b6040516020818303038152906040527f0be77f56000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506102c5565b50565b6102dc816102d46102df610300565b63ffffffff16565b50565b60006a636f6e736f6c652e6c6f679050600080835160208501845afa505050565b61030b819050919050565b61031361061c565b565b600080fd5b6000819050919050565b61032d8161031a565b811461033857600080fd5b50565b60008135905061034a81610324565b92915050565b60006020828403121561036657610365610315565b5b60006103748482850161033b565b91505092915050565b6000819050919050565b6103908161037d565b82525050565b60006020820190506103ab6000830184610387565b92915050565b6103ba8161031a565b82525050565b60006020820190506103d560008301846103b1565b92915050565b600081519050919050565b600081905092915050565b60005b8381101561040f5780820151818401526020810190506103f4565b60008484015250505050565b6000610426826103db565b61043081856103e6565b93506104408185602086016103f1565b80840191505092915050565b6000610458828461041b565b915081905092915050565b600082825260208201905092915050565b7f707265636f6d70696c652063616c6c206661696c656400000000000000000000600082015250565b60006104aa601683610463565b91506104b582610474565b602082019050919050565b600060208201905081810360008301526104d98161049d565b9050919050565b6104e98161037d565b81146104f457600080fd5b50565b600081519050610506816104e0565b92915050565b60006020828403121561052257610521610315565b5b6000610530848285016104f7565b91505092915050565b600081519050919050565b6000601f19601f8301169050919050565b600061056082610539565b61056a8185610463565b935061057a8185602086016103f1565b61058381610544565b840191505092915050565b600060208201905081810360008301526105a88184610555565b905092915050565b600082825260208201905092915050565b60006105cc826103db565b6105d681856105b0565b93506105e68185602086016103f1565b6105ef81610544565b840191505092915050565b6000602082019050818103600083015261061481846105c1565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052605160045260246000fdfea26469706673582212203f893be732789443c2aed374de980d148342a60e0beae3d31bf4aac8becef00664736f6c63430008130033";
type ExampleSHA256ConstructorParams =
| [signer?: Signer]

View file

@ -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<typeof ContractFactory>;
const isSuperArgs = (
xs: ExampleSHA256ConstructorParams
): xs is ConstructorParameters<typeof ContractFactory> => 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<ContractDeployTransaction> {
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;
}
}

View file

@ -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<typeof ContractFactory>;
const isSuperArgs = (
xs: ExampleSum3ConstructorParams
): xs is ConstructorParameters<typeof ContractFactory> => 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<ContractDeployTransaction> {
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;
}
}

View file

@ -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";

View file

@ -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<typeof ContractFactory>;
const isSuperArgs = (
xs: ExampleSum3ConstructorParams
): xs is ConstructorParameters<typeof ContractFactory> => 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<ContractDeployTransaction> {
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;
}
}

View file

@ -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";

View file

@ -17,6 +17,10 @@ declare module "hardhat/types/runtime" {
name: "ExampleSHA256",
signerOrOptions?: ethers.Signer | FactoryOptions
): Promise<Contracts.ExampleSHA256__factory>;
getContractFactory(
name: "ExampleSum3",
signerOrOptions?: ethers.Signer | FactoryOptions
): Promise<Contracts.ExampleSum3__factory>;
getContractFactory(
name: "Lock",
signerOrOptions?: ethers.Signer | FactoryOptions
@ -27,6 +31,11 @@ declare module "hardhat/types/runtime" {
address: string | ethers.Addressable,
signer?: ethers.Signer
): Promise<Contracts.ExampleSHA256>;
getContractAt(
name: "ExampleSum3",
address: string | ethers.Addressable,
signer?: ethers.Signer
): Promise<Contracts.ExampleSum3>;
getContractAt(
name: "Lock",
address: string | ethers.Addressable,
@ -37,6 +46,10 @@ declare module "hardhat/types/runtime" {
name: "ExampleSHA256",
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.ExampleSHA256>;
deployContract(
name: "ExampleSum3",
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.ExampleSum3>;
deployContract(
name: "Lock",
signerOrOptions?: ethers.Signer | DeployContractOptions
@ -47,6 +60,11 @@ declare module "hardhat/types/runtime" {
args: any[],
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.ExampleSHA256>;
deployContract(
name: "ExampleSum3",
args: any[],
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.ExampleSum3>;
deployContract(
name: "Lock",
args: any[],

View file

@ -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";

View file

@ -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.