mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Sum3 is working
This commit is contained in:
parent
cd85455098
commit
f983bcd4cc
5 changed files with 45 additions and 16 deletions
|
|
@ -3,8 +3,8 @@ 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));
|
||||
function sum3(uint256 a, uint256 b, uint256 c) public view returns (bytes memory h) {
|
||||
(bool ok, bytes memory out) = address(0x0b).staticcall(abi.encode(a,b,c));
|
||||
require(ok, "precompile call failed");
|
||||
|
||||
console.logString("log out:");
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@ describe("sum3", 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));
|
||||
// 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(3, 4, 5));
|
||||
|
||||
expect(await exampleSum3.sum3(uint8Array)).to.equal("0x0000000000000000000000000000000000000000000000000000000000000003");
|
||||
expect(await exampleSum3.sum3(3, 4, 5)).to.equal("0x000000000000000000000000000000000000000000000000000000000000000c");
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
/* eslint-disable */
|
||||
import type {
|
||||
BaseContract,
|
||||
BigNumberish,
|
||||
BytesLike,
|
||||
FunctionFragment,
|
||||
Result,
|
||||
|
|
@ -22,7 +23,10 @@ import type {
|
|||
export interface ExampleSum3Interface extends Interface {
|
||||
getFunction(nameOrSignature: "sum3"): FunctionFragment;
|
||||
|
||||
encodeFunctionData(functionFragment: "sum3", values: [BytesLike]): string;
|
||||
encodeFunctionData(
|
||||
functionFragment: "sum3",
|
||||
values: [BigNumberish, BigNumberish, BigNumberish]
|
||||
): string;
|
||||
|
||||
decodeFunctionResult(functionFragment: "sum3", data: BytesLike): Result;
|
||||
}
|
||||
|
|
@ -70,7 +74,11 @@ export interface ExampleSum3 extends BaseContract {
|
|||
event?: TCEvent
|
||||
): Promise<this>;
|
||||
|
||||
sum3: TypedContractMethod<[a: BytesLike], [string], "view">;
|
||||
sum3: TypedContractMethod<
|
||||
[a: BigNumberish, b: BigNumberish, c: BigNumberish],
|
||||
[string],
|
||||
"view"
|
||||
>;
|
||||
|
||||
getFunction<T extends ContractMethod = ContractMethod>(
|
||||
key: string | FunctionFragment
|
||||
|
|
@ -78,7 +86,11 @@ export interface ExampleSum3 extends BaseContract {
|
|||
|
||||
getFunction(
|
||||
nameOrSignature: "sum3"
|
||||
): TypedContractMethod<[a: BytesLike], [string], "view">;
|
||||
): TypedContractMethod<
|
||||
[a: BigNumberish, b: BigNumberish, c: BigNumberish],
|
||||
[string],
|
||||
"view"
|
||||
>;
|
||||
|
||||
filters: {};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,19 @@ const _abi = [
|
|||
{
|
||||
inputs: [
|
||||
{
|
||||
internalType: "bytes32",
|
||||
internalType: "uint256",
|
||||
name: "a",
|
||||
type: "bytes32",
|
||||
type: "uint256",
|
||||
},
|
||||
{
|
||||
internalType: "uint256",
|
||||
name: "b",
|
||||
type: "uint256",
|
||||
},
|
||||
{
|
||||
internalType: "uint256",
|
||||
name: "c",
|
||||
type: "uint256",
|
||||
},
|
||||
],
|
||||
name: "sum3",
|
||||
|
|
@ -34,7 +44,7 @@ const _abi = [
|
|||
] as const;
|
||||
|
||||
const _bytecode =
|
||||
"0x608060405234801561001057600080fd5b506105e1806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c806310b19c6714610030575b600080fd5b61004a6004803603810190610045919061033d565b610060565b60405161005791906103fa565b60405180910390f35b6060600080600b73ffffffffffffffffffffffffffffffffffffffff168460405160200161008e919061042b565b6040516020818303038152906040526040516100aa9190610482565b600060405180830381855afa9150503d80600081146100e5576040519150601f19603f3d011682016040523d82523d6000602084013e6100ea565b606091505b50915091508161012f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610126906104f6565b60405180910390fd5b61016d6040518060400160405280600881526020017f6c6f67206f75743a000000000000000000000000000000000000000000000000815250610180565b61017681610219565b8092505050919050565b61021681604051602401610194919061055a565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506102b2565b50565b6102af8160405160240161022d91906103fa565b6040516020818303038152906040527f0be77f56000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506102b2565b50565b6102c9816102c16102cc6102ed565b63ffffffff16565b50565b60006a636f6e736f6c652e6c6f679050600080835160208501845afa505050565b6102f8819050919050565b61030061057c565b565b600080fd5b6000819050919050565b61031a81610307565b811461032557600080fd5b50565b60008135905061033781610311565b92915050565b60006020828403121561035357610352610302565b5b600061036184828501610328565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60005b838110156103a4578082015181840152602081019050610389565b60008484015250505050565b6000601f19601f8301169050919050565b60006103cc8261036a565b6103d68185610375565b93506103e6818560208601610386565b6103ef816103b0565b840191505092915050565b6000602082019050818103600083015261041481846103c1565b905092915050565b61042581610307565b82525050565b6000602082019050610440600083018461041c565b92915050565b600081905092915050565b600061045c8261036a565b6104668185610446565b9350610476818560208601610386565b80840191505092915050565b600061048e8284610451565b915081905092915050565b600082825260208201905092915050565b7f707265636f6d70696c652063616c6c206661696c656400000000000000000000600082015250565b60006104e0601683610499565b91506104eb826104aa565b602082019050919050565b6000602082019050818103600083015261050f816104d3565b9050919050565b600081519050919050565b600061052c82610516565b6105368185610499565b9350610546818560208601610386565b61054f816103b0565b840191505092915050565b600060208201905081810360008301526105748184610521565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052605160045260246000fdfea2646970667358221220a11a3764504ba767a98f1f80053560a19726cafb73623fec58b820da70cd0e8964736f6c63430008130033";
|
||||
"0x608060405234801561001057600080fd5b50610629806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063d412532e14610030575b600080fd5b61004a60048036038101906100459190610343565b610060565b6040516100579190610426565b60405180910390f35b6060600080600b73ffffffffffffffffffffffffffffffffffffffff1686868660405160200161009293929190610457565b6040516020818303038152906040526040516100ae91906104ca565b600060405180830381855afa9150503d80600081146100e9576040519150601f19603f3d011682016040523d82523d6000602084013e6100ee565b606091505b509150915081610133576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161012a9061053e565b60405180910390fd5b6101716040518060400160405280600881526020017f6c6f67206f75743a000000000000000000000000000000000000000000000000815250610186565b61017a8161021f565b80925050509392505050565b61021c8160405160240161019a91906105a2565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506102b8565b50565b6102b5816040516024016102339190610426565b6040516020818303038152906040527f0be77f56000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506102b8565b50565b6102cf816102c76102d26102f3565b63ffffffff16565b50565b60006a636f6e736f6c652e6c6f679050600080835160208501845afa505050565b6102fe819050919050565b6103066105c4565b565b600080fd5b6000819050919050565b6103208161030d565b811461032b57600080fd5b50565b60008135905061033d81610317565b92915050565b60008060006060848603121561035c5761035b610308565b5b600061036a8682870161032e565b935050602061037b8682870161032e565b925050604061038c8682870161032e565b9150509250925092565b600081519050919050565b600082825260208201905092915050565b60005b838110156103d05780820151818401526020810190506103b5565b60008484015250505050565b6000601f19601f8301169050919050565b60006103f882610396565b61040281856103a1565b93506104128185602086016103b2565b61041b816103dc565b840191505092915050565b6000602082019050818103600083015261044081846103ed565b905092915050565b6104518161030d565b82525050565b600060608201905061046c6000830186610448565b6104796020830185610448565b6104866040830184610448565b949350505050565b600081905092915050565b60006104a482610396565b6104ae818561048e565b93506104be8185602086016103b2565b80840191505092915050565b60006104d68284610499565b915081905092915050565b600082825260208201905092915050565b7f707265636f6d70696c652063616c6c206661696c656400000000000000000000600082015250565b60006105286016836104e1565b9150610533826104f2565b602082019050919050565b600060208201905081810360008301526105578161051b565b9050919050565b600081519050919050565b60006105748261055e565b61057e81856104e1565b935061058e8185602086016103b2565b610597816103dc565b840191505092915050565b600060208201905081810360008301526105bc8184610569565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052605160045260246000fdfea2646970667358221220138b8b95419e468cde0b0f057a53c9bc741fa464c1c6043b7733896eda0cbf5364736f6c63430008130033";
|
||||
|
||||
type ExampleSum3ConstructorParams =
|
||||
| [signer?: Signer]
|
||||
|
|
|
|||
|
|
@ -249,13 +249,20 @@ func (c *sum3) RequiredGas(input []byte) uint64 {
|
|||
func (c *sum3) Run(input []byte) ([]byte, error) {
|
||||
log.Info(fmt.Sprintf("input: %v\n", input))
|
||||
|
||||
//a := make([]byte, 32)
|
||||
//copy(a, input[:32])
|
||||
|
||||
a := big.Int{}
|
||||
a.SetBytes(input[:32])
|
||||
|
||||
return common.LeftPadBytes(a.Bytes(), 32), nil
|
||||
b := big.Int{}
|
||||
b.SetBytes(input[32:64])
|
||||
|
||||
_c := big.Int{}
|
||||
_c.SetBytes(input[64:96])
|
||||
|
||||
rez := big.Int{}
|
||||
rez.Add(&a, &b)
|
||||
rez.Add(&rez, &_c)
|
||||
|
||||
return common.LeftPadBytes(rez.Bytes(), 32), nil
|
||||
}
|
||||
|
||||
// RIPEMD160 implemented as a native contract.
|
||||
|
|
|
|||
Loading…
Reference in a new issue