Skip to content

Commit

Permalink
Merge branch 'develop' into wsdt/mainnet-faucet
Browse files Browse the repository at this point in the history
  • Loading branch information
wsdt authored Nov 17, 2023
2 parents 1da3bbd + ad3dae7 commit 777de40
Show file tree
Hide file tree
Showing 69 changed files with 6,147 additions and 2,896 deletions.
10 changes: 7 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
version: 2.1

parameters:
ci_builder_image:
type: string
default: us-docker.pkg.dev/${GCP_PROJECT_ID}/${GCP_ARTIFACT_REPOSITORY}/images/ci-builder:latest

executors:
intergration-tests-executor:
resource_class: xlarge
Expand Down Expand Up @@ -164,15 +169,14 @@ jobs:
type: string
default: this-package-does-not-exist
docker:
- image: ethereumoptimism/ci-builder:latest
- image: cimg/postgres:14.1
- image: <<pipeline.parameters.ci_builder_image>>
steps:
- checkout
- check-changed:
patterns: go/proxyd
- run:
name: Lint
command: golangci-lint run -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint -e "errors.As" -e "errors.Is" ./...
command: make lint
working_directory: <<parameters.working_directory>>
- store_test_results:
path: /test-results
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM python:3.8-slim
RUN pip3 install --no-cache-dir web3==5.31.4
RUN pip3 install --no-cache-dir web3==6.11.1
COPY boba_community/fraud-detector/fraud-detector.py /
COPY boba_community/fraud-detector/packages/jsonrpclib /jsonrpclib
COPY /packages/contracts/artifacts/contracts/L1/rollup/StateCommitmentChain.sol/StateCommitmentChain.json /contracts/StateCommitmentChain.json
Expand Down
14 changes: 7 additions & 7 deletions boba_community/fraud-detector/fraud-detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def status(*args):
while True:
try:
rpc[1] = Web3(Web3.HTTPProvider(os.environ['L1_NODE_WEB3_URL']))
assert (rpc[1].isConnected())
assert (rpc[1].is_connected())
break
except:
logger.info ("Waiting for L1...")
Expand All @@ -99,7 +99,7 @@ def status(*args):
while True:
try:
rpc[2] = Web3(Web3.HTTPProvider(os.environ['L2_NODE_WEB3_URL']))
assert (rpc[2].isConnected())
assert (rpc[2].is_connected())
break
except:
logger.info ("Waiting for L2...")
Expand All @@ -111,7 +111,7 @@ def status(*args):
while True:
try:
rpc[3] = Web3(Web3.HTTPProvider(os.environ['VERIFIER_WEB3_URL']))
assert (rpc[3].isConnected())
assert (rpc[3].is_connected())
break
except:
logger.info ("Waiting for verifier...")
Expand Down Expand Up @@ -181,17 +181,17 @@ def doEvent(event, force_L2):
match = "**** SCC/VERIFIER MISMATCH ****"

if l2SR:
l2SR_str = Web3.toHex(l2SR)
l2SR_str = Web3.utils.toHex(l2SR)
else:
l2SR_str = " -- "
log_str = "{} {} {} {} {} {}".format(rCount, event.blockNumber, Web3.toHex(sr), l2SR_str, Web3.toHex(vfSR), match)
log_str = "{} {} {} {} {} {}".format(rCount, event.blockNumber, Web3.utils.toHex(sr), l2SR_str, Web3.utils.toHex(vfSR), match)
matchedLock.acquire()
if match != "":
Matched['is_ok'] = False
logger.warning(log_str)
else:
Matched['Block'] = rCount
Matched['Root'] = Web3.toHex(sr)
Matched['Root'] = Web3.utils.toHex(sr)
Matched['Time'] = time.time()
logger.info(log_str)
matchedLock.release()
Expand Down Expand Up @@ -238,7 +238,7 @@ def fpLoop():

logger.info("#SCC-IDX L1-Block SCC-STATEROOT L2-STATEROOT VERIFIER-STATEROOT MISMATCH")

topic_sig = Web3.toHex(Web3.keccak(text="StateBatchAppended(uint256,bytes32,uint256,uint256,bytes)"))
topic_sig = Web3.utils.toHex(Web3.keccak(text="StateBatchAppended(uint256,bytes32,uint256,uint256,bytes)"))

while startBlock < l1_tip:
toBlock = min(startBlock+batch_size, l1_tip) - 1
Expand Down
29 changes: 28 additions & 1 deletion boba_examples/turing-hello-world/contracts/HelloTuring.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,36 @@ contract HelloTuring {
return product;
}

// Tests error handling when a contract tries to make more than one call
// per Tx, using the "multFloatNumbers" offchain handler.
// Multiple calls from the same stack depth are permitted for legacy reasons
// but should not be used in new code.
function callTwice(string memory _url, string memory a, string memory b, uint32 mode)
public returns (uint256) {

bytes memory encRequest;
bytes memory encResponse;

if (mode == 2) {
// Call from a different stack depth
HelloTuring(address(this)).callTwice(_url, a, b, 0);
} else if (mode == 1) {
// Call from same stack depth
encRequest = abi.encode(b);
encResponse = myHelper.TuringTxV2(_url, encRequest);
}

encRequest = abi.encode(a);
encResponse = myHelper.TuringTxV2(_url, encRequest);

uint256 product = abi.decode(encResponse, (uint256));
emit MultFloatNumbers(product);
return product;
}

// Tests a Turing method which returns a variable-length array.
// The parameters 'a' and 'b' are passed in the request, returing
// an array of 'b' elements each with value 'a'. This function
// an array of 'a' elements each with value 'b'. This function
// adds all of the returned values and returns a total of (a*b)
function multArray(string memory _url, uint256 a, uint256 b)
public {
Expand Down
76 changes: 66 additions & 10 deletions boba_examples/turing-hello-world/test/local-webserver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BigNumber, Contract, ContractFactory, providers, Wallet, utils } from 'ethers'
import { ethers } from 'hardhat'
import { Contract, ContractFactory, providers, Wallet, utils } from 'ethers'
import chai, { expect } from 'chai'
import { solidity } from 'ethereum-waffle'
chai.use(solidity)
Expand Down Expand Up @@ -204,7 +203,7 @@ if (hre.network.name === "boba_local") {

it('Should fund your Turing helper contract in turingCredit', async () => {

const depositAmount = utils.parseEther('0.5')
const depositAmount = utils.parseEther('1.5')
const preBalance = await turingCredit.prepaidBalance(helper.address)

const bobaBalance = await L2BOBAToken.balanceOf(deployerWallet.address)
Expand Down Expand Up @@ -280,15 +279,26 @@ if (hre.network.name === "boba_local") {
}
})

it("should charge extra gas for L1 calldata storage", async() => {
const g1 = (await hello.estimateGas.multArray(urlStr2, 1, 10, gasOverride)).toNumber()
const g2 = (await hello.estimateGas.multArray(urlStr2, 101, 10, gasOverride)).toNumber()
it("should charge extra gas for L1 calldata storage", async() => {
const eg1 = (await hello.estimateGas.multArray(urlStr2, 1, 10, gasOverride)).toNumber()
let tx1 = await hello.multArray(urlStr2, 1, 10, gasOverride)
const res1 = await tx1.wait()
expect(res1).to.be.ok
const ag1 = res1.gasUsed.toNumber()

const eg2 = (await hello.estimateGas.multArray(urlStr2, 101, 10, gasOverride)).toNumber()
let tx2 = await hello.multArray(urlStr2, 101, 10, gasOverride)
const res2 = await tx2.wait()
expect(res2).to.be.ok
const ag2 = res2.gasUsed.toNumber()

// Larger calldata costs more gas inside the contract itself. We need to test for
// additional usage on top of this from the L1 calldata calculation. The exact value
// depends on the L1 gas price so this test doesn't look for a specific number
expect (g2 - g1).to.be.above(110000)
})
// depends on the L1 gas price so this test doesn't look for a specific number.
// Actual tx is a different code path than estimateGas so both are checked.
expect (eg2 - eg1).to.be.above(110000)
expect (ag2 - ag1).to.be.above(110000)
})

it("should support a large response", async() => {
const nElem = 2038
Expand All @@ -304,11 +314,57 @@ if (hre.network.name === "boba_local") {
expect(result).to.equal(nElem * 55)
})

it("should allow repeated calls (legacy support)", async () => {
await hello.estimateGas.callTwice(urlStr, '6', '6', 1, gasOverride)
let tr = await hello.callTwice(urlStr, '6', '6', 1, gasOverride)
const res = await tr.wait()
expect(res).to.be.ok

const ev = res.events.find(e => e.event === "MultFloatNumbers")
const result = parseInt(ev.data.slice(-64), 16) / 100
expect(result.toFixed(5)).to.equal('904.78000')
})

it("should disallow repeated calls with different input", async () => {
try {
await hello.estimateGas.callTwice(urlStr, '6', '7', 1, gasOverride)
expect(1).to.equal(0)
} catch (e) {
// generic error code indicating that a tx reverted
expect(e.error.toString()).to.contain("gas required exceeds allowance")
}

try {
let tr = await hello.callTwice(urlStr, '6', '7', 1, gasOverride)
const res = await tr.wait()
expect(1).to.equal(0)
} catch (e) {
expect(e.toString()).to.contain("transaction failed")
}
})

it("should disallow repeated calls at different depth", async () => {
try {
await hello.estimateGas.callTwice(urlStr, '8', '8', 2, gasOverride)
expect(1).to.equal(0)
} catch (e) {
expect(e.error.toString()).to.contain("gas required exceeds allowance")
}
try {
let tr = await hello.callTwice(urlStr, '8', '8', 2, gasOverride)
const res = await tr.wait()
expect(1).to.equal(0)
} catch (e) {
expect(e.toString()).to.contain("transaction failed")
}
})

it("final balance", async () => {
const postBalance = await turingCredit.prepaidBalance(
helper.address
)
//expect(postBalance).to.equal( utils.parseEther('0.5'))
// Change expected value if tests are added or skipped above
expect(postBalance).to.equal(utils.parseEther('0.7'))
})
})
} else {
Expand Down
6 changes: 4 additions & 2 deletions go/proxyd/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.18.0-alpine3.15 as builder
FROM golang:1.21.3-alpine3.18 as builder

ARG GITCOMMIT=docker
ARG GITDATE=docker
Expand All @@ -12,7 +12,9 @@ WORKDIR /app

RUN make proxyd

FROM alpine:3.15
FROM alpine:3.18

RUN apk add bind-tools jq curl bash git redis

COPY ./proxyd/entrypoint.sh /bin/entrypoint.sh

Expand Down
4 changes: 2 additions & 2 deletions go/proxyd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ fmt:
.PHONY: fmt

test:
go test -race -v ./...
go test -v ./...
.PHONY: test

lint:
go vet ./...
.PHONY: test
.PHONY: test
Loading

0 comments on commit 777de40

Please sign in to comment.