Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Commit

Permalink
Merge branch 'upgrade-51' into change-default-values
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-bousfield committed Dec 10, 2021
2 parents 77d0e5c + ea932f1 commit 0a7a6a2
Show file tree
Hide file tree
Showing 34 changed files with 304 additions and 58 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ jobs:
- name: Build Arbitrum
run: |
mkdir arbitrum/packages/arb-avm-cpp/debug/
mkdir arbitrum/packages/arb-avm-cpp/build/
cd $_
cmake .. -DCMAKE_BUILD_TYPE=Debug
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo
make -j
- name: Test Node's C++ Database
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
generics_files = basic simple nested func closure colorful queue
generics_outputs = $(patsubst %,generics/%, $(generics_files))

minitest_outputs = arithmetic codeloadtest default globaltest simple-closure closure stack-safety quick wide-tuples $(generics_outputs)
minitest_outputs = arithmetic codeloadtest default globaltest modexp simple-closure closure stack-safety quick wide-tuples $(generics_outputs)
upgrade_outputs = regcopy_new regcopy_old upgrade1_new upgrade1_old
looptest_outputs = upgrade2_new upgrade2_old
builtin_outputs = arraytest kvstest maptest
Expand Down
2 changes: 1 addition & 1 deletion arb_os/arbos-upgrade.mexe

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion arb_os/arbos.mexe

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion arb_os/arbos_before.mexe

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions arb_os/gasAccounting.mini
Original file line number Diff line number Diff line change
Expand Up @@ -809,15 +809,16 @@ public view write func gasAccounting_prepareTx(tx: TxRequestData) -> (
payForTxAndL1Gas(
tx.gasPayer,
tx.caller,
None<address>,
None,
gasAccountingInfo.feeConfig,
prices,
tx.feeStats,
tx.maxGas * prices.perArbGasTotal,
)
};

set tx.feeStats = feeStats;
if !fullyPaid {
if !fullyPaid && !tx.feeStats.noFeeGasEstimationMode {
// sender didn't have enough gas funds
// we took all of the funds to make a partial payment to the aggregator
// now fail the tx
Expand All @@ -829,7 +830,7 @@ public view write func gasAccounting_prepareTx(tx: TxRequestData) -> (
// for a fractional ArbGas unit (rounding down would credit the user with fractional
// ETH that we don't have)
let roundedUpGasDelta = safeAdd(safeAdd(feeStats.weiPaid.tx, feeStats.weiPaid.calldataUnit), prices.perArbGasTotal - 1) / prices.perArbGasTotal;
if tx.maxGas > roundedUpGasDelta {
if tx.maxGas >= roundedUpGasDelta {
set tx.maxGas = tx.maxGas - roundedUpGasDelta;
} else {
set tx.feeStats.units.calldataUnit = feeStats.units.calldataUnit;
Expand All @@ -839,7 +840,7 @@ public view write func gasAccounting_prepareTx(tx: TxRequestData) -> (
if tx.incomingRequest.kind == const::L1MessageType_L2ForGasEstimation {
let gasPrice = gasAccountingInfo.currentPrices.perArbGasTotal;
let gasPayerFunds = account_getEthBalance(accountStore_get(safeGetGlobalAccountStore(), tx.gasPayer));
if tx.value >= gasPayerFunds {
if tx.value > gasPayerFunds {
(const::TxResultCode_insufficientBalance, tx)
} else {
let affordableGas = (gasPayerFunds - tx.value) / gasPrice;
Expand Down Expand Up @@ -929,7 +930,6 @@ view write func payForTxAndL1Gas(
safeMul(calldataUnits, networkUnitPrice),
feeStats,
paymentLimitWei,
feeStats.noFeeGasEstimationMode,
);
feeStats = ufs with {
price: ufs.price with {
Expand Down Expand Up @@ -961,7 +961,6 @@ view write func payForTxAndL1Gas(
safeMul(calldataUnits, basePriceCalldataUnit),
feeStats,
safeSub(paymentLimitWei, totalWeiPaid),
feeStats.noFeeGasEstimationMode,
);
set feeStats.price.tx = safeAdd(feeStats.price.tx, basePriceTx);
set feeStats.price.calldataUnit = safeAdd(feeStats.price.calldataUnit, basePriceCalldataUnit);
Expand All @@ -982,8 +981,10 @@ view write func tryToPayForL1Gas(
weiForCalldata: uint,
feeStats: TxFeeStats,
paymentLimit: uint,
dontActuallyPay: bool,
) -> (bool, TxFeeStats, uint) { // returns (fullyPaid, updatedFeeStats, totalWeiPaid)

let dontActuallyPay = feeStats.noFeeGasEstimationMode;

let totalDue = weiForTx + weiForCalldata;
let fullyPaid = if totalDue <= paymentLimit {
true
Expand Down Expand Up @@ -1223,7 +1224,7 @@ public func deferredPayments_apply(acctStore: AccountStore, dp: DeferredPayments
acctStore = uAcctStore;
} else {
asm(11000) { debugprint };
return None<AccountStore>;
return None;
}
} else {
return Some(acctStore);
Expand Down
2 changes: 1 addition & 1 deletion arb_os/upgrade.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion benchmarks/boot.aoslog
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"format_version":1,"inbox":[{"Tuple":[{"Int":"4"},{"Int":"186a0"},{"Int":"989680"},{"Int":"0"},{"Int":"0"},{"Int":"77359400"},{"Int":"40"},{"Buffer":"625a539a292ffb7be735d7db3f6b9b9c88b9ced262ae58163dfb75ba308551f2000000000000000000000000000000000000000000000000000000000000a4b1"}]}],"logs":[{"Tuple":[{"Int":"1"},{"Int":"0"},{"Int":"0"},{"Tuple":[{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"0"}]},{"Tuple":[{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"1"},{"Int":"0"}]},{"Tuple":[{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"112a8800"}]},{"Int":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},{"Int":"0"}]}],"sends":[],"total_gas":1253250}
{"format_version":1,"inbox":[{"Tuple":[{"Int":"4"},{"Int":"186a0"},{"Int":"989680"},{"Int":"0"},{"Int":"0"},{"Int":"77359400"},{"Int":"40"},{"Buffer":"625a539a292ffb7be735d7db3f6b9b9c88b9ced262ae58163dfb75ba308551f2000000000000000000000000000000000000000000000000000000000000a4b1"}]}],"logs":[{"Tuple":[{"Int":"1"},{"Int":"0"},{"Int":"0"},{"Tuple":[{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"0"}]},{"Tuple":[{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"1"},{"Int":"0"}]},{"Tuple":[{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"112a8800"}]},{"Int":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},{"Int":"0"}]}],"sends":[],"total_gas":1247162}
2 changes: 1 addition & 1 deletion benchmarks/nulltx_100.aoslog

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion benchmarks/nulltx_1000.aoslog

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion benchmarks/nulltx_batch_100.aoslog

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion benchmarks/nulltx_batch_500.aoslog

Large diffs are not rendered by default.

151 changes: 151 additions & 0 deletions minitests/modexp.mini
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
//
// Copyright 2020, Offchain Labs, Inc. All rights reserved.
//

use std::biguint::biguint_equal;
use std::biguint::biguint_fromUint;
use std::biguint::biguint_modexp;
use std::biguint::biguint_toBytes;
use std::biguint::biguint_fromBytes;
use std::biguint::biguint_isZero;

use std::queue::queue_new;
use std::queue::queue_isEmpty;
use std::queue::queue_put;
use std::queue::queue_get;
use std::queue::queue_size;

use std::bytearray::ByteArray;
use std::bytearray::bytearray_new;
use std::bytearray::bytearray_set64;
use std::bytearray::bytearray_set256;
use std::bytearray::bytearray_get256;
use std::bytearray::bytearray_extract;

use std::keccak::keccak256;

var entropy: ByteArray;

view write func main() {
if let Some(res) = test() {
asm(res) { log };
} else {
asm("unwrap panic".1,) { log };
}
}

view write func test() -> option<any> {

let q = queue_new();

q = queue_put(q, (
biguint_fromUint(0), // base
biguint_fromUint(1), // exponent
biguint_fromUint(1), // modulus
biguint_fromUint(0), // expected result
));

q = queue_put(q, (
biguint_fromUint(0x10001),
biguint_fromUint(0xccf4d91acbdba9e9795b09c107816a4538d193be735e2aef192d49bc86e179ad),
biguint_fromUint(0x73753b483ae0f07b9ad7fab2932e47bc8a67fa44d848770b26de2140aedf9996),
biguint_fromUint(0x595368ed0128efa3fb81d46fbfec3ef263055b883fea4813b19b87cc218e8731),
));

q = queue_put(q, (
biguint_fromBytes({
let base = bytearray_new(0);
base = bytearray_set256(base, 0, 0x630f4bef8d4648e496b55384a8373cde2f2abcf9cf542436cfc69b884ae8840e);
base = bytearray_set256(base, 32, 0x5726f10727c325c3be1cb08931c7bf42b9d163c9ecedd30abeec31d654ec3790);
base
}),
biguint_fromBytes({
let exp = bytearray_new(0);
exp = bytearray_set256(exp, 0, 0xccf4d91acbdba9e9795b09c107816a4538d193be735e2aef192d49bc86e179ad);
exp = bytearray_set256(exp, 32, 0xccf4d91acbdba9e9795b09c107816a4538d193be735e2aef192d49bc86e179ad);
exp
}),
biguint_fromBytes({
let mod = bytearray_new(0);
mod = bytearray_set256(mod, 0, 0x73753b483ae0f07b9ad7fab2932e47bc8a67fa44d848770b26de2140aedf9996);
mod = bytearray_set256(mod, 32, 0x73753b483ae0f07b9ad7fab2932e47bc8a67fa44d848770b26de2140aedf9996);
mod
}),
biguint_fromBytes({
let res = bytearray_new(0);
res = bytearray_set256(res, 0, 0x521c7db3320c62d2c9e27e53ecbc07105a0c2604d3c38828301391b747a149f8);
res = bytearray_set256(res, 32, 0xeb04d256a17429f1590942d176b1fe89f600926a47b8a5874c1444180ef6a3e2);
res
})
));

while !queue_isEmpty(q) {
let (*q, case) = queue_get(q)?;
let case = unsafecast<([]uint, []uint, []uint, []uint)>(case);
let (base, exponent, modulus, expected) = case;

let result = biguint_modexp(base, exponent, modulus)?;
if !biguint_equal(result, expected) {
return Some(("failed on test #".1, (queue_size(q) + 1), "expected:", expected, "but have:", result));
}
}

entropy = bytearray_new(0);
entropy = bytearray_set256(entropy, 0, 5);

let rand = view write closure(bound: uint) -> uint {
let keccak = uint(keccak256(entropy, 0, 32));
entropy = bytearray_set256(entropy, 0, keccak);
bytearray_get256(entropy, 0) % bound
};

let rand_bytes = view write closure(lower: uint, upper: uint) -> []uint {
let bytes = bytearray_new(0);
let i = 0;
let length = lower + rand(upper - lower);
while i < length {
bytes = bytearray_set256(bytes, i*32, bytearray_get256(entropy, rand(1)));
i = i + 1;
}
biguint_fromBytes(bytearray_extract(bytes, 0, 1))
};

let rounds = 100;
let step = 0;
while step < rounds {
entropy = bytearray_set64(entropy, 0, step);
debug((step, entropy.contents));

let base = rand_bytes(1, 2);
let exponent = rand_bytes(1, 2);
let modulus = rand_bytes(1, 2);

if !biguint_isZero(modulus) {

let result = biguint_modexp(base, exponent, modulus)?;
let modexp = biguint_toBytes(result);
let hashed = keccak256(modexp, 0, 32);

entropy = bytearray_set256(entropy, 0, uint(hashed));

debug((
step,
entropy.contents,
bytearray_get256(biguint_toBytes(base), 0),
bytearray_get256(biguint_toBytes(exponent), 0),
bytearray_get256(biguint_toBytes(modulus), 0),
bytearray_get256(biguint_toBytes(result), 0)
));
}

step = step + 1;
}

let accumulation = bytearray_get256(entropy, 0);

if accumulation != 0x48078cfed56339ea54962e72c37c7f588fc4f8e5bc173827ba75cb10a63a96a5 {
Some(accumulation)
} else {
Some(0)
}
}
Loading

0 comments on commit 0a7a6a2

Please sign in to comment.